DDCAarm - Ch3 - New
DDCAarm - Ch3 - New
DDCAarm - Ch3 - New
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <1>
Chapter 3 :: Topics
• Introduction
• Latches and Flip-Flops
• Synchronous Logic Design
• Finite State Machines
• Timing of Sequential Logic
• Parallelism
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <2>
Introduction
• Outputs of sequential logic depend on current
and prior input values – it has memory.
• Some definitions:
– State: all the information about past inputs
necessary to explain its future behavior
– Latches and flip-flops: state elements that store
one bit of state
– Synchronous sequential circuits: combinational
logic followed by a bank of flip-flops
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <3>
Sequential Circuits
• Give sequence to events
• Have memory (short-term)
• Use feedback from output to input to store
information
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <4>
State Elements
• The state of a circuit influences its future
behavior
• State elements store state
– Bistable circuit
– SR Latch
– D Latch
– D Flip-flop
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <5>
Bistable Circuit
• Fundamental building block of other state
elements
• Two outputs: Q, Q
• No inputs
I1 Q
Q Q
I2 I1
I2 Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <6>
Bistable Circuit Analysis
• Consider the two possible cases:
0
– Q = 0: 1
I1 Q
then Q = 0, Q = 1 (consistent) 0 1
I2 Q
– Q = 1: 1
I1 Q
0
then Q = 1, Q = 0 (consistent)
1 0
I2 Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <7>
SR (Set/Reset) Latch
• SR Latch R
N1 Q
N2 Q
S
• Consider the four possible cases:
– S = 1, R = 0
– S = 0, R = 1
– S = 0, R = 0
– S = 1, R = 1
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <8>
SR Latch Analysis
– S = 1, R = 0: R
0
1
N1 Q
then Q = 1 and Q = 0 0
– S = 0, R = 1: R
1
N1
0
Q
1
then Q = 0 and Q = 1
0
Reset the output S
0 N2
1
Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <9>
SR Latch Analysis
– S = 0, R = 0: Qprev = 0 Qprev = 1
then Q = Qprev R
0
N1
0
Q
R
0
N1
1
Q
Memory!
0 N2 Q 0 N2 Q
S S
– S = 1, R = 1:
1
R 0
then Q = 0, Q = 0 N1 Q
0
Invalid State
0
Q ≠ NOT Q S
1 N2
0
Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <10>
SR Latch Symbol
• SR stands for Set/Reset Latch
– Stores one bit of state (Q)
• Control what value is being stored with S, R
inputs
– Set: Make the output 1 SR Latch
Symbol
(S = 1, R = 0, Q = 1)
– Reset: Make the output 0 R Q
(S = 0, R = 1, Q = 0)
S Q
• Avoid invalid state
(when S = R = 1)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <11>
D Latch
• Two inputs: CLK, D
– CLK: controls when the output changes
– D (the data input): controls what the output changes to
• Function
– When CLK = 1,
D Latch
D passes through to Q (transparent) Symbol
– When CLK = 0,
Q holds its previous value (opaque) CLK
• Avoids invalid case when D Q
Q ≠ NOT Q Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <12>
D Latch Internal Circuit
CLK R CLK
D R Q Q
S
D Q
S Q Q
D
Q
CLK D D S R Q Q
0 X X 0 0 Qprev Qprev
1 0 1 0 1 0 1
1 1 0 1 0 1 0
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <13>
D Flip-Flop
• Inputs: CLK, D
D Flip-Flop
• Function Symbols
– Samples D on rising edge of CLK
• When CLK rises from 0 to 1, D
passes through to Q D Q
• Otherwise, Q holds its previous Q
value
– Q changes only on rising edge of CLK
• Called edge-triggered
• Activated on the clock edge
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <14>
D Flip-Flop Internal Circuit
• Two back-to-back latches (L1 and L2) controlled by
complementary clocks
• When CLK = 0 CLK
– L1 is transparent
– L2 is opaque
– D passes through to N1 CLK CLK
N1
• When CLK = 1 D D Q D Q Q
– L2 is transparent L1 Q L2 Q Q
– L1 is opaque
– N1 passes through to Q
• Thus, on the edge of the clock (when CLK rises from 0 1)
– D passes through to Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <15>
D Latch vs. D Flip-Flop
CLK
D Q D Q
Q Q
CLK
Q (latch)
Q (flop)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <16>
Registers: Multi-bit Flip-Flop
CLK
D0 D Q Q0
CLK
D1 D Q Q1
4 4
D3:0 Q3:0
D2 D Q Q2
D3 D Q Q3
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <17>
Enabled Flip-Flops
• Inputs: CLK, D, EN
– The enable input (EN) controls when new data (D) is stored
• Function
– EN = 1: D passes through to Q on the clock edge
– EN = 0: the flip-flop retains its previous state
Internal
Circuit
Symbol
EN CLK
0
D Q Q D Q
D 1
EN
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <18>
Resettable Flip-Flops
• Inputs: CLK, D, Reset
• Function:
– Reset = 1: Q is forced to 0
– Reset = 0: flip-flop behaves as ordinary D flip-flop
Symbols
D Q
r
Reset
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <19>
Resettable Flip-Flops
• Two types:
– Synchronous: resets at the clock edge only
– Asynchronous: resets immediately when Reset = 1
• Asynchronously resettable flip-flop requires
changing the internal circuitry of the flip-flop
• Synchronously resettable flip-flop?
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <20>
Resettable Flip-Flops
• Two types:
– Synchronous: resets at the clock edge
only
– Asynchronous: resets immediately
when Reset = 1
• Asynchronously resettable flip-
flop requires changing the
internal circuitry of the flip-flop
• Synchronously resettable flip-flop
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <21>
Settable Flip-Flops
• Inputs: CLK, D, Set
• Function:
– Set = 1: Q is set to 1
– Set = 0: the flip-flop behaves as ordinary D flip-flop
Symbols
D Q
s
Set
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <22>
Sequential Logic
• Sequential circuits: all circuits that aren’t
combinational
• A problematic circuit:
X
X Y Z
Y
Z
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <23>
SystemVerilog Description
module flop(input logic clk, d,
output logic q);
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <27>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <28>
Chapter 4
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <29>
Chapter 4 :: Topics
• Introduction
• Combinational Logic
• Structural Modeling
• Sequential Logic
• More Combinational Logic
• Finite State Machines
• Parameterized Modules
• Testbenches
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <30>
Introduction
• Hardware description language (HDL):
– specifies logic function only
– Computer-aided design (CAD) tool produces or synthesizes
the optimized gates
• Most commercial designs built using HDLs
• Two leading HDLs:
– SystemVerilog
• developed in 1984 by Gateway Design Automation
• IEEE standard (1364) in 1995
• Extended in 2005 (IEEE STD 1800-2009)
– VHDL 2008
• Developed in 1981 by the Department of Defense
• IEEE standard (1076) in 1987
• Updated in 2008 (IEEE STD 1076-2008)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <31>
HDL to Gates
• Simulation
– Inputs applied to circuit
– Outputs checked for correctness
– Millions of dollars saved by debugging in simulation instead of
hardware
• Synthesis
– Transforms HDL code into a netlist describing the hardware (i.e., a list
of gates and the wires connecting them)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <32>
HDL to Gates
• Simulation
– Inputs applied to circuit
– Outputs checked for correctness
– Millions of dollars saved by debugging in simulation
instead of hardware
• Synthesis
– Transforms HDL code into a netlist describing the hardware
(i.e., a list of gates and the wires connecting them)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <33>
SystemVerilog Modules
a
Verilog
SystemVerilog
b Module
y
Module
c
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <34>
Behavioral SystemVerilog
SystemVerilog:
module example(input logic a, b, c,
output logic y);
assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <35>
Behavioral SystemVerilog
SystemVerilog:
module example(input logic a, b, c,
output logic y);
assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c;
endmodule
Continuous
assignment • module/endmodule: required to begin/end module
Đầu ra sẽ
• example: name of the module
thay đổi • Operators:
ngay khi
đầu vào ~: NOT
thay đổi &: AND
|: OR
Dùng cho Combinational logic
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <36>
HDL Simulation
SystemVerilog:
module example(input logic a, b, c,
output logic y);
assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <37>
HDL Synthesis
SystemVerilog:
module example(input logic a, b, c,
output logic y);
assign y = ~a & ~b & ~c | a & ~b & ~c | a & ~b & c;
endmodule
Synthesis:
b
c y
un5_y y
un8_y
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <38>
SystemVerilog Syntax
• Case sensitive
– Example: reset and Reset are not the same signal.
• No names that start with numbers
– Example: 2mux is an invalid name
• Whitespace ignored
• Comments:
– // single line comment
– /* multiline
comment */
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <39>
Structural Modeling - Hierarchy
module and3(input logic a, b, c,
output logic y);
assign y = a & b & c;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <40>
Bitwise Operators
module gates(input logic [3:0] a, b,
output logic [3:0] y1, y2, y3, y4, y5);
/* Five different two-input logic
gates acting on 4 bit busses */
assign y1 = a & b; // AND Synthesis:
assign y2 = a | b; // OR
assign y3 = a ^ b; // XOR
assign y4 = ~(a & b); // NAND
assign y5 = ~(a | b); // NOR
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <41>
Reduction Operators
SystemVerilog:
module and8(input logic [7:0] a,
output logic y);
assign y = &a;
// &a is much easier to write than
// assign y = a[7] & a[6] & a[5] & a[4] &
// a[3] & a[2] & a[1] & a[0];
endmodule
Synthesis:
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <42>
Conditional Assignment
SystemVerilog:
module mux2(input logic [3:0] d0, d1,
input logic s,
output logic [3:0] y);
assign y = s ? d1 : d0;
endmodule
Synthesis:
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <43>
Internal Variables
SystemVerilog:
module fulladder(input logic a, b, cin,
output logic s, cout);
logic p, g; // internal nodes
assign p = a ^ b;
assign g = a & b;
Synthesis:
assign s = p ^ cin;
s
assign cout = g | (p & cin); s
g
endmodule
cin
cout
a
b
un1_cout cout
p
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <44>
Precedence
Highest ~ NOT
*, /, % mult, div, mod
+, - add,sub
<<, >> shift
<<<, >>> arithmetic shift
<, <=, >, >= comparison
==, != equal, not equal
&, ~& AND, NAND
^, ~^ XOR, XNOR
|, ~| OR, NOR
Lowest ?: ternary operator
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <45>
Numbers
Format: N'Bvalue
N = number of bits, B = base
N'B is optional but recommended (default is decimal)
Number # Bits Base Decimal Stored
Equivalent
3'b101 3 binary 5 101
'b11 unsized binary 3 00…0011
8'b11 8 binary 3 00000011
8'b1010_1011 8 binary 171 10101011
3'd6 3 decimal 6 110
6'o42 6 octal 34 100010
8'hAB 8 hexadecimal 171 10101011
42 Unsized decimal 42 00…0101010
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <46>
Bit Manipulations: Example 1
assign y = {a[2:1], {3{b[0]}}, a[0], 6'b100_010};
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <47>
Bit Manipulations: Example 2
SystemVerilog:
module mux2_8(input logic [7:0] d0, d1,
input logic s,
output logic [7:0] y);
lsbmux
mux2
s
[7:4] [7:4]
d0[3:0] y[3:0]
[7:4]
d1[3:0]
msbmux
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <48>
Z: Floating Output
SystemVerilog:
module tristate(input logic [3:0] a,
input logic en,
output tri [3:0] y);
assign y = en ? a : 4'bz;
endmodule
Synthesis:
en
[3:0] [3:0] [3:0] [3:0]
a[3:0] y[3:0]
y_1[3:0]
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <49>
Delays
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} = ~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb;
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <50>
Delays
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} =
~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb;
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <51>
Delays
1
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} =
~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb;
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <52>
Delays
2
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} =
~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb;
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <53>
Delays
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} =
~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb; 2
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <54>
Delays
module example(input logic a, b, c,
output logic y);
logic ab, bb, cb, n1, n2, n3;
assign #1 {ab, bb, cb} =
~{a, b, c};
assign #2 n1 = ab & bb & cb;
assign #2 n2 = a & bb & cb; 4
assign #2 n3 = a & bb & c;
assign #4 y = n1 | n2 | n3;
endmodule
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <55>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <56>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <57>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <58>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <59>
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <60>
Thiết kế mạch phân kênh 2-4
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <61>
Dùng quá nhiều điều kiện: Độ trễ quá lớn
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <62>
Thiết kế mạch dử dụng toán tử Assign và bitwise
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <63>
Thiết kế mạch dử dụng toán tử Assign và bitwise
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <64>
Thiết kế mạch có cổng vừa input vừa ouput
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <65>
Cấu trúc
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <66>
Sequential Logic
• SystemVerilog uses idioms to describe
latches, flip-flops and FSMs
• Other coding styles may simulate correctly
but produce incorrect hardware
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <67>
Finite State Machine (FSM)
• Consists of:
CLK
– State register
• Stores current state S’
Next
S
Current
• Loads next state at clock edge State State
Output
Logic
CL Outputs
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <68>
Finite State Machines (FSMs)
• Next state determined by current state and inputs
• Two types of finite state machines differ in output logic:
– Moore FSM: outputs depend only on current state
– Mealy FSM: outputs depend on current state and inputs
Moore FSM
CLK
M next
next k k output N
inputs state
state state
outputs
logic
logic
Mealy FSM
CLK
M next
next k k state output N
inputs state
state
outputs
logic
logic
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <69>
FSM Example
• Traffic light controller
– Traffic sensors: TA, TB (TRUE when there’s traffic)
– Lights: LA, LB
Bravado
Dining
Hall
LB
LA TB
LA
Academic TA TA Ave.
Labs TB LB Dorms
Blvd.
Fields
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <70>
FSM Black Box
• Inputs: CLK, Reset, TA, TB
• Outputs: LA, LB
CLK
Bravado
Dining
Hall
LB
TA Traffic LA
LA TB
LA
Light
Academic TA TA Ave.
TB Controller LB
Labs TB LB Dorms
Blvd.
Fields
Reset
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <71>
FSM State Transition Diagram
• Moore FSM: outputs labeled in each state
• States: Circles Reset
• Transitions: Arcs S0
L : green A
LB: red
Bravado
Dining
Hall
LB
LA TB
LA
Academic TA TA Ave.
Labs TB LB Dorms
Blvd.
Fields
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <72>
FSM State Transition Diagram
• Moore FSM: outputs labeled in each state
• States: Circles Reset
T A
S0 T S1
• Transitions: Arcs
A
L : green L : yellow A A
LB: red LB: red
Bravado
Dining
Hall
LB
LA TB
LA
Academic TA TA Ave.
Labs TB LB Dorms S3 S2
LA: red LA: red
Blvd.
Fields
LB: yellow LB: green
TB
TB
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <73>
FSM State Transition Table
Current Next
State Inputs State
S TA TB S' Reset
TA
S0 TA S1
S0 0 X S1 LA: green
LB: red
LA: yellow
LB: red
S0 1 X S0
S1 X X S2
S2 X 0 S3 S3
LA: red
S2
LA: red
LB: yellow LB: green
TB
S2 X 1 S2 TB
S3 X X S0
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <74>
FSM Encoded State Transition Table
Current State Inputs Next State
State Encoding
S1 S0 TA TB S'1 S'0
S0 00
0 0 0 X 0 1
0 0 1 X 0 0 S1 01
0 1 X X 1 0 S2 10
1 0 X 0 1 1
S3 11
1 0 X 1 1 0 Reset
TA
TA
S0 S1
1 1 X X 0 0 LA: green
LB: red
LA: yellow
LB: red
S'1 = S1 xor S0 S3 S2
LA: red LA: red
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <75>
FSM Output Table
Current State Outputs
S1 S0 LA1 LA0 LB1 LB0 Output Encoding
0 0 0 0 1 0 green 00
0 1 0 1 1 0 yellow 01
1 0 1 0 0 0
red 10
1 1 1 0 0 1 TA
Reset
TA
LA1 = S1
S0 S1
LA: green LA: yellow
LB: red LB: red
LA0 = S1S0
LB1 = S1 S3
LA: red
S2
LA: red
LB: yellow LB: green
TB
LB0 = S1S0 TB
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <76>
FSM Schematic: State Register
CLK
S'1 S1
S'0 S0
r
Reset
state register
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <77>
FSM Schematic: Next State Logic
CLK
S'1 S1
TA S'0 S0
r
TB Reset
S1 S0
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <78>
FSM Schematic: Output Logic
CLK LA1
S'1 S1
LA0
TA S'0 S0
LB1
r
TB Reset
S1 S0 LB0
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <79>
SystemVerilog Description
module trafficFSM(input logic clk, reset,
input logic ta, tb,
output logic [1:0] la, lb);
logic [1:0] state, nextstate, sb;
logic tab, tbb, p1, p2;
// state register
flopr #(2) statereg(clk, reset, nextstate, state);
// output logic
buf b1(la[1], s[1]);
and a3(la[0], s[0], sb[1]);
inv n4(lb[1], s[1]);
and a4(lb[0], s[0], s[1]);
endmodule
CLK
Reset
TA
TB
0 5 10 15 20 25 30 35 40 45 t (sec)
TA
Reset
S0 TA S1
LA: green LA: yellow
LB: red LB: red
S3 S2
LA: red LA: red
LB: yellow LB: green
TB
TB
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <81>
FSM State Encoding
• Binary encoding:
– i.e., for four states, 00, 01, 10, 11
• One-hot encoding
– One state bit per state
– Only one state bit HIGH at once
– i.e., for 4 states, 0001, 0010, 0100, 1000
– Requires more flip-flops
– Often next state and output logic is simpler
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <82>
Moore vs. Mealy FSM
• Alyssa P. Hacker has a snail that crawls down a paper tape
with 1’s and 0’s on it. The snail smiles whenever the last two
digits it has crawled over are 01. Design Moore and Mealy
FSMs of the snail’s brain.
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <83>
Phân tích theo mô hình Moore
Note:
- Output phụ thuộc state, được thể hiện trong vòng state
- Kích thích Input làm chuyển state
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <84>
Phân tích theo mô hình Mealy
Note:
- Output phụ thuộc state và kích thích Input, được thể hiện trên thay đổi
- Kích thích Input làm chuyển state
A=0/Y=0 A=0/Y=0
reset
𝑆0 𝑆1
A=1/Y=0
A=1/Y=1
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <85>
State Transition Diagrams
Moore FSM
Reset
0 1
S0 S1 S2
0 0 1
1 0 0
1
Mealy FSM
Reset
0/0
S0 S1
1/0 0/0
1/1
1 0 0 0 1
S0 S1 S2
0 0 1
1 0 0
1
1 0 1 0 0
S1’ = S0A
S0’ = A
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <87>
Moore FSM Output Table
Moore FSM
Current State Output Reset
0 1
S1 S0 Y
S0 S1 S2
0 0 0 1
0
0
0
0
1
1
0 1 0
1 0 1
Y = S1
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <88>
Mealy FSM State Transition & Output Table
Current Next
State Input State Output
S0 A S'0 Y
State Encoding
0 0 1 0
0 1 0 0 S0 0
1 0 1 0
S1 1
1 1 0 1
Mealy FSM
Reset
0/0
S0 = A
’
S0 S1
Y = S0 A 1/0 0/0
1/1
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <89>
Moore Mealy
A CLK
S'1 S1
Y A
CLK
S'0 S0 Y
S'0 S0
r r
Reset
Reset
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <90>
Moore & Mealy Timing Diagram
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Cycle 10 Cycle 11
CLK
Reset
A 0 1 0 1 1 0 1 1 1
Moore Machine
S ?? S0 S1 S2 S1 S2 S0 S1 S2 S0
Y
Mealy Machine
S ?? S0 S1 S0 S1 S0 S1 S0
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <91>
Factoring State Machines
• Break complex FSMs into smaller interacting
FSMs
• Example: Modify traffic light controller to have
Parade Mode.
– Two more inputs: P, R
– When P = 1, enter Parade Mode & Bravado Blvd
light stays green
– When R = 1, leave Parade Mode
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <92>
Parade FSM
P
Unfactored FSM R
TA
Controller LA
FSM LB
TB
P
Factored FSM R
Mode
FSM
TA Lights LA
TB FSM LB
Controller
FSM
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <93>
Unfactored FSM
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <94>
Factored FSM
TA
Reset
S0 TA S1
LA: green LA: yellow
LB: red LB: red
P
Reset
S3 S2 P
S0 S1
LA: red LA: red
M: 0 M: 1
LB: yellow LB: green R
MTB
M + TB R
Lights FSM Mode FSM
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <95>
FSM Design Procedure
1. Identify inputs and outputs
2. Sketch state transition diagram
3. Write state transition table
4. Select state encodings
5. For Moore machine:
a. Rewrite state transition table with state encodings
b. Write output table
5. For a Mealy machine:
Rewrite combined state transition and output table with
state encodings
6. Write Boolean equations for next state and output logic
7. Sketch the circuit schematic
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <96>
Timing
• Flip-flop samples D at clock edge
• D must be stable when sampled
• Similar to a photograph, D must be stable
around clock edge
• If not, metastability can occur
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <97>
Input Timing Constraints
• Setup time: tsetup = time before clock edge data must be
stable (i.e. not changing)
• Hold time: thold = time after clock edge data must be stable
• Aperture time: ta = time around clock edge data must be
stable (ta = tsetup + thold)
CLK
tsetup thold
ta
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <98>
Dynamic Discipline
• Synchronous sequential circuit inputs must
be stable during aperture (setup and hold)
time around clock edge
• Specifically, inputs must be stable
– at least tsetup before the clock edge
– at least until thold after the clock edge
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <99>
Output Timing Parameters
• Contamination delay: tccq = time after clock edge that Q
might be unstable (i.e., start changing)
• Propagation delay: tpcq = time after clock edge that the
output Q is guaranteed to be stable (i.e., to stop changing)
CLK
tccq
tpcq
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <100>
Dynamic Discipline
• The delay between registers has a minimum
and maximum delay, dependent on the
delays of the circuit elements
CLK CLK
Q1 CL D2
R1 R2
(a)
Tc
CLK
Q1
D2
(b)
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <101>
Setup Time Constraint
• Depends on the maximum delay from register R1
through combinational logic to R2
• The input to register R2 must be stable at least tsetup
before clock edge
CLK CLK
Q1 CL D2
D2
tpcq tpd tsetup (tpcq + tsetup): sequencing overhead
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <102>
Hold Time Constraint
• Depends on the minimum delay from register R1
through the combinational logic to R2
• The input to register R2 must be stable for at least
thold after the clock edge
CLK CLK
Q1 CL D2
R1 R2
thold < tccq + tcd
CLK
tcd > thold - tccq
Q1
D2
tccq tcd
thold
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <103>
Timing Analysis
CLK CLK Timing Characteristics
A tccq = 30 ps
tpcq = 50 ps
B tsetup = 60 ps
thold = 70 ps
X' X
per gate
C
tpd = 35 ps
D
Y' Y tcd = 25 ps
tpd = 3 x 35 ps = 105 ps
tcd = 25 ps
Setup time constraint: Hold time constraint:
Tc ≥ (50 + 105 + 60) ps = 215 ps tccq + tcd > thold ?
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <104>
Timing Analysis
Add buffers to the short paths: Timing Characteristics
CLK CLK tccq = 30 ps
A
tpcq = 50 ps
tsetup = 60 ps
B
thold = 70 ps
X' X
per gate
C
tpd = 35 ps
D
Y' Y tcd = 25 ps
tpd = 3 x 35 ps = 105 ps
tcd = 2 x 25 ps = 50 ps
Setup time constraint: Hold time constraint:
Tc ≥ (50 + 105 + 60) ps = 215 ps tccq + tcd > thold ?
fc = 1/Tc = 4.65 GHz (30 + 50) ps > 70 ps ? Yes!
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <105>
Clock Skew
• The clock doesn’t arrive at all registers at same time
• Skew: difference between two clock edges
• Perform worst case analysis to guarantee dynamic
discipline is not violated for any register – many
registers in a system!
delay CLK
CLK1 CLK2
Q1 C D2
L
R1 R2
t skew
CLK1
CLK2
CLK
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <106>
Setup Time Constraint with Skew
• In the worst case, CLK2 is earlier than CLK1
CLK1 CLK2
Q1 C D2
L
R1 R2
Tc
CLK1
Tc ≥ tpcq + tpd + tsetup + tskew
CLK2
tpd ≤ Tc – (tpcq + tsetup + tskew)
Q1
D2
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <107>
Hold Time Constraint with Skew
• In the worst case, CLK2 is later than CLK1
CLK1 CLK2
Q1 C D2
L
R1 R2
CLK1
tskew thold
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <108>
Violating the Dynamic Discipline
Asynchronous (for example, user) tsetup thold
CLK
button
D
Case I
D Q
Q
D
Case II
Q
Case III
???
Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <109>
Metastability
• Bistable devices: two stable states, and a
metastable state between them
• Flip-flop: two stable states (1 and 0) and one
metastable state
• If flip-flop lands in metastable state, could stay
there for an undetermined amount of time
metastable
stable stable
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <110>
Flip-Flop Internals
• Flip-flop has feedback: if Q is somewhere between
1 and 0, cross-coupled gates drive output to either
rail (1 or 0) R
N1 Q
N2 Q
S
• Metastable signal: if it hasn’t resolved to 1 or 0
• If flip-flop input changes at random time, probability
that output Q is metastable after waiting some time, t:
P(tres > t) = (T0/Tc ) e-t/τ
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <111>
Metastability
• Intuitively:
T0/Tc: probability input changes at a bad time (during aperture)
P(tres > t) = (T0/Tc ) e-t/τ
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <112>
Synchronizers
• Asynchronous inputs are inevitable (user interfaces,
systems with different clocks interacting, etc.)
• Synchronizer goal: make the probability of failure (the
output Q still being metastable) low
• Synchronizer cannot make the probability of failure 0
CLK
SYNC
D Q
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <113>
Synchronizer Internals
• Synchronizer: built with two back-to-back flip-flops
• Suppose D is transitioning when sampled by F1
• Internal signal D2 has (Tc - tsetup) time to resolve to 1
or 0 CLK
D2
CLK
D Q
F1 F2
Tc
CLK
D2 metastable
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <114>
Synchronizer Probability of Failure
For each sample, probability of failure is:
P(failure) = (T0/Tc ) e-(T c - tsetup)/τ
CLK CLK
D2
D Q
F1 F2
Tc
CLK
D2 metastable
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <115>
Synchronizer Mean Time Between Failures
• If asynchronous input changes once per second,
probability of failure per second is P(failure).
• If input changes N times per second, probability of failure
per second is:
P(failure)/second = (NT0/Tc) e-(T - t c setup )/τ
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <116>
Example Synchronizer
CLK CLK
D2
D Q
F1 F2
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <117>
Parallelism
• Two types of parallelism:
– Spatial parallelism
• duplicate hardware performs multiple tasks at once
– Temporal parallelism
• task is broken into multiple stages
• also called pipelining
• for example, an assembly line
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <118>
Parallelism Definitions
• Token: Group of inputs processed to produce
group of outputs
• Latency: Time for one token to pass from
start to end
• Throughput: Number of tokens produced
per unit time
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <119>
Parallelism Example
• Ben Bitdiddle bakes cookies to celebrate traffic light
controller installation
• 5 minutes to roll cookies
• 15 minutes to bake
• What is the latency and throughput without parallelism?
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <120>
Parallelism Example
• What is the latency and throughput if Ben
uses parallelism?
– Spatial parallelism: Ben asks Allysa P. Hacker to
help, using her own oven
– Temporal parallelism:
• two stages: rolling and baking
• He uses two trays
• While first batch is baking, he rolls the
second batch, etc.
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <121>
Spatial Parallelism
Latency:
time to
first tray
0 5 10 15 20 25 30 35 40 45 50
Time
Tray 1 Ben 1 Ben 1
Roll
Parallelism
Bake
Tray 3 Ben 2 Ben 2
Legend
Tray 4 Alyssa 2 Alyssa 2
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <122>
Temporal Parallelism
Latency:
time to
first tray
0 5 10 15 20 25 30 35 40 45 50
Time
Tray 1 Ben 1 Ben 1
Parallelism
Temporal
Digital Design and Computer Architecture: ARM® Edition © 2015 Chapter 3 <123>