- 11
- 0
- 约3.51万字
- 约 34页
- 2017-03-03 发布于江苏
- 举报
FPGA实现RS-232串口收发的仿真过程(Quartus+Synplify+ModelSim)(2007-09-11 12:17:37)
网上关于RS-232的异步收发介绍得很多,最近没事学着摸索用ModelSim来做时序仿真,就结合网上的参考资料和自己的琢磨,做了这个东西。
针对我这个小程序结合FPGA的开发流程,主要走了以下几步:
1. 文本程序输入(Verilog HDL)
2. 功能仿真(ModelSim,查看逻辑功能是否正确,要写一个Test Bench)
3. 综合(Synplify Pro,程序综合成网表)
4. 布局布线(Quartus II,根据我选定的FPGA器件型号,将网表布到器件中,并估算出相应的时延)
5. 时序仿真(ModelSim,根据时延做进一步仿真)
?
这里贴出我的程序和各个详细步骤,能和各位正在学习的新手们一起分享。
0. 原理
????略
一、文本程序输入(Verilog HDL)
发送端:
module trans(clk,???????????? rst,???????????? TxD_start,???????????? TxD_data,???????????? TxD,???????????? TxD_busy???????????? );input????? clk,?????????? rst,?????????? TxD_start;input[7:0] TxD_data;?? // 待发送的数据output???? TxD,??????? // 输出端口发送的串口数据?????????? TxD_busy;???
reg??????? TxD;reg [7:0]? TxD_dataReg;?? // 寄存器发送模式,因为在串口发送过程中输入端不可能一直保持有效电平reg [3:0]? state;parameter? ClkFrequency =? // 时钟频率-25 MHzparameter? Baud = 115200;??????????? // 串口波特率-115200?
// 波特率产生parameter BaudGeneratorAccWidth = 16;reg?????? [BaudGeneratorAccWidth:0] BaudGeneratorAcc;wire [BaudGeneratorAccWidth:0] BaudGeneratorInc = ((Baud(BaudGeneratorAccWidth-4))+(ClkFrequency5))/(ClkFrequency4);wire BaudTick = BaudGeneratorAcc[BaudGeneratorAccWidth];wire TxD_busy;always @(posedge clk or negedge rst)牋 if(~rst)牋牋?BaudGeneratorAcc = 0;爀lse if(TxD_busy)牋?BaudGeneratorAcc = BaudGeneratorAcc[BaudGeneratorAccWidth-1:0] + BaudGeneratorInc;
// 发送端状态wire?? TxD_ready = (state==0);? // 当state = 0时,处于准备空闲状态,TxD_ready = 1assign TxD_busy = ~TxD_ready;?? // 空闲状态时TxD_busy = 0
// 把待发送数据放入缓存寄存器 TxD_dataRegalways @(posedge clk or negedge rst)?? if(~rst)????? TxD_dataReg = 8?else if(TxD_ready TxD_start)??TxD_dataReg = TxD_data;?????// 发送状态机always @(posedge clk or negedge rst)?if(~rst)????? begin???????? state = 4b0000;?? // 复位时,状态为0000,发送端一直发1电平???????? TxD = 1b1;????? end?else??case(state)??4b0000: if(TxD_start) begin????????????????????? state = 4b0100; // 接受到发送信号,进入发送状态????????? ?????????????? end??4b0100: if(BaudTic
原创力文档

文档评论(0)