lecture9 fsm examples

32
George Mason University ECE 448 – FPGA and ASIC Design with VHDL FSM Examples: Serial Adder, The Arbiter Circuit ECE 448 Lecture 9

Upload: anil-kumar-dendukuri

Post on 16-Apr-2015

28 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture9 FSM Examples

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

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

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

4 ECE 448 – FPGA and ASIC Design with VHDL

Mixing Design Styles

within a Single Architecture

Page 5: Lecture9 FSM Examples

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

6 ECE 448 – FPGA and ASIC Design with VHDL

Serial Adder

Page 7: Lecture9 FSM Examples

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

26 ECE 448 – FPGA and ASIC Design with VHDL

The Arbiter Circuit

Page 27: Lecture9 FSM Examples

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

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

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

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

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

32 ECE 448 – FPGA and ASIC Design with VHDL

Simulation results for the Arbiter Circuit