veriloghdl(自学)

上传人:xh****66 文档编号:61936044 上传时间:2018-12-15 格式:PPT 页数:29 大小:429KB
返回 下载 相关 举报
veriloghdl(自学)_第1页
第1页 / 共29页
veriloghdl(自学)_第2页
第2页 / 共29页
veriloghdl(自学)_第3页
第3页 / 共29页
veriloghdl(自学)_第4页
第4页 / 共29页
veriloghdl(自学)_第5页
第5页 / 共29页
点击查看更多>>
资源描述

《veriloghdl(自学)》由会员分享,可在线阅读,更多相关《veriloghdl(自学)(29页珍藏版)》请在金锄头文库上搜索。

1、第七章 用Verilog HDL设计数字电路,主要内容:,7.1 常用组合电路的设计,门电路的描述,译码器、编码器,数据选择器,奇偶校验器,BCD码-七段 译码器,运算电路(补充),7.2常用时序电路模块,D触发器,数据锁存器,数据寄存器,移位寄存器,各种计数器,7.1 常用组合电路的设计(组合电路以自学为主),1.基本门电路的描述,7.1.1 简单门电路的描述,方法1:调用门原语,module gate1(F, A, B, C, D); input A, B, C, D; output F; wire F1,F2; nand G1 ( F1, A, B ); and G2 ( F2, B,

2、C, D); or G3 ( F, F1, F2); endmodule,门的名称:可省略。,原语,多输入门:原语名 (输出,输入1,输入2),调用格式:,非门: 原语名 (输出,输入),结构描述,方法2:用assign连续赋值语句描述,module gate2(F,A,B,C,D); input A,B,C,D; output F; assign F=(A endmodule,方法3:用过程赋值语句描述,module gate3(F,A,B,C,D); input A,B,C,D; output F; reg F; always (A or B or C or D) begin F=(A e

3、nd endmodule,敏感信号表: 与同步时序电路差别?,逻辑表达式,2.三态门,例7.2 用bufifl关键字描述的三态门,module tristate(in, oe, out); input in, oe; output out; tri out; /注意三态门端口的排列顺序 bufif1 b1(out, in, oe);/(输入,输出,使能) endmodule,例7.3 用assign描述的三态门,module tri_1(out, in, en); output out; input in, en; assign out = en ? in : 1bz; /若en = 1, o

4、ut = in;若en = 0 ,out为高阻态 endmodule,与wire一样,例7.4 用三态双向驱动器,module bidir(tri_inout , out , in , en , b); inout tri_inout; output out; input in, en, b; assign tri_inout = en ? in : 1bz;/三态门 assign out = tri_inout b; endmodule,双向端口,7.1.2译码器、编码器,1. 3线_8线译码器(输出低电平有效),module edcoder_38(out, in); output7:0 o

5、ut; input2:0 in; reg7:0 out; always (in) begin case(in) 3d0: out = 8b1111_1110; 3d1: out = 8b1111_1101; 3d2: out = 8b1111_1011; 3d3: out = 8b1111_0111; 3d4: out = 8b1110_1111; 3d5: out = 8b1101_1111; 3d6: out = 8b1011_1111; 3d7: out = 8b0111_1111; endcase end endmodule,分隔符,便于阅读,真值表,2. 8 线_ 3线高优先编码器,

6、方法1:用if_else语句描述编码器,module encoder8_3(none_on,outcode,a, b, c, d, e, f, g, h); output2:0 outcode; output none_on; input a, b, c, d, e, f, g, h; reg3:0 outtemp; assign none_on, outcode = outtemp; always (a or b or c or d or e or f or g or h) begin if(h) outtemp = 4b0_111; else if(g) outtemp = 4b0_110

7、; else if(f ) outtemp = 4b0_101; else if(e) outtemp = 4b0_100; else if(d) outtemp = 4b0_011; else if(c) outtemp = 4b0_010; else if(b) outtemp = 4b0_001; else if(a) outtemp = 4b0_000; else outtemp = 4b1_000; end endmodule,引进变量,便于描述,none_on,outcode,方法2:用case语句描述编码器,module encoder_83(none_on,outcode,a,

8、 b, c, d, e, f, g, h); output2:0 outcode; output none_on; input a, b, c, d, e, f, g, h; reg3:0 outtemp; assign none_on, outcode = outtemp; always (a or b or c or d or e or f or g or h) begin casex (a, b, c, d, e, f, g, h) 8B?_?1 : outtemp=4b0_111; 8B?_?10 : outtemp=4b0_110; 8B?_?100 : outtemp=4b0_10

9、1; 8B?_1000 : outtemp=4b0_100; 8B?1_0000 : outtemp=4b0_011; 8B?10_0000 : outtemp=4b0_010; 8B?100_0000 : outtemp=4b0_001; 8B1000_0000 : outtemp=4b0_000; 8B0000_0000 : outtemp=4b1_000; endcase end endmodule,真值表,7.1.3 数据选择器,1. 用assign语句设计2选1 MUX,module mux2_1(out , a , b , sel); output out; input a, b,

10、 sel; assign out = sel ? a : b; endmodule,sel=1:out=a sel=0:out=b,module mux4_1(out , in0 , in1 , in2 , in3 , sel); output out ; input7:0 in0 , in1 , in2 , in3 ; input1:0 sel; reg7:0 out ; always (in0 or in1 or in2 or in3 or sel) begin if(sel= 2b00) out = in0; else if(sel = 2b01) out = in1; else if(

11、sel = 2b10) out = in2; else out = in3; end endmodule,2. 用if-else语句描述4选1 MUX,功能描述,共有8个4选1 MUX, 它们共用sel信号,3. 用case语句描述4选1 MUX,module mux_4_1(out , in0 , in1 , in2 , in3 , sel); output7:0 out ; input7:0 in0 , in1 , in2 , in3 ; input1:0 sel; reg7:0 out ; always (in0 or in1 or in2 or in3 or sel) begin ca

12、se(sel) 2b00: out = in0; 2b01: out = in1; 2b10: out = in2; default: out = in3; endcase end endmodule,共有8个4选1 MUX, 它们共用sel信号,真值表,7.1.4 奇偶校验器,例7.10 奇偶位产生器,module parity(even_bit ,odd_bit , input_bus); output even_bit ,odd_bit ; input7:0 input_bus; assign odd_bit = input_bus; /产生奇校验位 assign even_bit =

13、odd_bit; /产生偶校验位 endmodule,奇校验:输入数据“1”的个数为奇数。可用“异或”运算,偶校验:输入数据“1”的个数为偶数。可用“同或”运算,仿真:,module decode4_7(a,b,c,d,e,f,g,D); output a,b,c,d,e,f,g; input3:0 D; reg a,b,c,d,e,f,g; always (D) begin case(D) 4d0 : a,b,c,d,e,f,g=7b1111110; 4d1 : a,b,c,d,e,f,g=7b0110000; 4d2 : a,b,c,d,e,f,g=7b1101101; 4d3 : a,b

14、,c,d,e,f,g=7b1111001; 4d4 : a,b,c,d,e,f,g=7b0110011; 4d5 : a,b,c,d,e,f,g=7b1011011; 4d6 : a,b,c,d,e,f,g=7b1011111; 4d7 : a,b,c,d,e,f,g=7b1110000; 4d8 : a,b,c,d,e,f,g=7b1111111; 4d9 : a,b,c,d,e,f,g=7b1111011; default : a,b,c,d,e,f,g=7bx; endcase end endmodule,7. 1 .5 :BCD码-七段 译码器(共阴),真值表,7.1.6 运算电路(补

15、充),一、加法器:,module adder_n (cout, sum, ina,inb, cin); parameter n=16; outputn:1 sum; output cout; inputn:1 ina,inb; input cin; assign cout,sum=ina+inb+cin; endmodule,逻辑图:,例:带进位的n位通用加法器,二、比较器,module compare_n (great, equal, Small,ina,inb); parameter n=16; output great, equal, Small; inputn:1 ina,inb; assign great=(inainb); assign equal=(ina=inb); assign Small=(inainb); endmodule,例:n位比较器,7.1.7、双向三态端口的描述,module tri_inout(tri_inout,out,data,en,clk); in

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

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