第八讲逻辑综合课件

上传人:壹****1 文档编号:591392066 上传时间:2024-09-17 格式:PPT 页数:132 大小:3.90MB
返回 下载 相关 举报
第八讲逻辑综合课件_第1页
第1页 / 共132页
第八讲逻辑综合课件_第2页
第2页 / 共132页
第八讲逻辑综合课件_第3页
第3页 / 共132页
第八讲逻辑综合课件_第4页
第4页 / 共132页
第八讲逻辑综合课件_第5页
第5页 / 共132页
点击查看更多>>
资源描述

《第八讲逻辑综合课件》由会员分享,可在线阅读,更多相关《第八讲逻辑综合课件(132页珍藏版)》请在金锄头文库上搜索。

1、 第八讲 逻辑综合授课教师:邹兴平电邮地址:2024/9/171内容提纲综合的概念描述语句与逻辑综合代码优化逻辑可综合风格2024/9/172综合的概念综合的过程就是将Verilog语句描述的电路从寄存器传输级(RTL)模型构造成门级网表的过程 包括翻译、映射、优化等可综合风格的Verilog HDL 和VHDL的语法只是它们各自语言的一个子集 ,国际标准目前尚未最后形成 ,各厂商的综合器所支持的HDL子集也略有所不同系统级(高层次的行为描述)的综合由于还不太成熟 按照一定的原则来编写代码就可以保证Verilog模块综合前和综合后仿真的一致性 ,只有设计者深入了解综合的实质,才能写出高质量的代

2、码2024/9/173数值数据类型与综合硬件模型数值与常量的对应关系:0:逻辑0,低电平1;逻辑1,高电平Z高阻,或无关值(用于casez和casex)X无关值或未知值2024/9/174数据类型与综合线网型Wire:通用的线网类型,综合成导线2024/9/175变量:Reg:既可用于端口也可用于变量,能综合Integer:仅能用于变量,并且以二进制补码的格式存储数值,可综合Time:仅用于仿真Real: 仅用于仿真Realtime: 仅用于仿真2024/9/176过程块任意边沿 在所有输入信号的任意边沿进入的过程块产生组合逻辑。这种过程块称为组合块。always ( a or b) / 与门

3、y = a & b; 单个边沿 在一个控制信号的单一边沿上进入的过程块产生同步逻辑。这种过程块称为同步块。always ( posedge clk) / D flip-flopq = d; 同步块也可以对异步复位信号的变化产生敏感always ( posedge clk or negedge rst_)if (! rst_) q = 0;else q = d;2024/9/177储值单元的综合原则硬件三种基本的储值单元Wire锁存器触发器对verilog语言而言,对于线网型只能综合成wireReg可以综合成导线也可能综合成存储器(锁存器或触发器)2024/9/178若同步块中使用一个reg,则

4、: 如果在一个时钟周期赋值并在另一个周期被采样,则只能以硬件寄存器实现。 如果reg还是一个基本输出,它会出现在综合网表中,但不一定是一个硬件寄存器。 若两者都不是,该信号可能被优化掉。2024/9/179若组合块中使用一个reg,则: 如果reg值随块的任何一个输入的变化而改变,则在综合时不会产生硬件寄存器。 如果reg值并不总是随块的输入变化而改变,则综合时会产生一个锁存器。2024/9/1710举例1module noreg (a, b, c);input a,b;output c;reg c, temp;always ( a or b)begin Temp=ab; C=tempende

5、ndmodule在一个过程块内,先赋值紧接着引用,没有综合成存储器2024/9/1711举例2module latch (a, b, c);input a,b;output c;reg c;always ( a or b)if(a) c=b;endmodule由于变量c在a=0时没有赋值,所以综合出了锁存器2024/9/1712举例3module ex1reg (d, clk, q);input d, clk;output q;reg q, rega;always ( posedge clk) begin rega = 0; if (d) rega = 1; q = rega; endendm

6、odule说明:在这个例子中,rega只作暂存,因此会被优化掉。2024/9/1713举例4module ex2reg (y, a, b, c);input a, b, c;output y;reg y, rega;always ( a or b or c)beginif (a & b)rega = c;elserega = 0;y = rega;endendmodule说明:在这个例子中, y和rega总是赋新值,因此产生一个纯组合逻辑,Rega作为暂存器被优化掉2024/9/1714举例5module ex4reg (y, a, b, c);input a, b, c;output y;r

