Something We Can't Build (Yet)
Something We Can't Build (Yet)
button
light
What makes this circuit so different from those weve discussed before? 1. State i.e. the circuit has memory 2. The output was changed by a input event (pushing a button) rather than an input value
6.111 Fall 2007 Lecture 5, Slide 1
Digital State
New State
Memory Device
LOAD Input
Current State
Combinational Logic
Output
Plan: Build a Sequential Circuit with stored digital STATE Memory stores CURRENT state, produced at output
Combinational Logic computes NEXT state (from input, current state) OUTPUT bit (from input, current state) State changes on LOAD control input
6.111 Fall 2007 Lecture 5, Slide 2
VOUT
D B S G
Lecture 5, Slide 4
G=0: Q holds
V2
Q Y
D G Q
V1
V1
V2
Lecture 5, Slide 5
D-Latch timing
D Stable
Q A D G
0 1
Q Y
D G Q
V2
TSETUP THOLD
Forbidden State
Reset R S Q Q Hold Set Reset Set
??
Flip-flop refers to a bi-stable element
Lecture 5, Slide 7
D G
Input
Q
Current State
Combinational Logic
Output
Plan: Build a Sequential Circuit with one bit of STATE Single latch holds CURRENT state
Combinational Logic computes NEXT state (from input, current state) OUTPUT bit (from input, current state) State changes when G = 1 (briey!)
6.111 Fall 2007 Lecture 5, Slide 8
Combinational Cycles
New State
Q
Current State
1
Input
Combinational Logic
Output
Lecture 5, Slide 9
Edge-triggered D-Register
The gate of this latch is open when the clock is low
D
D0 0 1 1
S
D G
D G
D CLK
master
slave
The gate of this latch is open when the clock is high
CLK
Observations: only one latch transparent at any time: Transitions mark instants, not intervals master closed when slave is open slave closed when master is open no combinational path through ip op
(the feedback path in one of the master or slave latches is always active)
Q only changes shortly after 0 1 transition of CLK, so ip op appears to be triggered by rising edge of CLK
6.111 Fall 2007 Lecture 5, Slide 10
D-Register Waveforms
D D G CLK Q D G Q Q D CLK D Q Q
master
slave
D CLK
Q
master closed slave open
6.111 Fall 2007
D-Register Timing - I
Values determined from slave latch
<tPD
D CLK
D Q
>tCD
Q CLK D
tPD: maximum propagation delay, CLK Q tCD: minimum contamination delay, CLK Q tSETUP: setup time tHOLD: hold time
6.111 Fall 2007
>tSETUP >tHOLD
Values determined from master latch
guarantee that D has propagated through feedback path before master closes guarantee master is closed and data is stable before allowing D to change
Lecture 5, Slide 12
D-Register Timing - II
Questions for register-based designs:
D Q
reg1
CLK
reg2
how much time for useful work (i.e. for combinational logic delay)? does it help to guarantee a minimum tCD? How about designing registers so that tCD,reg > tHOLD,reg?
t1 CLK
t2
what happens if CLK signal doesnt arrive at the two registers at exactly the same t1 = tCD,reg1 + tCD,1 > tHOLD,reg2 time (a phenomenon known as t2 = tPD,reg1 + tPD,1 < tCLK - tSETUP,reg2 clock skew)?
6.111 Fall 2007 Lecture 5, Slide 13
Combinational Logic
tCD,L = ? tPD,L = 5ns
Output
Questions:
Constraints on TCD for the logic? Minimum clock period? Setup, Hold times for Inputs?
> 1 ns > 10 ns (TPD,R+TPD,L+ TS,R) TS = TPD,L +TS,R TH = TH,R -TCD,L
Sequential
module sequential(a, b, sel, clk, out); input a, b; input sel, clk; output out; reg out; always @ (posedge clk) begin if (sel) out <= a; else out <= b; end endmodule
a b
1 out 0 sel
a b
1 D Q 0 sel clk
Lecture 5, Slide 15
out
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 execute in parallel
6.111 Fall 2007 Lecture 5, Slide 16
Nonblocking assignment: all assignments deferred until all righthand sides have been evaluated (end of simulation timestep)
always begin x <= y <= z <= end @ (a or b or c) a | b; a ^ b ^ c; b & ~c; 1. Evaluate a | b but defer assignment of x 2. Evaluate a^b^c but defer assignment of y 3. Evaluate b&(~c) but defer assignment of z 4. Assign x, y, and z with their new values
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) begin q1 <= in; q2 <= q1; out <= q2; end endmodule module blocking(in, clk, out); input in, clk; output out; reg q1, q2, out; always @ (posedge clk) begin q1 = in; q2 = q1; out = q2; end endmodule
Lecture 5, Slide 18
q1 in clk D Q D Q
q2 D Q out clk in
out
Blocking assignments do not reflect the intrinsic behavior of multi-stage sequential logic
Lecture 5, Slide 19
module blocking(a,b,c,x,y); input a,b,c; output x,y; reg x,y; always @ (a or b or c) begin x = a & b; y = x | c; end endmodule
x = a & b; y = x | c;
Nonblocking Behavior
(Given) Initial Condition a changes; always block triggered
Deferred
module nonblocking(a,b,c,x,y); input a,b,c; output x,y; reg x,y; always @ (a or b or c) begin x <= a & b; y <= x | c; end endmodule
Nonblocking and blocking assignments will synthesize correctly. 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), its not elegant
Lecture 5, Slide 20
D Q Q
LIGHT
Lecture 5, Slide 21
A Simple Counter
Isn t this a lot like Exercise 1 in Lab 2?
+1
0 1 0 enb
1 4 0 clr clk
count
# 4-bit counter with enable and synchronous clear module counter(clk,enb,clr,count); input clk,enb,clr; output [3:0] count; reg [3:0] count; always @ (posedge clk) begin count <= clr ? 4b0 : (enb ? count+1 : count); end endmodule
6.111 Fall 2007 Lecture 5, Slide 22