E N D
Overview • LogicDesignreview • BasicBuildingBlocks • DesignExamples:Incrementer,Fifo • Verilog:CodingBasicblocks • Useof Modules • Gates,Mux/Demux,Registers • DataValues • CounterExample
LogicDesignReview RegisterTransferLevel (RTL)Design
LogicDesign • BasicbuildingblocksforLogic designare • Gates • Muxes/Demuxes • Registers/Memory • ArithmeticOperations(Adder, Subtracter,Multipliersetc.) • Statemachines • AnycombinationsofAbove
Gates Inputs Outputs
Input[N:0] Clock Reset Output[N:0] Clock Input[N:0] 3 4 5 6 Output[N:0] x 3 4 5
Input[N:0] Clock Enable Output[N:0] Clock Input[N:0] 3 4 5 6 Output[N:0] x 5 Enable
SelectLines/Address Output Inputs
Address[N:0] DataOut[K:0] Write DataIn[K:0] RegistersFile
Address[N:0] DataOut[K:0] Write DataIn[K:0] MEMORY RegistersFile
Input1[N:0] Input2[N:0] Output[N+1:0] Adder/ Subtracter Cin Add/Sub Saturate Input1[N:0] Input2[N:0] Output[2N:0] Multiplier Signed/Unsigned Saturate
MakingnewModules,Using ExistingModules • DesignExamples • Example1: • Asimpledecrementercapable of countingnumberofclockcycles downtozero. • Example2: • AfourdeepFIFO
Decrementer Initial Value[N:0] Decrement -- Count Load Enable Clock Reset
FourdeepFIFO Datain[N:0] Push Dataout[N:0 FIFOFull ==4 Increment Pop counter Decrement FIFOEmpty ==0
++ -- Increment Decrement Count Increment counter Decrement
FIFO Datain[N:0] Push Dataout[N:0 FIFOFull ==4 Increment Pop counter Decrement FIFOEmpty ==0
FIFO DMA PROCESSORA MEMORY SDRAM PROCESSORB MEMORY
Othercomponents Somewayto configure FilterTaps Somewayto takeOutput Somewayto provideInput FIRFilter Somewayto takeOutput Somewayto provideInput FFT Somewayto takeOutput Somewayto provideInput Error Correction
Verilog IntroductiontoModules
Verilog Module:Areasonablesize replicate-ableblocke.g.FIFO, counteranddecrementerthatwe coveredaregoodcandidates.
FIFO DMA PROCESSORA MEMORY SDRAM PROCESSORB MEMORY
fifo.v data_in push data_out fifo_full pop fifo_empty
fifo.v counter.v
modulecounter( inputinput output[3:0] increment, decrement, count ); Codeformode endmodule modulefifo( input input input data_in, push, pop, [15:0] lingCounter output[15:0] data_out, output output ); fifo_full, fifo_empty ThecodeformodelingFIFOhere endmodule
modulecounter( inputinput output[3:0] increment, decrement, count ); Codeformode endmodule wirepush; wirepop; wire[3:0]count; lingCounter countercounter_inst1( .increment(push), .decrement .count ); (pop), (count) counter
Summary • Ablocklevelhierarchycanbe modeledasmodules. • Moduleisthebasicbuilding block. • Amodulecanbeinstantiated insideanothermodule. • Modulecanbereplicatedwitha differentinstancename.
Verilog Basicbuildingblocks
BasicBuildingBlocks • BasicbuildingblocksforLogic designare • Gates • Muxes/Demuxes • Registers/Memory • ArithmeticOperations(Adder, Subtracter,Multipliersetc.) • Statemachines
Whatwearetryingtodo? Wearetryingtomodelour buildingblocksusingwordsand charactersorganizedinaset offiles
ModelingMuxes/Demuxes always@(*) begin addr case(addr) endcase end MUX
DataValues 8’hXA 8’bXXXX_1010 8’hA 8’d10 8’b0000_1010 Underscores areignored BaseFormat (b,o,d,h) Width X’sshowdon’t carevalues
ModelingMuxes/Demuxes always@(*) begin addr case(addr) endcase end DEMUX
ModelingMuxes/Demuxes addr always@(*) begin case(addr) 2’d0: {a,b,c,d}={in,3’d0}; 2’d1:{a,b,c,d}={1’d0,in,2’d0}; 2’d2:{a,b,c,d}= {2’d0,in,1’d0}; 2’d3:{a,b,c,d}= {3’d0,in}; endcase end DEMUX
concatenation c 0000 a[3:0] b[2:0] data_in={a,b,4’d0,{3{c}}}; data_in[13:0] MEMORY
ModelingMuxes/Demuxes addr always@(*) begin case(addr) 2’d0: 2’d1: 2’d2: 2’d3: 0 0 0 endcase end
ModelingRegisters always@(posedgeclk) begin clk reset reg_out[N:0]
ArithmeticOperations a[N:0] b[N:0] c[N+1:0] Adder/ Subtracter cin add/sub saturate always@(*) begin c=a+b; end a[N:0] b[N:0] c[2N:0] Multiplier c=a-b; c=a*b; signed/unsigned saturate
Declarations reg [16:0]c; always@(*) c= a+b; wire[16:0]c; assign c= a+ b; a[15:0] b[15:0] Whatabouta&b? Shouldtheybe wireorreg? Adder c[16:0] always@(posedgeclk) c<=#1a+b;
VerilogCoding • MakeaDesignDiagram • Codeallthebuildingblocks • Namethewiresinthedesign diagram • Declarethemoduleportlist • Startcodingthelogicelements onebyone • DeclareVariables
modulecounter( input input input input clk, reset, increment, decrement, outputreg[3:0]count ); regenable; reg[3:0]mux_out; Example1:counter.v always@(*) enable=increment|decrement; always@(*) begin case(increment) 1’b0:mux_out= count-1; 1’b1:mux_out=count+1; endcase end always@(posedgeclk) if(reset) count<=#10; elseif(enable) count<=#1mux_out; endmodule dec_out inc_out ++ -- mux_out increment enable decrement count
Verilog LogicVerification
Generate Inputs ModuleUnder Test(DUT) DUTModel OR Reference Outputs Monitor Outputs == Monitor results TestBench
Example:TestBench forcounter counter.v
Example:TestBench forcounter moduletb_counter; regclk; regreset;regincrement; regdecrement; wire[3:0]count; countercounter_inst(
moduletb_counter; clkreset increment decrement xxxx count[3:0] 0000 000100100001 initial begin clk=0; forever #5clk= end Cstyleblock executing statements sequentially unlesswemove forwardintime axisusing# ,@(something), waitetc. ~clk; endmodule
moduletb_counter; clk reset increment decrement xxxx count[3:0] 0000 000100100001 Cstyleblock executing statements sequentially unlesswemove forwardintime axisusing# ,@(something), waitetc. endmodule
initial begin increment=0; decrement=0; reset=0; @(posedgeclk) reset<=#1 1; @(posedgeclk) reset<=#1 0; @(posedgeclk); #1increment= 1; repeat(2)@(posedgeclk); Cstyleblock executing statements sequentially unlesswemove forwardintime axisusing# ,@(something), waitetc. @(posedgeclk); #1decrement= 0; repeat(20)@(posedgeclk); $stop; end