7、eg y, rega;always ( a or b or c)beginif (a & b)rega = c;y = rega;endendmodule说明:在这个例子中,rega不总是产生新值,因此会产生一个锁存器,y是锁存器的输出,Rega作为暂存器被优化掉2024/9/17153. 运算符与综合l几乎所有的操作符都可以综合。几乎所有的操作符都可以综合。l和!与和!与x x和和z z有关的操作符不可综合有关的操作符不可综合l写表达式时,要用写表达式时,要用圆括号使逻辑关系明确圆括号使逻辑关系明确,最好不要依赖运算的优先级,最好不要依赖运算的优先级操作符类型操作符类型符号符号连接及复制操作

8、符连接及复制操作符一元操作符一元操作符算术操作符算术操作符逻辑移位操作符逻辑移位操作符关系操作符关系操作符相等操作符相等操作符按位操作符按位操作符逻辑操作符逻辑操作符条件操作符条件操作符 ! & | + - * % = = = != & | & |?:2024/9/1716算术运算符的综合综合工具把线网型和寄存器型翻译成无符号数据格式把整型翻译成有符号二进制补码数据格式2024/9/1717进位与位宽对算术运算都存在结果与操作数的宽度匹配问题,为避免结果的截断误差:加法运算:结果位宽大于或等于两个操作数中最大位宽乘法运算:结果位宽大于或等于两个操作数位宽之和2024/9/1718位选择的综合常

9、量索引位选择module bitselect(a,b,c);input 2:0 a,b;output 2:0 c;Reg 2:0 c;always(a or b )C2:0=a1:0,b0;endmodule2024/9/1719过程赋值语句只能出现在always里阻塞赋值:module blockassignment(clk,q1,q2);input clk;output 2:0 q1,q2;reg 2:0 q1,q2; Always (posedge clk) beginQ1=q1+1;Q2=q1;endendmodule2024/9/17202024/9/1721非阻塞赋值语句modul

10、e blockassignment(clk,q1,q2);input clk;output 2:0 q1,q2;reg 2:0 q1,q2; Always (posedge clk) beginQ1=q1+1;Q2=q1;endendmodule2024/9/17222024/9/1723建议组合逻辑使用阻塞语句时序逻辑使用非阻塞语句对所附加的延时控制,都被综合工具忽略在一个模块中,同一个变量不能既有阻塞赋值又有非阻塞赋值,大多数的综合工具报错2024/9/1724条件表达式的综合module conditioin1(din,c1,c2,dout);input din,c1 , c2;outp

11、ut dout;Assign dout=(c1c2) ? din:0;endmodule2024/9/17252024/9/1726条件表达式级联,有优先级module conditioin2(din1,din2,c1,c2,dout);input din1,din2,c1 , c2;output dout;Assign dout=(c1) ? (din1 & din2):(!c2) ? (din1 | din2) : (din1din2);endmodule2024/9/17272024/9/1728Always语句的组合逻辑综合对于组合逻辑,事件列表必须包括所有输入变量临时变量可以不用列出

12、,通常综合出来就是导线,且不唯一,可以不用,主要是让代码更简洁注意功能仿真的结果与实际综合结果的不一致,见下例2024/9/1729Module incompletevent(din,c,dout); Input din, c; output dout; always(c) Dout=din & c; endmodule2024/9/1730综合结果和功能仿真2024/9/1731时序仿真2024/9/1732 if语句的综合语句的综合module compif (out, d0, d1, s); input d0, d1, s; output out; reg out; always ( s

13、 or d0 or d1) if (s) out = d1; else out = d0;endmodule单条的单条的if-then语语句综合为一个二选句综合为一个二选1数据选择器数据选择器2024/9/1733不完整的if分支语句的综合Module latch(counter,state););input 3:0 counter;output 1:0 state;reg 1:0 state; Always (counter) beginIf(counter2) state=0;Else if(counter5) state=1;endendmodule2024/9/17342024/9/1

14、735描述完整的if分支语句Module latch(counter,state););input 3:0 counter;output 1:0 state;reg 1:0 state; Always (counter) beginIf(counter2) state=0;Else if(counter5) state=1;Else state=2;endendmodule2024/9/17362024/9/1737Case语句的综合全等比较控制表达式与分支表达式位宽必须相同 必须显式表示,否则编译器认为与机器字长相同可以多个不同取值对应同一操作2024/9/1738Module casest

15、ate(a,b,state,q););input a,b;input 1:0 state; output q; reg q;Always (state or a or b)Case(state) 2b00: q=a & b; 2b01: q=a | b; 2b10: q=a b; 2b11: q=0;endcaseendmodule2024/9/17392024/9/1740不完整的case分支语句Module casestate(a,b,state,q););input a,b;input 1:0 state; output q; reg q;Always (state or a or b)

