新闻中心

EEPW首页 > EDA/PCB > 设计应用 > 基于FPGA的UART、USB接口协议设计

基于FPGA的UART、USB接口协议设计

作者: 时间:2012-03-13 来源:网络 收藏

//-------------------------------------

//Capture the falling of data transfer over

reg txd_flag_r0,txd_flag_r1;

always@(posedge clk or negedge rst_n)

begin

if(!rst_n)

begin

txd_flag_r0 = 0;

txd_flag_r1 = 0;

end

else

begin

txd_flag_r0 = txd_flag_r;

txd_flag_r1 = txd_flag_r0;

end

end

assign txd_flag = txd_flag_r1 ~txd_flag_r0;

(3)RXD发送模块

由于接收数据的时候,主控是PC,从机是,因此需要采样数据。以上波特率发生器中讲到过,采样时钟clk_bps = 16*clk_bps。硬件描述,通过计数,当采样到RXD数据起始位信号有效时,0-7-15开始计数,,其中7为数据的中点,最稳定的时刻。因此在此时采样数据,能够达到最稳定的效果。Bingo设计代码如下:

always@(posedge clk or negedge rst_n)

begin

if(!rst_n)

begin

smp_cnt = 0;

rxd_cnt = 0;

rxd_data = 0;

rxd_state = R_IDLE;

end

else if(clk_smp == 1)

begin

case(rxd_state)

R_IDLE:

begin

rxd_cnt = 0;

if(rxd_sync == 1'b0)

begin

smp_cnt = smp_cnt + 1'b1;

if(smp_cnt == 4'd7) //8 clk_smp enable

rxd_state = R_SAMPLE;

end

else

smp_cnt = 0;

end

R_SAMPLE:

begin

smp_cnt = smp_cnt +1'b1;

if(smp_cnt == 4'd7)

begin

rxd_cnt = rxd_cnt +1'b1;

if(rxd_cnt == 4'd7)

rxd_state = R_IDLE;

case(rxd_cnt)

3'd0: rxd_data[0] = rxd_sync;

3'd1: rxd_data[1] = rxd_sync;

3'd2: rxd_data[2] = rxd_sync;

3'd3: rxd_data[3] = rxd_sync;

3'd4: rxd_data[4] = rxd_sync;

3'd5: rxd_data[5] = rxd_sync;

3'd6: rxd_data[6] = rxd_sync;

3'd7: rxd_data[7] = rxd_sync;

endcase

end

end

endcase

end

end

c++相关文章:c++教程




关键词: FPGA UART USB 接口

评论


相关推荐

技术专区

关闭