Sequential Logic at MIT
Sequential Logic at MIT
button
Sequential Logic
Digital State
Combinational
Logic
LOAD
Input
Output
CLK
New
State
Current
State
Lecture 4
Memory
Device
light
Lecture 4
Lecture 4
D-Register Timing - I
D-Register Timing - II
D Q
reg1
!tPD
"tCD
tCLK
tPD,reg1
CLK
CLK
tPD,logic
D
"tSETUP
tCD,reg1
"tHOLD
tCD,logic
Does that
symbol
register?
Lecture 4
D Q
reg1
CLK
CLKreg1
D Q
reg2
logic
skew
tPD,reg1+ tPD,logic
tCD,reg1+tCD,logic
" tSETUP,reg2
CLKreg2
Lecture 4
No combinational cycles
" tSETUP,reg2
D Q
reg2
CLK
logic
" tHOLD,reg2
Lecture 4
New
State
Current
State
Clock
Combinational
Logic
tCD,L = ?
tPD,L = 5ns
Input
Sequential
Combinational
module comb(input a, b, sel,
output reg out);
Output
endmodule
endmodule
Questions:
Constraints on tCD for the logic?
> 1 ns
Lecture 4
module dff_async_clear(
input d, clearb, clock,
output reg q
);
always @(negedge clearb or posedge clock)
begin
if (!clearb) q <= 1'b0;
else q <= d;
end
endmodule
! 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 2009
Lecture 4
10
module dff_sync_clear(
input d, clearb, clock,
output reg q
);
always @(posedge clock)
begin
if (!clearb) q <= 1'b0;
else q <= d;
end
endmodule
Lecture 4
Lecture 4
12
module blocking(
input in, clk,
output reg out
);
reg q1, q2;
always @(posedge clk) begin
q1 = in;
q2 = q1;
// uses new q1
out = q2; // uses new q2
end
endmodule
6.111 Fall 2009
Blocking assignments do not reflect the intrinsic behavior of multistage sequential logic
Guideline: use nonblocking assignments for sequential always blocks
endmodule
Lecture 4
13
Verilog Events
Lecture 4
14
IEEE 1364-2001 Verilog Standard: Section 5.3 The stratified event queue
The Verilog event queue is logically segmented into five different regions. Events
are added to any of the five regions but are only removed from the active region.
1.Events that occur at the current simulation time and can be processed in any order.
These are the active events.
2.Events that occur at the current simulation time, but that shall be processed after all
the active events are processed. These are the inactive events.
3.Events that have been evaluated during some previous simulation time, but that
shall be assigned at this simulation time after all the active and inactive events are
processed. These are the nonblocking assign update events.
4.Events that shall be processed after all the active, inactive, and nonblocking assign
update events are processed. These are the monitor events.
5.Events that occur at some future simulation time. These are the future events.
Future events are divided into future inactive events, and future nonblocking
assignment update events.
Lecture 4
15
Lecture 4
16
Coding Guidelines
Lecture 1
C
initial begin
clk = 0; a = 0; b = 1;
D
#10 clk = 1;
#10 $display("a=%d b=%d\n",a,b);
$finish;
E
end
endmodule
Rule: always change state using <= (e.g., inside always @(posedge clk))
17
Lecture 4
18
button
light
For most of our lab designs well use a 27MHz system clock (37ns
clock period).
module main;
reg a,b,clk;
Lecture 4
19
Lecture 4
20
The circuit on the last slide toggles the light on every rising clock
edge for which button is 1. But clocks are fast (27MHz!) and our
fingers are slow, so how do we press the button for just one clock
edge? Answer: we cant, but we can can add some state that
remembers what button was last clock cycle and then detect the
clock cycles when button changes from 0 to 1.
* Actually, our FPGAs will reset all registers to 0 when the device is
programmed. But its nice to be able to press a reset button to return to a
known state rather than starting from scratch by reprogramming the
device.
6.111 Fall 2009
Lecture 4
21
Lecture 4
Cant guarantee
setup and hold
times will be met!
Clock
Clocked
Synchronous
System
II
22
III
D Q
Sequential System
Q0
Clock
Async
Input
Clock
Q1
Clock
Clock
Transition is missed
on first clock cycle,
but caught on next
clock cycle.
6.111 Fall 2009
Transition is caught
on first clock cycle.
Output is metastable
for an indeterminate
amount of time.
23
Lecture 4
24
Handling Metastability
Very unlikely to
be metastable for
>1 clock cycle
D Q
D Q D Q
Extremely unlikely
to be metastable for
>2 clock cycle
Lecture 4
endmodule
25
Lecture 4
26
0
+1
4
count
enb
Lecture 4
Complicated
Sequential Logic
System
Clock
clr
clk
27
Lecture 4
28