16、Case(state) 2b00: q=a & b; 2b01: q=a | b; 2b10: q=a b;endcaseendmodule2024/9/17412024/9/1742避免从case语句中综合出锁存器措施1.在case语句之前对要赋值的变量赋初始值Module casestate(a,b,state,q););input a,b;input 1:0 state; output q; reg q;Always (state or a or b) beginq=0;Case(state) 2b00: q=a & b; 2b01: q=a | b; 2b10: q=a b;enden

17、dcaseendmodule2024/9/17432024/9/17442.使用default分支语句Module casestate(a,b,state,q););input a,b;input 1:0 state; output q; reg q;Always (state or a or b) beginCase(state) 2b00: q=a & b; 2b01: q=a | b; 2b10: q=a b; Default: q=0;endendcaseendmodule2024/9/17452024/9/17463.使用full_case综合指令Module casestate(a

18、,b,state,q););input a,b;input 1:0 state; output q; reg q;Always (state or a or b) beginCase(state) /*synthesis full_case*/ 2b00: q=a & b; 2b01: q=a | b; 2b10: q=a b;endendcaseendmodule综合工具认为所有可能都已经列出2024/9/17472024/9/1748Casez综合Module casezstate(opa,opb,ir,dout););input opa,opb;input 2:0 ir; output

19、dout; reg dout;Always (opa or opb or ir)Casez(ir) 3bzz1: dout=opa & opb; 3bz10: dout=a | b; 3b100: dout=a b;endcaseendmodule2024/9/1749Z为无关紧要条件,可用“?”代替Z可出现在条件表达式或选择表达式的任意位2024/9/1750Casex综合Module casexstate(opa,opb,ir,dout);Parameter mask 3bx11;input opa,opb; input 2:0 ir; output dout; reg dout;Alwa

20、ys (opa or opb or ir)Casex(ir) 3bxx1: dout=opa & opb; 3bx10: dout=a | b; 3b100: dout=a b;endcaseendmodule2024/9/1751并行case语句module prioritycase(key,decoder); input 3:0 key; output 1:0 decoder; reg 1:0 decoder; always (key) casex(key) /等价的等价的if语句如下语句如下 4bxxx1:decoder =0; /if(key0) decoder =0; 4bxx1x:

21、decoder =1; /else if(key1) decoder =1; 4bx1xx:decoder =2; /else if(key2) decoder =2; 4b1xxx:decoder =3; /else if(key3) decoder =3; endcaseendmodule综合出优先级译码器2024/9/17522024/9/1753使用并行综合指令module parallelcase(key,decoder); input 3:0 key; output 1:0 decoder; reg 1:0 decoder; always (key) casex(key) /syn

22、thesis parallel_case 4bxxx1:decoder =0; 4bxx1x:decoder =1; 4bx1xx:decoder =2; 4b1xxx:decoder =3; endcaseendmodule2024/9/1754条件表达式使用常量的case语句module constantcase(key,decoder); input 3:0 key; output 1:0 decoder; reg 1:0 decoder; always (key) case (1) key0: decoder =0; key1: decoder =1; key2: decoder =2

23、; key3: decoder =3; endcaseendmodule:条件表达式用常量,综合工具不确认到底有多少分支,只能当不完备的case语句处理,综合出锁存器2024/9/17552024/9/1756module fullconstantcase(key,decoder); input 3:0 key; output 1:0 decoder; reg 1:0 decoder; always (key) case (1) /synthesis full_case key0: decoder =0; key1: decoder =1; key2: decoder =2; key3: de

24、coder =3; endcaseendmodule2024/9/17572024/9/1758综合出锁存器的情况有意识和无意识无意识: case和if语句对变量赋值不完整 条件操作符?:以反馈的形式实现Always内部定义的局部变量,如果也是不完全赋值(if或case)一样会综合出锁存器,如果在同一个条件分支,先赋值马上引用则不会全局变量,如果先应用再赋值,就会综合出锁存器2024/9/1759条件操作符module conditionallatch(din,latch,dout); input latch, din; output dout; assign dout =(latch) ?

25、Din:dout; endmodule2024/9/1760局部变量综合出锁存器module localvariablelatch(din,latch,dout); input latch; input 3:0 din; output 3:0 dout; reg 3:0 dout; always (latch or din) begin reg 3:0 temp; if(latch) temp =din; dout =temp; end endmodule2024/9/17612024/9/1762同一条件分支module localtempvariable (din,latch,dout);

26、 input latch; input din; output dout; reg dout; always (latch or din) begin:l1; reg temp; if(latch) begin temp =din; dout =temp; end end endmodule2024/9/1763全局变量先引用情况module usebeforeassign(din,latch,dout); input latch; input din; output dout; reg dout; reg temp; always (latch or din or temp); if(lat

27、ch)begin dout =temp; temp =din; end endmodule2024/9/17642024/9/1765循环语句的综合迭代次数在仿真前由编译器确定,也就是循环次数为常数,叫做静态循环,反之叫非静态循环不是每个综合工具都支持while,for,repeat,forever循环,for一般都能支持2024/9/1766For实现静态循环define data_width 4Module staticloop(A,B,C); input data_width-1:0 A, B; output data_width-1:0 C; reg data_width-1:0 C;

