Академический Документы
Профессиональный Документы
Культура Документы
2010/2011-2
INTRODUCTIONTO VERILOGHDL
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
OVERVIEW
VerilogwasadoptedasanofficialstandardasIEEEStandard1364 1995in1995. Anenhancedversion,calledVerilog2001,wasadoptedin2001as IEEEStandard13642001. Originallyintendedforsimulation,todayVerilogisdesignedto facilitatedescribedigitalhardwareforbothsimulationand synthesis. Verilogisagreatlowlevellanguage. StructuralmodelsareeasytodesignandBehavioralRTLcodeis prettygood.
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
Internalsignals, wireinta; variables, wire[3:0]intb; constants integer[7:0]counter; reg[0:7]temp; parameterC3b000; Component instantiation modulesystem1(); circuitU_comp(A,B); endmodule
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
assignDataout=Datain;
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
Controlflow a) If b) ifelse
if(en==1)f=x1; if(sel==0) beginf=x1;g=x2;end else beginf=x2;g=x1;end case(y) 0:f<=stateA; 1:f<=stateB; default:f<=stateC; endcase
c) case
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
BASICSOFVERILOG
Verilogdesignunit
modulemodule_name(ports); {parameterdeclarations} input<portlist>; //input/outputdeclarations: output<portlist>; wire<list>; //nets&variables: reg(orinteger)<list>; {assigncontinuousstatement;} //behaviourstatements: {initialblock;} {alwaysblocks;} {gateinstantiations;} {moduleinstantiations;} endmodule
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
Verilogdescribesadigitalcircuitorsystemasasetofmodules. TheentityusedinVerilogdescriptionofhardwarecomponentsisa module Followingthemoduleheaderisadeclarativepart,wheremodule ports,netsandvariablesaredeclared. AportinVerilogmaybeinput,output,orinout.Portsprovidethe modulewithameanstoconnecttoothermodules. Netsaretypicallydeclaredbythekeywordwire,connection betweenhardwareelements. Aportisautomaticallydeclaredaswireifitisdefinedasinput, output,orinout. Variables,declaredasreg,areusedforbehaviouraldescriptions, andareverymuchlikevariablesinsoftwarelanguages.
8
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
modulecircuitA(Cin,x,y,X,Y,Cout,s,Bus,S); inputCin,x,y; input[3:0] X,Y; outputCout,s; output[3:0] S; inout [7:0] Bus; wire d; reg e; endmodule
CADforElectronicDesign
10
L2:VERILOGHDL
2010/2011-2
RepresentationofNumbersinVerilog
CADforElectronicDesign
11
L2:VERILOGHDL
2010/2011-2
CADforElectronicDesign
12
L2:VERILOGHDL
2010/2011-2
Fancytotry?
CADforElectronicDesign
13
L2:VERILOGHDL
2010/2011-2
OperatorsinVerilog Operator type Bitwise Logical Arithmetic Relational Equality Operator symbol ~,&,|,^,~^ !,&&,|| +,,*,/ >,<,>=,<= ==,!= ===,!== Shift >>,<< Concatenation {,} Conditional ?: Operation not,and,or,xor,xnor not,and,or add,sub,mult,divide Gt,Lt,Gtoreq,Ltoreq Logicalequality,logicalinequality, caseequality,caseinequality Rightshift,Leftshift
CADforElectronicDesign
14
L2:VERILOGHDL
2010/2011-2
ConsiderthatA,B,andCtobeoperands,eithervectorsorscalar(1 bit).
The bitwise operator produce the same number of bits as the operands.E.g,A=a1a0,B=b1b0,C=c1c0,thenA|Bresultsin c1=a1|b1andc0=a0|b0. Thelogicaloperatorgeneratesaonebitresult.Usedinconditional statements. o A||Bresultsin1unlessbothAandBarezeros o A&&Bwillproducearesultof1ifbothAandBarenonzeros. o !Agivesa1ifallitsbitsare0,otherwiseitresultsina1. Therelationaloperatoroutputsa1or0basedonthe(specified) comparisonofAandB. Theshiftoperatorsperformlogical1bitshiftstotherightorleft, withzerosshiftedin.
15
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
In the case of the conditional operator, the operation A?B:C producearesultthatisequaltoBifAevaluatesto1,otherwisethe resultisC. The precedence of Verilog operators is similar to that found in arithmeticandBooleanalgebra.
CADforElectronicDesign
16
L2:VERILOGHDL
2010/2011-2
HDLMODELLINGOFDIGITALCIRCUITS
Different circuit complexities (e.g., simple modules to complete systems) require different kinds of specification or levels of abstraction. ThreemodellingstylesinHDLbaseddesignofdigitalsystems Structuralmodelling Dataflowmodelling Behaviouralmodelling
CADforElectronicDesign
17
L2:VERILOGHDL
2010/2011-2
Structural modelling using primitives and lowerlevel module instantiation. This modelling allows for the hierarchical modular design approach in design. It is used to describe a schematic or logicdiagram.Thefunctionalityofthedesignishiddeninsidethe components. Dataflowmodelling outputsignalsarespecifiedintermsofinput signal transformation. This style is similar to Boolean equations. This modelling style allows a digital system to be designed in termsofitsfunction. Behavioural modelling describes the function or expected behaviourofthedesigninanalgorithmicmanner.Thisstyleisthe closesttoanaturallanguagedescriptionofthecircuitfunctionality.
CADforElectronicDesign
18
L2:VERILOGHDL
2010/2011-2
DataflowModelling
modulefunc2(x1,x2,x3,f); input x1,x2,x3; outputf; assignf=(~x1&~x2&x3) |(x1&~x2&~x3) |(x1&~x2&x3) |(x1&x2&~x3); endmodule
CADforElectronicDesign
19
L2:VERILOGHDL
2010/2011-2
CADforElectronicDesign
20
L2:VERILOGHDL
2010/2011-2
NotesonConcurrent/Continuoussignalassignmentstatements InVerilog,concurrentassignmentstatementsarecalledcontinuous assignmentstatements. Lines5and6intheaboveVerilogcodearecontinuousassignment statements,bythefactthattheybeginwiththeassignkeyword. Theyareexecutedconcurrently,andthelineorderisnotimportant. Besidesconcurrentstatements,therearealsosequential(inVHDL jargon)orprocedural(inVerilogjargon)statements. Differing from concurrent statements, sequential statements are evaluatedintheorderinwhichtheyappearinthecode.
Verilogsyntaxrequirethemtobeinanalwaysblock.
CADforElectronicDesign
21
L2:VERILOGHDL
2010/2011-2
CADforElectronicDesign
22
L2:VERILOGHDL
2010/2011-2
StructuralModelling
Modulardesignoffulladderusinghalfadders moduleFA(cin,a,b,sum,cout); input cin,a,b; outputsum,cout; wires1,s2,s3; HAu1(a,b,s1,s2); HAu2(s1,cin,sum,s3); assigncout=s2|s3; endmodule
cin FA HA a b a b u1 sum cout HA
s1 s2 s3
a b
u2
sum cout
sum
cout
CADforElectronicDesign
23
L2:VERILOGHDL
2010/2011-2
InVerilogstructuralmodelling,moduleinstantiationisused. Theinstantiationstatementassociatesthesignalsintheinstantiated module(HA,inthiscase)withtheportsofthedesignunit(FAin thiscase). Here, positional association is applied, where each signal in the instantiationstatementismappedbypositiontothecorresponding signalinthemodule.
CADforElectronicDesign
24
L2:VERILOGHDL
2010/2011-2
BehaviouralModelling
At higher levels of design abstraction, a digital module is often modelledbehaviourally, The function or operation of the module is described in an algorithmicmanner. The HDL code will contain statements that are executed sequentiallyinapredefinedorder(orprocedure). Theorderofthesequential(orprocedural)statementsintheHDL codeisimportantandmayaffectthesemanticsofthecode.
CADforElectronicDesign
25
L2:VERILOGHDL
2010/2011-2
BehaviouralModellinginVerilog
Behavioural modelling in Verilog uses constructs similar to C languageconstructs. Sequential statements, like ifelse and case statements, are called proceduralstatements. Procedural statements be contained inside a construct called an alwaysblock Analwaysblockexecutesequentiallyintheordertheyarelistedin thesourcecode. The@symboliscalledtheeventcontroloperator.Thepartafterthe @symbol,istheeventcontrolexpression,alsoreferredtoasthe sensitivitylist. Thisvariableholdsitsvalueuntilthenexttimeaneventoccurson inputsinthesensitivitylist.
26
CADforElectronicDesign
L2:VERILOGHDL
2010/2011-2
moduleVcircuit(A,B,z); input [3:0]A,B; outputz; regz; always@(AorB) begin z=0; if(A==B)z=1; end endmodule
CADforElectronicDesign
27
L2:VERILOGHDL
2010/2011-2
Verilog syntax requires any signal assigned a value inside an alwaysblockhastobeavariableoftypereg;hencezisdeclaredas reg. Since z depends on A and B, these signals are included in the sensitivitylist. Blocking assignments, denoted by = symbol is used. The assignment completes and updates its LHS before the next statementisevaluated. We will cover nonblocking assignment, denoted by <= symbol lateron.
CADforElectronicDesign
28