Verilog数字系统设计.ppt

上传人:牧羊曲112 文档编号:6524412 上传时间:2023-11-09 格式:PPT 页数:57 大小:2.94MB
返回 下载 相关 举报
Verilog数字系统设计.ppt_第1页
第1页 / 共57页
Verilog数字系统设计.ppt_第2页
第2页 / 共57页
Verilog数字系统设计.ppt_第3页
第3页 / 共57页
Verilog数字系统设计.ppt_第4页
第4页 / 共57页
Verilog数字系统设计.ppt_第5页
第5页 / 共57页
点击查看更多>>
资源描述

《Verilog数字系统设计.ppt》由会员分享,可在线阅读,更多相关《Verilog数字系统设计.ppt(57页珍藏版)》请在三一办公上搜索。

1、数字系统设计(Verilog),-Verilog基本语法1,主要内容,模块结构;数据类型;变量;基本运算符号;,与C语言的比较,Hierarchical Design,E.g.,Module,module my_module(out1,.,inN);output out1,.,outM;input in1,.,inN;./declarations./description of f(maybe./sequential)endmodule,模块结构,由关键词:Moduleendmodule定义,模块结构,例1:D触发器,module dff_pos(data,clk,q)input data,c

2、lk;output q;reg q;,always(posedge clk)q=data;endmodule,Case sensitivitymyid Myid,模块引用,module top(D,CLK,Q)input D,CLK;Output Q;reg Q;dff_pos DFF1(.data(D),.clk(CLK),.q(Q)dff_pos DFF2(.data(D),.endmodule,Example:Half Adder,module half_adder(S,C,A,B);output S,C;input A,B;wire S,C,A,B;assign S=A B;assig

3、n C=A endmodule,Example:Full Adder,module full_adder(sum,cout,in1,in2,cin);output sum,cout;input in1,in2,cin;wire sum,cout,in1,in2,cin;wire I1,I2,I3;half_adder ha1(I1,I2,in1,in2);half_adder ha2(sum,I3,I1,cin);assign cout=I2|I3;endmodule,Instancename,Modulename,Hierarchical Names,ha2.A,Remember to us

4、e instance names,not module names,模块内部信号说明,regwire,wire signed PhaseWidth+5:0 SignPhaseError;reg signed PhaseWidth+5:0 SignPhaseError_d;,assign SignPhaseError=in_Dir?(-in_PE):in_PE;,always(posedge in_UpdateClk)begin if(in_ResetFilter)SignPhaseError_d=0;else SignPhaseError_d=SignPhaseError;end,连续赋值语句

5、、过程块、实例引用三项是顺序执行,但是always内的语句是顺序执行的。,基本词法,命名注释逻辑状态数字,数据命名规则,从以下符号中任意组合A-Z,a-z,0-9,_,$,但是不能以$或者 0-9数字开头myidentifierm_y_identifier3my_identifier$my_identifier_myidentifier$Case sensitivitymyid Myid,注释行,与C语言完全一致/The rest of the line is a comment/*Multiple line comment*/*Nesting/*comments*/do NOT work*/

6、,四种逻辑状态,0represents low logic level or false condition1represents high logic level or true conditionxrepresents unknown logic level(不定态)zrepresents high impedance logic level(高阻态),数字(i),8h ax=1010 xxxx12o 3zx7=011zzzxxx111,No of bits,Binary b or BOctal o or ODecimal d or DHexadecimal h or H,Consecut

7、ive chars 0-f,x,z,数字(ii),可以插入“_”符号便于阅读12b 000_111_010_100 12b 00011101010012o 07_24Bit extensionMS bit=0,x or z extend this4b x1=4b xx_x1MS bit=1 zero extension4b 1x=4b 00_1x,Represent the same number,数字(iii),如果 size(位宽)没标出,默认值是32位,每个字母用8位ASII码值表示 如果 radix(进制)没标出,默认为十进制15=d 15,数据类型,是对硬件电路中的信号连线和寄存器等

8、物理量的描述,而不是一般一般计算机语言的整型、实型等Verilog中两种数据类型:线型wire和寄存器型reg,区别在于:驱动方式(赋值方式)保持方式硬件实现,线型数据类型nets(i),用于连接器件原件,相当于版图中的金属走线当某个节点没有任何连接时,等效为高阻态 nets数据类型wirewand(wired-AND)wor(wired-OR)tri(tri-state)下面的例子中:只要A或者B发生变化,Y的值就会持续的自动更新,线型数据类型nets(ii),wire Y;/declarationassign Y=A,wand Y;/declarationassign Y=A;assign

9、 Y=B;,wor Y;/declarationassign Y=A;assign Y=B;,tri Y;/declarationassign Y=(dr)?A:z;,Reg型,可以用来存储数据可用来表示always模块内的指定信号Only one type:regreg A,C;/declaration/assignments are always done inside a procedureA=1;C=A;/C gets the logical value 1A=0;/C is still 1C=0;/C is now 0寄存器保持最后一次的赋值,端口定义,InputsOutputsIn

10、outs,矢量,代表总线buswire 3:0 busA;reg 1:4 busB;reg 1:0 busC;左边是最大位 MS bitSlice managementbusC1=busA2;busC0=busA1;矢量赋值(by position!)busB4=busA3;busB3=busA2;busB2=busA1;busB1=busA0;,busB=busA;,busC=busA2:1;,寄存器类型:整数和实数,Declarationinteger i,k;real r;在一个过程块中,实数可以当做寄存器用i=1;/assignments occur inside procedurer

11、=2.9;k=r;/k is rounded to 3整数没有默认的初始值!实数的默认初始值为0.0,寄存器类型:time,不对应具体的硬件电路Declarationtime my_time;Use inside proceduremy_time=$time;/get current sim timeSimulation runs at simulation time,not real time,标量和矢量,标量 线宽为1的连线类,或位宽为1的寄存器类 wire a,b,c;reg d,e,f;矢量 线宽大于1的连线类,或位宽大于1的寄存器类 wire7:0 bus_a,bus_b;reg15

12、:0 reg_d,reg_e;,矢量(i),Syntaxinteger count1:5;/5 integersreg var-15:16;/32 1-bit regsreg 7:0 mem0:1023;/1024 8-bit regsAccessing array elementsEntire element:mem10=8b 10101010;Element subfield(needs temp storage):reg 7:0 temp;.temp=mem10;var6=temp2;,矢量(ii),Limitation:Cannot access array subfield or e

13、ntire array at oncevar2:9=?;/WRONG!var=?;/WRONG!No multi-dimentional arraysreg var1:10 1:100;/WRONG!Arrays dont work for the Real data typereal r1:10;/WRONG!,字符串,Implemented with regs:reg 8*13:1 string_val;/can hold up to 13 chars.string_val=“Hello Verilog”;string_val=“hello”;/MS Bytes are filled wi

14、th 0string_val=“I am overflowed”;/“I”is truncated特殊字符:n换行ttab键%反斜杆“引号,参数定义,用文本来替代数字量格式 parameter parameter msb=7,lsb=0;方便阅读,可参数化设计,宏替换,用文本(宏名)替换verilog描述内容格式:结束无分号(;)引用中宏名前加“”宏名习惯用大写 define define MSB=7 define LSB=0 regMSB:LSB a;,模拟时间定标(i),对模拟器的时间单位和时间计算精度进行定标格式timescale/计时单位:模拟器的模拟单位时间 计时精度:模拟过程中的延

15、时量计时精度 结束没有“;”timescale 1ns/1ps,模拟时间定标(ii),timescale 1ns/100psmoduleAndFunc(Z,A,B);outputZ;input A,B;and#(5.22,6.17)Al(Z,A,B);/规定了上升及下降时延值。endmodule时延值5.22对应5.2 ns,时延6.17对应6.2 ns,系统命令,输出控制:$display,$write,$monitor模拟时标:$time,realtime进程控制:$finish,$stop文件读写:$readmem,运算符,表示物理量间的相互作用关系,反映硬件电路的物理特性。,算术运算符

16、(i),+,-,*,/,%如果某一个操作数是不定态x,则整个结果页为不定态 x无符号reg:无符号寄存器regs可为负数赋值,但是在算术运算中被当做是无符号数处理。reg 15:0 regA;.regA=-4d12;/stored as 216-12=65524regA/3evaluates to 21861,算术运算符(ii),无符号整数 integers:可以赋值负数 different treatment depending on base specification or notreg 15:0 regA;integer intA;.intA=-12/3;/evaluates to-4

17、(no base spec)intA=-d12/3;/evaluates to 1431655761(base spec),位运算符(i),按位运算,两个操作数不等长时,运算结果按长操作数补0或x&按位与运算|按位或运算 按位取反运算 按位异或运算 or 按位同或运算,位运算符(ii),c=a;,c=a,a=4b1010;b=4b1100;,a=4b1010;b=2b11;,c=a b;,缩位运算符,单目运算符,对操作数按位进行逻辑运算,结果是一位值!/c=1|0|0|1=1,逻辑运算符,表示运算关系的:“真”(1)与“假”(0)C|B x|0 x,关系运算符,大于=大于等于 0 1b1x1=

18、0 x10 z x,相等于全等运算符,=logical equality!=logical inequality=case equality!=case inequality4b 1z0 x=4b 1z0 x x4b 1z0 x!=4b 1z0 x x4b 1z0 x=4b 1z0 x 14b 1z0 x!=4b 1z0 x 0,Return 0,1 or x,Return 0 or 1,移位运算符,右移 2;/d=0010c=a 1;/c=0100,连接运算符,op1,op2,.concatenates op1,op2,.to single number 操作数必须标明位宽!reg a;reg 2:0 b,c;.a=1b 1;b=3b 010;c=3b 101;catx=a,b,c;/catx=1_010_101caty=b,2b11,a;/caty=010_11_1catz=b,1;/WRONG!重复信号的拼接方法.catr=4a,b,2c;/catr=1111_010_101101,条件运算符,Verilog中唯一的三目运算符格式:?:Like a 2-to-1 mux.若条件表达式为不定态,则结果为后两个表达式的逐位比较结果,A,B,Y,sel,Y=(sel)?A:B;,0,1,运算符的优先级,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号