28、 always (A or B)begin:lable integer k; for(k=0; kdata_width;k=k+1) C k = A k B k; endendmodule2024/9/17672024/9/1768综合出触发器module flipflop(clk,a,b); input clk; input a; output b; reg b,temp; always (posedge clk) begin:block temp = a; b = temp; endendmodule2024/9/1769反向时钟的使用module invertedclock(clk,a,

29、b,c,d); input clk; input a,b; output c,d; reg c,d; always (posedge clk) c = a & b; always (negedge clk) d = a | b;endmodule2024/9/17702024/9/1771注意一个周期同时使用上下降沿,相当于时钟倍频,时序约束要求变紧在FPGA中PLL或DLL都能很好保证某个时钟沿指标,而另一个沿要求不一定严格如果使用反向时钟,最好不要使用反向器生成,时钟的延时和倾斜加大如果是使用FPGA,直接可以生成反向时钟2024/9/17722024/9/1773异步复位和置位在alwa

30、ys语句中异步描述的语句必须和敏感表中的事件沿一致在在always语句中异步描述的语句最后必须要有一个else,该语句为隐含时钟操作2024/9/1774异步复位、置位计数器module asynccounter(clk,preset,reset,predata,counter); input clk,preset,reset; input 1:0 predata; output 1:0 counter; reg 1:0 counter; always (posedge preset or posedge reset or posedge clk) if(preset) /异步置数异步置数 c

31、ounter =predata; else if(reset) /异步复位异步复位 counter =0; else /隐含时钟隐含时钟 counter=counter +1; /同步计数同步计数endmodule2024/9/17752024/9/1776异步置数,非0叫置位,0叫复位module asnycset(clk;preset,din,dout); input clk,preset; input 2:0 din; output 2:0 dout; reg 2:0 dout; always (posedge preset or posedge clk) if (preset) dou

32、t=5; else dout=din;endmodule2024/9/17772024/9/1778同步置位和复位module syncset(clk;preset,reset,din,dout); input clk,preset,reset; input 2:0 din; output 2:0 dout; reg 2:0 dout; always (posedge clk) if (reset) dout=3h0; else if (preset) dout=3h5; else dout=din;endmodule同步置位2024/9/17792024/9/1780函数的综合:例奇偶校验m

33、odule functionapp(datain,odd_even); input 3:0 datain; output odd_even; function parity; input 3:0 din; integer I; begin parity = 0; for(i=0;i4;i=i+1) if(dini) parity =parity+1; end endfunction assign odd_even =parityb (datain);endmodule 在verilog语言中,函数代表的是纯组合逻辑电路2024/9/17812024/9/1782任务的综合:module tas

34、kapp(a,b,clk,dataout); input clk; input 3:0 a,b; output 3:0 dataout; task bitxor; input 3:0 din1,din2; output 3:0 dout; integer I; begin for (i=0,i Flatten selected schematics HDL Analyst - Show Critical Path2024/9/171213.Assign timing constraints using SCOPE1)Create a new constraint fileFile - New

35、- Constraint File (Spreadsheet)2)edit3)Save the constraint file 4)Add the new constraint file to the list of source files in the project window2024/9/17122Assign attributes using SCOPE例:Select signalType in “ALSPIN” in the property columnAssign a pin number value of * in the value column2024/9/17123

36、Assign attributes using HDL source codeDisable I/O Insertion/* synthesis syn_noclockbuf = 1 */ 避免综合出锁存/* synthesis full_case */无优先级译码/* synthesis parallel_case */2024/9/17124FSM (Finite State Machine) Compiler Change the encoding style for the state machine using SCOPE use the “syn_encoding” attribu

37、te is to add this attribute to the HDL source code Reg?.? /* synthesis state_machine syn_encoding =“”; 2024/9/17125quartusII的使用建立工程添加文件参数设置、引脚绑定综合程序下载2024/9/17126Synplify pro 与quartusII的联合使用仿真工具设置建立工程,调用synplify综合结果和约束文件2024/9/17127SPI接口协议的Verilog HDL实现串行外设接口,Motorala开发的接口标准用途广泛2024/9/171282024/9/171292024/9/17130例:用Verilog HDL实现SPI0模式的SPI主模式,其中读写都是低字节在后、高字节在前,每次传送一个字节。2024/9/17131小结2024/9/17132

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号