lecture9 fsm examples
TRANSCRIPT
![Page 1: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/1.jpg)
George Mason University ECE 448 – FPGA and ASIC Design with VHDL
FSM Examples:Serial Adder, The Arbiter Circuit
ECE 448Lecture 9
![Page 2: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/2.jpg)
2 ECE 448 – FPGA and ASIC Design with VHDL
Required reading
• S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design
Chapter 8, Synchronous Sequential Circuits
Sections 8.5, 8.8
![Page 3: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/3.jpg)
3 ECE 448 – FPGA and ASIC Design with VHDL
Optional Reading
• Sundar Rajan,
Essential VHDL: RTL Synthesis Done Right
Chapter 6, Finite State Machines
![Page 4: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/4.jpg)
4 ECE 448 – FPGA and ASIC Design with VHDL
Mixing Design Styles
within a Single Architecture
![Page 5: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/5.jpg)
5 ECE 448 – FPGA and ASIC Design with VHDL
architecture ARCHITECTURE_NAME of ENTITY_NAME is
• Here you can declare signals, constants, functions, procedures…
• Component declarations
beginConcurrent statements:
• Concurrent simple signal assignment • Conditional signal assignment • Selected signal assignment• Generate statement
• Component instantiation statement
• Process statement• inside process you can use only sequential
statements
end ARCHITECTURE_NAME;
Mixed Style Modeling
Concurrent Statements
![Page 6: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/6.jpg)
6 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder
![Page 7: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/7.jpg)
7 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – block diagram
Sum A B + =
Shift register
Shift register
Adder
FSM Shift register
B
A
a
b
s
Clock
![Page 8: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/8.jpg)
8 ECE 448 – FPGA and ASIC Design with VHDL
Serial adder FSM – Mealy state diagram
G
00 1
11 1 10 0 01 0
H 10 1 01 1 00 0
carry-in 0 =
carry-in 1 = G:
H:
Reset
11 0 ab s
![Page 9: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/9.jpg)
9 ECE 448 – FPGA and ASIC Design with VHDL
Left-to-right Shift Register (1)
LIBRARY ieee ;USE ieee.std_logic_1164.all ;
-- left-to-right shift register with parallel load and enableENTITY shiftrne IS
GENERIC ( N : INTEGER := 4 ) ;PORT ( R : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;
L, E, w : IN STD_LOGIC ; Clock : IN STD_LOGIC ; Q : BUFFER STD_LOGIC_VECTOR(N-1 DOWNTO 0) ) ;
END shiftrne ;
![Page 10: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/10.jpg)
10 ECE 448 – FPGA and ASIC Design with VHDL
Left-to-right Shift Register (2)ARCHITECTURE Behavior OF shiftrne IS
BEGIN
PROCESS
BEGIN
WAIT UNTIL Clock'EVENT AND Clock = '1' ;
IF E = '1' THEN
IF L = '1' THEN
Q <= R ;
ELSE
Genbits: FOR i IN 0 TO N-2 LOOP
Q(i) <= Q(i+1) ;
END LOOP ;
Q(N-1) <= w ;
END IF ;
END IF ;
END PROCESS ;
END Behavior ;
![Page 11: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/11.jpg)
11 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Entity declaration
1 LIBRARY ieee ;2 USE ieee.std_logic_1164.all ;
3 ENTITY serial IS4 GENERIC ( length : INTEGER := 8 ) ;5 PORT ( Clock : IN STD_LOGIC ;6 Reset : IN STD_LOGIC ;7 A, B : IN STD_LOGIC_VECTOR(length-1 DOWNTO 0) ;8 Sum : BUFFER STD_LOGIC_VECTOR(length-1 DOWNTO
0));9 END serial ;
![Page 12: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/12.jpg)
12 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Architecture (2)10 ARCHITECTURE Behavior OF serial IS
11 COMPONENT shiftrne12 GENERIC ( N : INTEGER := 4 ) ;13 PORT ( R : IN STD_LOGIC_VECTOR(N-1 DOWNTO 0) ;14 L, E, w : IN STD_LOGIC ;15 Clock : IN STD_LOGIC ;16 Q : BUFFER STD_LOGIC_VECTOR(N-1 DOWNTO 0)
) ;17 END COMPONENT ;
18 SIGNAL QA, QB, Null_in : STD_LOGIC_VECTOR(length-1 DOWNTO 0) ;
19 SIGNAL s, Low, High, Run : STD_LOGIC ;
20 SIGNAL Count : INTEGER RANGE 0 TO length ;
21 TYPE State_type IS (G, H) ;22 SIGNAL y : State_type ;
![Page 13: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/13.jpg)
13 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Architecture (3)
23 BEGIN
24 Low <= '0' ; High <= '1' ;
25 ShiftA: shiftrne GENERIC MAP (N => length)26 PORT MAP ( A, Reset, High, Low, Clock, QA ) ;
27 ShiftB: shiftrne GENERIC MAP (N => length)28 PORT MAP ( B, Reset, High, Low, Clock, QB ) ;
![Page 14: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/14.jpg)
14 ECE 448 – FPGA and ASIC Design with VHDL
Serial adder FSM – Mealy state diagram
G
00 1
11 1 10 0 01 0
H 10 1 01 1 00 0
carry-in 0 =
carry-in 1 = G:
H:
Reset
11 0 ab s
![Page 15: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/15.jpg)
15 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Architecture (4)29 AdderFSM: PROCESS ( Reset, Clock )30 BEGIN31 IF Reset = '1' THEN32 y <= G ;33 ELSIF Clock'EVENT AND Clock = '1' THEN34 CASE y IS35 WHEN G =>36 IF QA(0) = '1' AND QB(0) = '1' THEN y <= H ;37 ELSE y <= G ;38 END IF ;39 WHEN H =>40 IF QA(0) = '0' AND QB(0) = '0' THEN y <= G ;41 ELSE y <= H ;42 END IF ;43 END CASE ;44 END IF ;45 END PROCESS AdderFSM ;
![Page 16: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/16.jpg)
16 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Architecture (5)
46 WITH y SELECT47 s <= QA(0) XOR QB(0) WHEN G,48 NOT ( QA(0) XOR QB(0) ) WHEN H ;
49 Null_in <= (OTHERS => '0') ;
50 ShiftSum: shiftrne GENERIC MAP ( N => length )51 PORT MAP ( Null_in, Reset, Run, s, Clock, Sum ) ;
![Page 17: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/17.jpg)
17 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder – Architecture (5)
52 Stop: PROCESS53 BEGIN54 WAIT UNTIL (Clock'EVENT AND Clock = '1') ;55 IF Reset = '1' THEN56 Count <= length ;57 ELSIF Run = '1' THEN58 Count <= Count -1 ;59 END IF ;60 END PROCESS ;
61 Run <= '0' WHEN Count = 0 ELSE '1' ; -- stops counter and ShiftSum
62 END Behavior ;
![Page 18: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/18.jpg)
18 ECE 448 – FPGA and ASIC Design with VHDL
Serial adder FSM – Mealy state diagram
G
00 1
11 1 10 0 01 0
H 10 1 01 1 00 0
carry-in 0 =
carry-in 1 = G:
H:
Reset
11 0 ab s
![Page 19: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/19.jpg)
19 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM – Mealy state table
Present Next state Output s
state ab =00 01 10 11 00 01 10 11
G G G G H 0 1 1 0 H G H H H 1 0 0 1
![Page 20: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/20.jpg)
20 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM – Mealy state-assigned table
Present Next state Output
state ab =00 01 10 11 00 01 10 11
y Y s
0 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1
![Page 21: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/21.jpg)
21 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder - Mealy FSM Circuit
Fulladder
a
b
s
D Q
Q
carry-out
Clock
Reset
Y y
![Page 22: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/22.jpg)
22 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM – Moore state diagram
H 1 s 1 =
Reset
H 0 s 0 =
011011
11
0110
G 1 s 1 =
G 0 s 0 =
0110 00
01
00
10
11
00
00
11
![Page 23: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/23.jpg)
23 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM – Moore state table
Present Nextstate Outputstate ab =00 01 10 11 s
G 0 G 0 G 1 G 1 H 0 0 G 1 G 0 G 1 G 1 H 0 1 H 0 G 1 H 0 H 0 H 1 0 H 1 G 1 H 0 H 0 H 1 1
![Page 24: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/24.jpg)
24 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM – Moore state-assigned table
Present Nextstate Outputstate ab =00 01 10 11 s
G 0 G 0 G 1 G 1 H 0 0 G 1 G 0 G 1 G 1 H 0 1 H 0 G 1 H 0 H 0 H 1 0 H 1 G 1 H 0 H 0 H 1 1
![Page 25: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/25.jpg)
25 ECE 448 – FPGA and ASIC Design with VHDL
Serial Adder FSM Circuit
Fulladder
a
b
D Q
Q Carry-out
Clock
Reset
D Q
Q
s
Y 2
Y 1 Sum bit
y 2
y 1
![Page 26: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/26.jpg)
26 ECE 448 – FPGA and ASIC Design with VHDL
The Arbiter Circuit
![Page 27: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/27.jpg)
27 ECE 448 – FPGA and ASIC Design with VHDL
The Arbiter Circuit
Arbiter
reset
r1
r2
r3
g1
g2
g3
clock
![Page 28: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/28.jpg)
28 ECE 448 – FPGA and ASIC Design with VHDL
The Arbiter Circuit – Moore state diagram
Idle
000
1xx
Reset
gnt1g 1 1 =
x1x
gnt2g 2 1 =
xx1
gnt3g 3 1 =
0xx 1xx
01x x0x
001 xx0
![Page 29: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/29.jpg)
29 ECE 448 – FPGA and ASIC Design with VHDL
The Arbiter Circuit – Alternative description
r 1 r 2
r 1 r 2 r 3
Idle
Reset
gnt1g 1 1 =
gnt2g 2 1 =
gnt3g 3 1 =
r 1 r 1
r 1
r 2
r 3
r 2
r 3
r 1 r 2 r 3
![Page 30: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/30.jpg)
30 ECE 448 – FPGA and ASIC Design with VHDL
Incorrect VHDL code for the grant signals
.
.
.PROCESS( y )BEGIN
IF y = gnt1 THEN g(1) <= '1' ;ELSIF y = gnt2 THEN g(2) <= '1' ;ELSIF y = gnt3 THEN g(3) <= '1' ;END IF ;
END PROCESS ;END Behavior ;
![Page 31: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/31.jpg)
31 ECE 448 – FPGA and ASIC Design with VHDL
Correct VHDL code for the grant signals
.
.
.PROCESS( y )BEGIN
g(1) <= '0' ;g(2) <= '0' ;g(3) <= '0' ;IF y = gnt1 THEN g(1) <= '1' ;ELSIF y = gnt2 THEN g(2) <= '1' ;ELSIF y = gnt3 THEN g(3) <= '1' ;END IF ;
END PROCESS ;END Behavior ;
![Page 32: Lecture9 FSM Examples](https://reader033.vdocuments.mx/reader033/viewer/2022051400/553208194a795943298b4b97/html5/thumbnails/32.jpg)
32 ECE 448 – FPGA and ASIC Design with VHDL
Simulation results for the Arbiter Circuit