Transcription of L5- Sequential Verilog - MIT
1 L5: Spring 20041 Introductory Digital Systems LaboratoryL5: simple Sequential Circuits and L5: simple Sequential Circuits and VerilogVerilogAcknowledgements: Nathan Ickes and Rex MinL5: Spring 20042 Introductory Digital Systems LaboratoryKey Points from L4 ( Sequential Blocks)Key Points from L4 ( Sequential Blocks)Classification: Latch: level sensitive (positive latch passes input to output on high phase, hold value on low phase) Register: edge-triggered (positive register samples input on rising edge) Flip-Flop: any element that has two stable states. Quite often Flip-flop also used denote an (edge-triggered) registerDClkQQDDClkQQDP ositiveLatchPositiveRegister Latches are used to build Registers (using the Master-Slave Configuration), but are almost NEVER used by itself in a standard digital design flow.
2 Quite often, latches are inserted in the design by mistake ( , an error in your Verilog code). Make sure you understand the difference between the two. Several types of memory elements (SR, JK, T, D). We will most commonly use the D-Register, though you should understand how the different types are built and their : Spring 20043 Introductory Digital Systems LaboratoryKey Points from L4 : System TimingKey Points from L4 : System TimingDClkQInCombinationalLogicDClkQCLKT suThTsuThTcqTcq,cdTcqTcq,cdFF1 INCLoutCLoutTl,cdTsuTlogicT > Tcq+ Tlogic+ TsuTcq,cd+ Tlogic,cd> TholdL5: Spring 20044 Introductory Digital Systems LaboratoryThe Sequential The Sequential alwaysalwaysBlockBlock Edge-triggered circuits are described using a Sequential alwaysblockmodule combinational(a, b, sel,out);input a, b;input sel;output out;reg out;always @ (a or b or sel) beginif (sel) out = a;else out = b;end endmodulemodule Sequential (a, b, sel, clk, out);input a, b;input sel, clk;output out;reg out;always @ (posedge clk) beginif (sel) out <= a;else out <= b.
3 End endmoduleCombinationalSequential10selout ab10seloutabDQclkL5: Spring 20045 Introductory Digital Systems LaboratoryNote: The following is incorrectsyntax:always @ (clear or negedge clock)If one signal in the sensitivity list uses posedge/negedge, then all signals must. Assign any signal or variable from only onealways block, Be wary of race conditions: always blocks execute in parallelImportance of the Sensitivity ListImportance of the Sensitivity List The use of posedgeand negedgemakes an alwaysblock Sequential (edge-triggered) Unlike a combinational alwaysblock, the sensitivity list doesdetermine behavior for synthesis!
4 Module dff_sync_clear(d, clearb, clock, q);input d, clearb, clock;output q;reg q;always @ (posedge clock) beginif (!clearb) q <= 1'b0;else q <= d; endendmoduleD Flip-flop with synchronousclearD Flip-flop with asynchronousclearmodule dff_async_clear(d, clearb, clock, q);input d, clearb, clock;output q;reg q;always @ (negedge clearb or posedge clock) beginif (!clearb) q <= 1 b0;else q <= d;endendmodulealwaysblock entered only at each positive clock edgealwaysblock entered immediately when (active-low) clearb is assertedL5: Spring 20046 Introductory Digital Systems LaboratorySimulationSimulationtc-qClear on Clock Edge DFF with Synchronous ClearClear happens on falling edge of clearb DFF with Asynchronous ClearL5: Spring 20047 Introductory Digital Systems Laboratory1.
5 Evaluate a| bbut defer assignment of x2. Evaluate a^b^cbut defer assignment of y3. Evaluate b&(~c) but defer assignment of z1. Evaluate a| b, assign result to x2. Evaluate a^b^c, assign result to y3. Evaluate b&(~c), assign result to zBlocking vs. Blocking vs. NonblockingNonblockingAssignmentsAssignm ents Verilog supports two types of assignments within alwaysblocks, with subtly different behaviors. Blocking assignment: evaluation and assignment are immediate Nonblocking assignment: all assignments deferred until all right-hand sides have been evaluated (end of simulation timestep) Sometimes, as above, both produce the same result.
6 Sometimes, not!always @ (a or b or c)beginx = a | b;y = a ^ b ^ c;z = b endalways @ (a or b or c)beginx <= a | b;y <= a ^ b ^ c;z <= b end4. Assign x, y, and zwith their new valuesL5: Spring 20048 Introductory Digital Systems LaboratoryAssignment Styles for Sequential LogicAssignment Styles for Sequential Logic Will nonblocking and blocking assignments both produce the desired result?module nonblocking(in, clk, out);input in, clk;output out;reg q1, q2, out;always @ (posedge clk) beginq1 <= in;q2 <= q1;out <= q2;end endmoduleDQDQDQ inoutq1q2clkFlip-Flop Based Digital Delay Linemodule blocking(in, clk, out);input in, clk;output out;reg q1, q2, out;always @ (posedge clk) beginq1 = in;q2 = q1;out = q2;end endmoduleL5: Spring 20049 Introductory Digital Systems LaboratoryUse Use NonblockingNonblockingfor Sequential Logicfor Sequential Logicalways @ (posedge clk) beginq1 <= in;q2 <= q1;out <= q2;endalways @ (posedge clk) beginq1 = in;q2 = q1;out = q2.
7 End DQDQDQ inoutq1q2clkDQinoutclk At each rising clock edge, q1, q2, and outsimultaneously receive the old valuesof in, q1, and q2. At each rising clock edge, q1= in. After that,q2= q1 = in. After that,out= q2 = q1 = in. Therefore out= in. Blocking assignments do not reflect the intrinsic behavior of multi-stage Sequential logic Guideline: use nonblocking assignments for Sequential alwaysblocksq1q2L5: Spring 200410 Introductory Digital Systems LaboratorySimulationSimulation Non-blocking Simulation Blocking SimulationL5: Spring 200411 Introductory Digital Systems LaboratoryUse Blocking for Combinational LogicUse Blocking for Combinational Logic Nonblocking and blocking assignments will synthesize correctly.
8 Will both styles simulate correctly? Nonblocking assignments do not reflect the intrinsic behavior of multi-stage combinational logic While nonblocking assignments can be hacked to simulate correctly (expand the sensitivity list), it s not elegant Guideline: use blocking assignments for combinational alwaysblocksx <= a Assignment completion(Given) Initial Conditionachanges; alwaysblock triggereda b c x y Deferred1 1 0 1 101 0 1 10 10 1 1 x<=00 1 0 11 x<=0, y<=10 1 0 01y <= x | c;Nonblocking Behaviorx = a (Given) Initial Conditionachanges; alwaysblock triggeredy = x | c.
9 Blocking Behaviora b c x y1 1 0 1 101 0 1 10 10 010 1 0 00module nonblocking(a,b,c,x,y);input a,b,c;output x,y;reg x,y;always @ (a or b or c) beginx <= a y <= x | c;end endmodulemodule blocking(a,b,c,x,y);input a,b,c;output x,y;reg x,y;always @ (a or b or c) beginx = a y = x | c;end endmoduleabcxyL5: Spring 200412 Introductory Digital Systems LaboratoryThe Asynchronous Ripple CounterThe Asynchronous Ripple CounterA simple counter architecture uses only registers ( , 74HC393 uses T-register and negative edge-clocking) Toggle rate fastest for the ripple architecture leads to large skew between outputsClockDQQDQQDQQDQQC ount[0]Count [3:0]ClockCount [3]Count [2]Count [1]Count [0]SkewD register set up to always toggle: , T Register with T=1 Count[1]Count[2]Count[3]L5.
10 Spring 200413 Introductory Digital Systems LaboratoryThe Ripple Counter in The Ripple Counter in VerilogVerilogmodule dreg_async_reset (clk, clear, d, q, qbar);input d, clk, clear;output q, qbar;reg q;always @ (posedge clk or negedge clear)beginif (!clear) q <= 1'b0;else q <= d;endassign qbar = ~q;endmoduleClockDQQDQQDQQDQQC ount[0]Count [3:0]Count[1]Count[2]Count[3]module ripple_counter(clk, count, clear);input clk, clear;output [3:0] count;wire [3:0] count, countbar;dreg_async_reset bit0(.clk(clk), .clear(clear), .d(countbar[0]),.q(count[0]), .qbar(countbar[0]));dreg_async_reset bit1(.)