Verilog硬件描述语言(二)三目运算符.ppt_第1页
Verilog硬件描述语言(二)三目运算符.ppt_第2页
Verilog硬件描述语言(二)三目运算符.ppt_第3页
Verilog硬件描述语言(二)三目运算符.ppt_第4页
Verilog硬件描述语言(二)三目运算符.ppt_第5页
已阅读5页,还剩59页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

,Verilog硬件描述语言 (二),2,课程内容,一、Verilog HDL 运算符 二、Verilog HDL 语句 三、可综合设计,一、Verilog HDL 运算符,按功能分: 算术运算符、逻辑运算符、关系运算符、缩减运算符、条件运算符、位运算符、移位运算符、拼接运算符等类。 按操作数的个数分: 单目运算符、双目运算符、三目运算符。,一、Verilog HDL 运算符,算术运算符 (Arithmetic operator),+ 加 - 减 * 乘 / 除 % 求模,一、Verilog HDL 运算符,逻辑运算符(Logical operator),& 逻辑与 | 逻辑或 ! 逻辑非,一、Verilog HDL 运算符,一、Verilog HDL 运算符,位运算符(Bitwise operator), 按位取反 & 按位与 | 按位或 按位异或 , 按位同或,一、Verilog HDL 运算符,按位与真值表,按位或真值表,按位异或真值表,一、Verilog HDL 运算符,关系运算符 (Relational operator), 大于 = 大于或等于 注意: “=”操作符还用于信号的一种赋值,一、Verilog HDL 运算符,缩位运算符(Reduction operator),& 与非 & 与 | 或 | 或非 异或 , 同或,一、Verilog HDL 运算符,缩位运算符与位运算符的逻辑运算法则一样,但缩位运算是对单个操作数进行与、或、非递推运算,它放在操作数前面。 缩位运算符将一个矢量缩减为一个标量 如: reg3:0 a; b=,一、Verilog HDL 运算符,移位运算符 (Shift operator),移位操作符只有两个:左移和右移 用法: An或An; 表示把操作数右移或左移n位;移出的位用0添补, 右移 左移,一、Verilog HDL 运算符,条件运算符 (Conditional operator),这是一个三目运算符,对3个操作数进行运算。 用法: signal=condition?true_expression:flase_expression; 即:信号=条件?表达式1:表达式2; 条件成立时,信号取表达式1的值,反之取2。,?,一、Verilog HDL 运算符,举例:,一、Verilog HDL 运算符,位接运算符, ,用法: 信号1的某几位,信号2的某几位,信号n的某几位,举例:assign cout,sum=a+b+cin;,二、Verilog HDL 语句,分类,二、Verilog HDL 语句,过程语句:always,always () begin /过程赋值 /if-else,case选择语句 end,二、Verilog HDL 语句,敏感信号类型: (a) (a or b) (posedge clock) (negedge clock) (posedge clk or negedge reset),举例:DFF,module DFF (d , clk, reset, q, qb ); output q, qb; input clk, reset,d; reg q, qb; always (posedge clk) begin if (!reset) begin q =0; qb=1; end else begin q =d; qb=d; end end endmodule,二、Verilog HDL 语句,特点:,只有两种状态:执行状态和等待状态 一般由敏感信号的变化来启动 各个always间通过信号线进行通信 一个always中只允许描述对应于一个时钟信号的同步时序逻辑 always之间是并发执行的,二、Verilog HDL 语句,块语句:begin end,总是在always内部 按顺序执行,二、Verilog HDL 语句,举例:,reg qa,qb,qc; always (posedge clk) begin qa =d; qb =qa; qc =qb; end,二、Verilog HDL 语句,赋值语句:,持续赋值语句 过程赋值语句,二、Verilog HDL 语句,持续赋值语句:,assign c=a,二、Verilog HDL 语句,过程赋值语句:,非阻塞赋值 “ = ” 阻塞赋值 “ = ” 分为两步骤:右式计算、左式更新,二、Verilog HDL 语句,非阻塞赋值 :,当前语句的执行不会阻塞下一语句的执行 语句之间并发执行 左式更新在块结束后才进行,二、Verilog HDL 语句,阻塞赋值 :,当前语句的执行会阻塞下一语句的执行 语句之间顺序执行 右式计算和左式更新同时进行,举例 :,module nonblocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin y=a; b=y; end end endmodule,结果 :,举例 :,module nonblocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin b=y; y=a; end end endmodule,结果 :,举例 :,module blocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin y=a; b=y; end end endmodule,结果 :,举例 :,module blocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin b=y; y=a; end end endmodule,结果 :,举例 :,module nonblocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin y=a; b=y; end end endmodule,结果 :,举例 :,module nonblocking(clk,reset,a,b); input clk,reset; input 3:0a; output 3:0b; reg 3:0b;reg 3:0y; always (posedge clk or negedge reset) begin if(!reset) begin y=0; b=0; end else begin y=a; b=y; end end endmodule,结果 :,阻塞非阻塞使用原则:,有clock的always进程要使用non-blocking,always(posedge clk or negedge reset_n) begin if (!reset_n) counter = 8b00; else counter = counter + 1; end,二、Verilog HDL 语句,always(sel or a or b) begin case (sel) 2b00 : c = a; 2b01 : c = b; endcase end,无clock的always进程使用blocking,二、Verilog HDL 语句,二、Verilog HDL 语句,continuous assignment使用blocking,一个always进程中不要同时使用blocking与non-blocking,assign y = a,二、Verilog HDL 语句,书P286页图8-10错误 参考MIT课件,说明:,二、Verilog HDL 语句,条件语句:,if else case endcase,二、Verilog HDL 语句,if else :,if (表达式) 语句1; if (表达式) 语句1; else 语句2; if (表达式1) 语句1; else if (表达式2) 语句2; else if (表达式3) 语句3; else if (表达式n) 语句n; else 语句n+1;,二、Verilog HDL 语句,特点 :,不完整的if else容易导致产生latch 总是在always内部按顺序执行,二、Verilog HDL 语句,Latch与DFF比较:,latch由电平触发,DFF由时钟沿触发 latch容易产生毛刺(glitch),DFF则不易产生毛刺 latch消耗的门资源比DFF要少,但耗费的LE资源要多 latch将静态时序分析变得极为复杂,二、Verilog HDL 语句,case endcase :,case (敏感表达式) 值1: 语句1; 值2: 语句2; 值n: 语句n; default: 语句n+1; endcase,二、Verilog HDL 语句,特点 :,不完整的case endcase容易导致产生latch 总是在always内部根据敏感量执行,二、Verilog HDL 语句,比较 :,if else带有优先级 case endcase延时小,举例 :四位选择器,always(sel) begin if (sel=2b00) out=in0; else if (sel=2b01) out=in1; else if (sel=2b10) out=in2; else out=in3; end,always(sel) begin case (sel) 2b00: out=in0; 2b01: out=in1; 2b10 : out=in2; default: out=in3; end,举例 :七段数码管显示译码器,module decode4_7(decodeout,indec); output6:0 decodeout; input3:0 indec; reg6:0 decodeout; always (indec) begin case(indec) 4d0: decodeout=7b1111110; 4d1: decodeout=7b0110000; 4d2: decodeout=7b1101101; 4d3: decodeout=7b1111001; 4d4: decodeout=7b0110011; 4d5: decodeout=7b1011011; 4d6: decodeout=7b1011111; 4d7: decodeout=7b1110000; 4d8: decodeout=7b1111111; 4d9: decodeout=7b1111011; default: decodeout=7b1111111; endcase end endmodule,三、可综合设计,要点 :,不使用初始化语句,不使用任务和函数 不使用带有延时的描述 不使用for循环 在always里面慎用乘法和除法,举例 :,module test_13(clk,rst_n,data,num); input clk,rst_n; input 12:0data; output 3:0num; reg 3:0i; reg 3:0num; always(posedge clk) begin if(!rst_n) num=0; else begin for(i=0;i13;i=i+1) if(datai) num=num+1; end end endmodule,结果 :,举例 :,module multip(clk,rst_n,a,b,num); input clk,rst_n; input 7:0a; input 7:0b; output 15:0num; reg 15

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论