end if

Transkrypt

end if
Projektowanie automatów z użyciem VHDL




struktura automatu i jego modelu w VHDL
przerzutnik T jako automat
przykłady automatów z wyjściami typu:
 Moore'a
 Mealy
 stanu
kodowanie stanów automatu
Wykorzystano przykłady z:
The Low-Carb VHDL Tutorial
© 2004 by Bryan Mealy (08-27-2004)
PUE-w05
1
Schemat blokowy automatu i jego model w VHDL
PUE-w05
2
Szablon opisu architektury dowolnego automatu
architecture szablon of nazwa_modelu is
deklaracje sygnalow wewnetrznych
begin
–– proces stan opisuje czesc sekwencyjną (synchroniczną)
stan: process (lista wrazliwosci ––clk,rst,NextState)
begin
instrukcje VHDL dla przerzutnikow
end process stan;
–– proces komb definiuje część kombinatoryczną
komb: process (lista wrazliwosci –– wszystkie wejścia)
begin
instrukcje VHDL opisujace część kombinacyjną
end process komb;
-- (opcjonalna instrukcja wyprowadzająca stan jako wyjście)
end architecture szablon;
PUE-w05
3
Przerzutnik T jako automat Moore'a
entity my_fsm1 is
port (
FSM - Finite State Machine ;
TOG_EN - Toggle Enable ;
CLR - Clear; CLK - Clock ;
ST0, ST1 - State 0, State 1
TOG_EN : in std_logic;
CLK,CLR : in std_logic;
Z1 : out std_logic);
end entity my_fsm1;
PUE-w05
4
Przerzutnik T jako automat Moore'a
architecture fsm1 of my_fsm1 is
type state_type is (ST0,ST1);
signal PS,NS : state_type;
begin
sync: process(CLK,NS,CLR)
begin
if (CLR = „1‟) then PS <= ST0;
elsif (rising_edge(CLK)) then PS <= NS;
end if;
end process sync_proc;
--(proces kombinacyjny na następnym slajdzie)
end architecture fsm1;
PUE-w05
5
Przerzutnik T jako automat Moore'a
comb: process(PS,TOG_EN)
begin
case PS is
when ST0 =>
if (TOG_EN =„1‟)
end if;
when ST1 =>
if (TOG_EN =„1‟)
end if;
when others =>
Z1 <= „0‟;
then NS <= ST1;
else NS <= ST0;
Z1 <= „1‟;
then NS <= ST0;
else NS <= ST1;
Z1 <= „0‟;
NS <= ST0;
end case;
end process comb;
PUE-w05
6
Przerzutnik T jako automat Moore'a- uwagi
• Zadeklarowano typ wyliczeniowy state_type do reprezentowania
stanów: PS - Present State, NS - Next State
• Proces sync opisuje asynchroniczne zerowanie i synchroniczne przejście do
nowego stanu; proces comb obsługuje wyjście Z1 oraz oblicza stan NS
• Oba procesy są współbieżne; zmiana NS wymusza obliczenia procesu sync,
ale w nie powoduje to natychmiastowej zmiany żadnego innego sygnału;
przypisanie PS<=NS następuje dopiero gdy narasta sygnał clk; zmiana PS
uruchamia proces comb w którym obliczany jest następny stan NS
• Klauzula when others w procesie comb obejmuje przypadki, które nie
powinny się zdarzyć, (np. po awaryjnym zakłóceniu, zaniku zasilania itp.)
• Można wyprowadzić stan PS jako wyjście nie w comb ale przy pomocy
współbieżnej z oboma procesami instrukcji, np.:
with PS select
Z1 <= „0‟ when ST0,
„1‟ when ST1,
„0‟ when others;
PUE-w05
7
Automat z wyprowadzonym stanem Y i wyjściem Mealy Z2
entity my_fsm3 is
port (
X
: in std_logic;
CLK : in std_logic;
SET : in std_logic;
Z2
: out std_logic;
Y
: out
std_logic_vector(1 downto 0));
end entity my_fsm3;
PUE-w05
8
Architektura automatu my_fsm3 (1)
architecture fsm3 of my_fsm3 is
type state_type is (ST0,ST1,ST2);
signal PS,NS : state_type;
begin
sync: process(CLK,NS,SET)
begin
if (SET = „1‟) then PS <= ST2;
elsif (rising_edge(CLK)) then PS <= NS;
end if;
end process sync;
-- (opis procesu comb na nastepnym slajdzie)
with PS select
Y <= “00” when ST0,
“10” when ST1,
“11” when ST2,
“00” when others;
end architecture fsm3;
PUE-w05
9
Architektura automatu my_fsm3 (2)
comb: process(PS,X)
begin
case PS is
when ST0 =>
if (X = „0‟)
end if;
when ST1 =>
if (X = „0‟)
end if;
when ST2 =>
if (X = „0‟)
end if;
when others =>
end case;
end process comb;
Z2 <= „0‟;
then NS <= ST0;
else NS <= ST1;
Z2 <= „0‟;
then NS <= ST0;
else NS <= ST2;
then NS <= ST0; Z2 <= „0‟;
else NS <= ST2; Z2 <= „1‟;
NS <= ST0; Z2 <= „1‟;
PUE-w05
10
Automat z trzema rodzajami wyjść (1)
entity my_fsm4 is
port (
X,CLK,RESET : in std_logic;
Y : out
std_logic_vector(1 downto 0);
Z1,Z2 : out std_logic);
end entity my_fsm4;
PUE-w05
11
Automat z trzema rodzajami wyjść (2)
architecture fsm4 of my_fsm4 is
type state_type is (ST0,ST1,ST2,ST3);
signal PS,NS : state_type;
begin
sync: process(CLK,NS,RESET)
begin
if (RESET = „1‟) then PS <= ST0;
elsif (rising_edge(CLK)) then PS <= NS;
end if;
end process sync;
with PS select
Y <= “00” when ST0,
“01” when ST1,
“10” when ST2,
“11” when ST3,
“00” when others;
--(process comb na nastepnym slajdzie)
end architecture fsm4;
PUE-w05
12
Automat z trzema rodzajami wyjść (3)
comb: process(PS,X)
begin
case PS is
when ST0 =>
if (X = „0‟) then NS <=
else NS <=
when ST1 =>
if (X = „0‟) then NS <=
else NS <=
when ST2 =>
if (X = „0‟) then NS <=
else NS <=
when ST3 =>
if (X = „0‟) then NS <=
else NS <=
when others => Z1 <= „1‟;
end case;
end process comb;
PUE-w05
Z1 <=
ST2; Z2 <=
ST1; Z2 <=
Z1 <=
ST2; Z2 <=
ST1; Z2 <=
Z1 <=
ST3; Z2 <=
ST2; Z2 <=
Z1 <=
ST0; Z2 <=
ST3; Z2 <=
Z2 <= „0‟;
„1‟;
„0‟;
„1‟; end if;
„1‟;
„0‟;
„1‟; end if;
„0‟;
„0‟;
„1‟; end if;
„1‟;
„0‟;
„1‟; end if;
NS <= ST0;
13
Kodowanie stanów automatu
1. Minimalna liczba przerzutników (np. kod NB)
N FF
log2 N ST
2. Kod 1 z N (tyle przerzutników ile stanów)
N FF
N ST
Dlaczego 1 z N ?
• prostsze funkcje wyjść
• dziś przerzutniki nie są kosztowne
• układy programowalne PLD mają przerzutniki
blisko końcówek wyjściowych
• mniej logiki kombinacyjnej => szybsze działanie
PUE-w05
14
Zmiana sposobu kodowania stanów
-- full encoded approach
entity my_fsm4 is
port ( X,CLK,RESET : in std_logic;
Y
: out std_logic_vector(1 downto 0);
Z1,Z2
: out std_logic);
end entity my_fsm4;
-- one-hot encoding approach
entity my_fsm4 is
port ( X,CLK,RESET : in std_logic;
Y
Z1,Z2
end my_fsm4;
: out std_logic_vector(3 downto 0);
: out std_logic);
PUE-w05
15
Zmiana sposobu kodowania stanów
architecture fsm4 of my_fsm4 is
type state_type is (ST0,ST1,ST2,ST3);
attribute ENUM_ENCODING: STRING;
attribute ENUM_ENCODING of state_type:
type is “1000 0100 0010 0001”;
signal PS,NS : state_type;
begin
-- (oba procesy bez zmian)
-- full encoded approach
with PS select
Y <= “00” when ST0,
“01” when ST1,
“10” when ST2,
“11” when ST3,
“00” when others;
end architecture fsm4;
-- one-hot encoded approach
with PS select
Y <= “1000” when ST0,
“0100” when ST1,
“0010” when ST2,
“0001” when ST3,
“1000” when others;
end architecture fsm4;
PUE-w05
16

Podobne dokumenty