22
Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

  • View
    217

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Finite State Machines

Mano and Kime

Sections 4-4, 4-5, 4-8

Page 2: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Canonical Sequential Network

Sta

te R

egis

ter

Com

bina

tion

alN

etw

ork

x(t)

s(t+1) s(t)

z(t)clk

init

present state

present input

nextstate

present output

Page 3: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Mealy Machine

Sta

te R

egis

ter

C1

x(t)

s(t+1)

s(t)z(t)

clk

init

present state

present input

nextstate

C2

Page 4: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Moore Machine

Sta

te R

egis

ter

C1

x(t)

s(t+1)

s(t)

z(t)

clk

init

present state

present input

nextstate

C2

Page 5: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

VHDLCanonical Sequential Network

Sta

te R

egis

ter

Com

bina

tion

alN

etw

ork

x(t)

s(t+1) s(t)

z(t)clk

init

present state

present input

nextstate

present output

process(clk, init)

process(present_state, x)

Page 6: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

VHDLMealy Machine

Sta

te R

egis

ter

C1

x(t)

s(t+1)

s(t)z(t)

clk

init

present state

present input

nextstate

C2

process(clk, init)

process(present_state, x)

process(present_state, x)

Page 7: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

VHDLMoore Machine

Sta

te R

egis

ter

C1

x(t)

s(t+1)

s(t)

z(t)

clk

init

present state

present input

nextstate

C2

process(present_state, x) process(present_state)

process(clk, init)

Page 8: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

ExampleDetect input sequence 1101

fsm

din

doutclk

clr

dindout

1 0 1 1 0 1 1 0 1 0 0 1 1 0 1 00 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0

Page 9: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Easy Solution:Use Shift Register

CLK

D Q

!Q CLK

D Q

!Q CLK

D Q

!Q CLK

D Q

!Q

CLK

Q0 Q1 Q2 Q3

1 0 1 1

dout

din

Page 10: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

More General: Use State DiagramDetect input sequence 1101

S00

S10

S110

S1100

S11011

11

0

1

0 10

0

1

0

CLR

Page 11: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsm.vhd

fsm

din

doutclk

clr

entity fsm is port (clk: in STD_LOGIC; clr: in STD_LOGIC; din: in STD_LOGIC; dout: out STD_LOGIC);end;

Page 12: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsm.vhd

architecture fsm_arch of fsm is

type state_type is (S0, S1, S11, S110, S1101);signal present_state, next_state: state_type;

begin

Page 13: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

synch: process(clk, clr)begin if clr = '1' then present_state <= S0; elsif clk'event and clk = '1' then present_state <= next_state; end if;end process;

fsm.vhd

Page 14: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsm.vhdcomb1: process(present_state, din)begin case present_state is

when S0 => if din = '1' then next_state <= S1; else next_state <= S0; end if;when S1 => if din = '1' then next_state <= S11; else next_state <= S0; end if;

Page 15: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsm.vhdwhen S11 => if din = '0' then next_state <= S110; else next_state <= S11; end if;when S110 => if din = '1' then next_state <= S1101; else next_state <= S0; end if; when S1101 => if din = '0' then next_state <= S0; else next_state <= S11; end if;when others => null;end case;

end process;

Page 16: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsm.vhd

comb2: process(present_state)begin if present_state = S1101 then dout <= '1'; else dout <= '0'; end if;end process;

end fsm_arch;

Page 17: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsmx.vhd

fsm

clk_pulse

SW1bn

BTN4

LD1

LD8din

doutclr

clk

fsmx

IBUFG

clkdivmclk

Page 18: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsmx.vhd

entity fsmx is

port(

mclk : in STD_LOGIC;

bn : in STD_LOGIC;

SW : in STD_LOGIC_VECTOR(1 to 8);

BTN4 : in STD_LOGIC;

led: out std_logic;

ldg : out STD_LOGIC;

LD : out STD_LOGIC_VECTOR(1 to 8)

);

end fsmx;

Page 19: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsmx.vhd

architecture fsmx of fsmx is component fsm port( clk : in std_logic; clr : in std_logic; din : in std_logic; dout : out std_logic); end component;

Page 20: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsmx.vhdcomponent clk_pulse

port(

BTN4 : in std_logic;

cclk : in std_logic;

clr : in std_logic;

clk : out std_logic);

end component;

signal clr, clk, cclk, bnbuf: std_logic;

signal clkdiv: std_logic_vector(23 downto 0);

Page 21: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

fsmx.vhd

U0: clk_pulse port map

(BTN4 => BTN4, cclk => cclk, clr =>clr, clk => clk);

U1: fsm port map

(clr =>clr, clk => clk, din => SW(1), dout => LD(8));

LD(1) <= SW(1);

Page 22: Finite State Machines Mano and Kime Sections 4-4, 4-5, 4-8

Detect input sequence 1101