Sequential Logic .Sel(F[0]), .Out(Addmux Out));
Total Page:16
File Type:pdf, Size:1020Kb
Use Explicit Port Declarations module mux32two (input [31:0] i0,i1, input sel, output [31:0] out); assign out = sel ? i1 : i0; endmodule mux32two adder_mux(.i0(b), .i1(32'd1), Sequential Logic .sel(f[0]), .out(addmux_out)); • Digital state: the D-Register mux32two adder_mux(b, 32'd1, f[0], addmux_out); • Timing constraints for D-Registers 2 • Specifying registers in Verilog • Blocking and nonblocking assignments Order of the ports matters! • Examples Reminder: Lab #2 due Thursday 6.111 Fall 2016 Lecture 4 1 6.111 Fall 2015 Verilog Summary Examples • Verilog – Hardware description language – not software program. parameter MSB = 7; // defines msb as a constant value 7 • A convention: lowercase for variables, UPPERCASE for parameter E = 25, F = 9; // defines two constant numbers parameters module blob #(parameter WIDTH = 64, // default width: 64 pixels parameter BYTE_SIZE = 8, HEIGHT = 64, // default height: 64 pixels BYTE_MASK = BYTE_SIZE - 1; COLOR = 3'b111) // default color: white (input [10:0] x,hcount, input [9:0] y,vcount, output reg [2:0] pixel); endmodule parameter [31:0] DEC_CONST = 1’b1; // value converted to 32 bits • wires wire a,b,z; // three 1-bit wires wire [31:0] memdata; // a 32-bit bus parameter NEWCONST = 3’h4; // implied range of [2:0] wire [7:0] b1,b2,b3,b4; // four 8-bit buses wire [WIDTH-1:0] input; // parameterized bus parameter NEWCONS = 4; // implied range of at least [31:0] 6.111 Fall 2016 Lecture 4 3 6.111 Fall 2016 Lecture 4 4 Something We Can’t Build (Yet) Digital State One model of what we’d like to build What if you were given the following design specification: Next State Memory When the button is pushed: 1) Turn on the light if Device Current it is off State Combinational button 2) Turn off the light if light LOAD it is on Logic The light should change state within a second Input Output of the button press What makes this circuit so different Plan: Build a Sequential Circuit with stored digital STATE – from those we’ve discussed before? • Memory stores CURRENT state, produced at output 1. “State” – i.e. the circuit has memory • Combinational Logic computes 2. The output was changed by a input • NEXT state (from input, current state) When Output depends on input and current state, circuit is “event” (pushing a button) rather • OUTPUT bit (from input, current state) called a Mealy machine. If than an input “value” Output depends only on the • State changes on LOAD control input current state, circuit is called a Moore machine. 6.111 Fall 2016 Lecture 4 5 6.111 Fall 2016 Lecture 4 6 Our next building block: the D register D-Register Timing - I The edge-triggered D register: on ≤tPD the rising edge of CLK, the value of ≥t D is saved in the register and then CD shortly afterwards appears on Q. Q CLK D D ≥t ≥t CLK tPD: maximum propagation delay, CLK Q SETUP HOLD tCD: minimum contamination delay, CLK Q Q tSETUP: setup time How long D must be stable before the rising edge of CLK tHOLD: hold time How long D must be stable after the rising edge of CLK 6.111 Fall 2016 Lecture 4 7 6.111 Fall 2016 Lecture 4 8 D-Register Internals – 74LS74 D-Register Timing - II ≤tPD DQ logic DQ reg1 reg2 ≥tCD Q CLK tCLK CLK tPD,reg1 D CLK tPD,logic ≥tSETUP ≥tHOLD tCD,reg1 CLK tSETUP = 20ns tPD-HL = 40ns The good news: you can tCD,logic ≥ tSETUP,reg2 choose tCLK so that this tHOLD = 5ns tPD-LH = 25ns constraint is satisfied! tPD,reg1 + tPD,logic + tSETUP,reg2 ≤ tCLK The bad news: you have to change t + t ≥ t your design if this constraint isn’t CD,reg1 CD,logic HOLD,reg2 met. 6.111 Fall 2016 Lecture 4 9 6.111 Fall 2016 Lecture 4 10 Single-clock Synchronous Circuits Clocks are Not Perfect: Clock Skew CLout We’ll use Registers in a highly constrained way to build digital systems: In Combinational Does that D Q D Q symbol Logic register? Single-clock Synchronous Discipline • No combinational cycles Wire delay clk2 • Single clock signal shared among clk1 all clocked devices (one clock domain) clk1 • Only care about value of combinational circuits just before clk2 rising edge of clock • Clock period greater than every δ>0 combinational delay tskew = tclk2 –tclk1 • Change saved state after noise- inducing logic transitions have stopped! 6.111 Fall 2016 Lecture 4 11 6.111 Fall 2016 Lecture 4 12 Positive and Negative Skew D-Register Timing With Skew In the real world the clock signal arrives T R1 R2 R3 CLK at different registers at different times. In Combinational Combinational TCLK DQ DQ DQ ••• 1 3 DQ logic DQ Logic Logic CLK1 The difference in arrival times (pos or reg1 reg2 CLK tCLK1 tCLK2 tCLK3 neg) is called the clock skew tskew. CLK2 2 4 delay delay tskew = tRn,clk2 –tRn,clk1 th CLK ±skew (a) Positive skew We can update our two timing constraints to reflect the worst-case skew Launching edge arrives before the receiving edge CLKreg1 Setup time: t = t tPD,reg1+tPD,logic Rn,clk Rn+1,clk tRn,clk1+tPD,reg1+tPD,logic +tSETUP,reg2 ≤ tRn+1,clk2 R1 R2 R3 T + t +t + t ≤ t + t In Combinational Combinational CLK PD,reg1 PD,logic SETUP,reg2 CLK skew DQ DQ DQ ••• Logic Logic TCLK tCD,reg1+tCD,logic 1 3 CLK1 tCLK1 tCLK2 tCLK3 Hold time: tRn,clk1+tCD,reg1+tCD,logic ≥ tRn,clk2+tHOLD,reg2 delay delay CLK CLK2 2 4 ≥ tSETUP,reg2 (b) Negative skew tCD,reg1+tCD,logic ≥ tHOLD,reg2+ tskew CLKreg2 Receiving edge arrives before the launching edge Thus clock skew increases the minimum ≥ tHOLD,reg2 cycle time of our design and makes it harder to meet register hold times. Adapted from J. Rabaey, A. Chandrakasan, B. Nikolic, CLKreg2 rising edge might fall “Digital Integrated Circuits: A Design Perspective” Copyright 2003 Prentice Hall/Pearson. anywhere in this region. Which skew is tougher to deal with (pos or neg)? 6.111 Fall 2016 Lecture 4 13 6.111 Fall 2016 Lecture 4 14 Delay Estimation : Simple RC Networks RC Equation VDD Vin 50% Vs = 5 V t V = 5 V Vin Vout s tpHL tpLH C V Switch is closed t<0 L out R 90% Switch opens t>0 50% V DD V DD V = V + V 10% t + s R C tf tr V dVc (b) High-to-low c Vs = iR R+ Vc iR = C R on (a) Low-to-high dt - dV review R RC c V vout Vs = dt c V V out t out vin C V V 1 e RC C t c s L C L V 51 e RC R c on tp = ln (2) = 0.69 RC 6.111 Fall 2016 Lecture 4 15 6.111 Fall 2016 Lecture 4 16 Clocks are Not Perfect: Clock Jitter Sequential Circuit Timing New tCD,R = 1ns State tPD,R = 3ns t = 2ns S,R Current Combinational tH,R = 2ns State Logic Clock tCD,L = ? t = 5ns InputPD,L Output Questions: tpd, tsu, thold • Constraints on tCD for the logic? > 1 ns • Minimum clock period? > 10 ns (tPD,R+tPD,L+ tSETUP,R) Typical crystal oscillator • Setup, Hold times for Inputs? tSETUP,Input = tPD,L +tSETUP,R tclk –2tjitter > tpd + tsu + tlogic 100mhz (10ns) Jitter: 1ps tHOLD,Input = tHOLD,R -tCD,L This is a simple Finite State Machine … more on next time! 6.111 Fall 2016 Lecture 4 17 6.111 Fall 2016 Lecture 4 18 The Sequential always Block Importance of the Sensitivity List Edge-triggered circuits are described using a sequential always • The use of posedge and negedge makes an always block block sequential (edge-triggered) • Unlike a combinational always block, the sensitivity list does Combinational Sequential determine behavior for synthesis! D-Register with synchronous clear D-Register with asynchronous clear module comb(input a, b, sel, module seq(input a, b, sel, clk, module dff_sync_clear( module dff_sync_clear( output reg out); output reg out); input d, clearb, clock, input d, clearb, clock, output reg q output reg q always @(*) begin always @(posedge clk) begin ); ); if (sel) out = b; if (sel) out <= b; always @(posedge clock) always @(negedge clearb or posedge clock) else out = a; else out <= a; begin begin end end if (!clearb) q <= 1'b0; if (!clearb) q <= 1'b0; endmodule endmodule else q <= d; else q <= d; end end endmodule endmodule always always block entered only at block entered immediately when each positive clock edge (active-low) clearb is asserted Note: The following is incorrect syntax: 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 one always block. Be wary of race conditions: always blocks with same trigger execute concurrently… 6.111 Fall 2016 Lecture 4 19 6.111 Fall 2016 Lecture 4 20 Blocking vs. Nonblocking Assignments Blocking vs. Nonblocking Assignments • Verilog supports two types of assignments within always blocks, • Guaranteed question on job interviews with Verilog questions. with subtly different behaviors. • Blocking assignment (=): evaluation and assignment are immediate • Blocking assignment (=): evaluation and assignment are immediate; always @(*) begin subsequent statements affected. x = a | b; // 1. evaluate a|b, assign result to x y = a ^ b ^ c; // 2. evaluate a^b^c, assign result to y z = b & ~c; // 3. evaluate b&(~c), assign result to z • Nonblocking assignment (<=): all assignments deferred to end of end simulation time step after all right-hand sides have been evaluated (even those in other active always blocks) Nonblocking assignment (<=): all assignments deferred to end of simulation time step after all right-hand sides have been evaluated (even those in other active always blocks) Sometimes, as above, both produce the same result.