vhdl state machine

Mokwon Univ 2008. 8. 16. 17:13
상태머신(State Machine) 설계
 
HW 1. moore machine
 
Text Editor
 
-- 0039085 Jung Yong Hak
LIBRARY ieee; USE ieee.std_logic_1164.all;
ENTITY moore_hw IS
             PORT(cl, rst, x, control : in std_logic;
                             y : out std_logic_vector(0 to 2));  -- y값 표현을 위해 vector사용
END moore_hw;
 
ARCHITECTURE behav of moore_hw is
             type states is (st0,st1,st2,st3);   -- 자료형선언
             signal z : states;                            -- 신호선언
BEGIN
             p1 : PROCESS(cl,rst)
             BEGIN
                           IF RST='0' then  z<=st0;                -- rst 0일시 초기화
                           ELSIF (cl'event and cl='1') then    -- 클락이 라이징 edge가 들어올 때
                                       case z is when st0 => if x='0' then z<=st0;
                                                                                else z<=st1; end if;
                                        when st1 => if x='0' then   z<=st0;
                                                                                elsif control='0' then z<=st2;
                                                                                else z<=st3; end if;
                                        when st2 => if x='0' then z<=st0;
                                                                               else z<=st3; end if;
                                        when st3 => z<=st0;   -- st3 다음에는 무조건 st0
                           end case;
                          end if;
end PROCESS;
 
             p2 : PROCESS(z)  -- z값에 따른 출력
             BEGIN
                           case z is              when st0 => y<="001";  -- 1을 나타냄
                                                       when st1 => y<="010";  -- 2를 나타냄
                                                       when st2 => y<="011";  -- 3을 나타냄
                                                       when st3 => y<="100";  -- 4를 나타냄
                           end case;
             end PROCESS;
end behav;
 
 
 
상태설명
 
4가지 상태(st0,st1,st2,st3)를 가지고 입력 x와 출력 y를 갖는 무어모델이다.
초기상태에서 출력 y 1값을 가지고 있다. rst값이 1이고 cl이 들어올때, 입력 x 1이 들어오면 출력 y 2값을 가진다. 다시 x 1이 들어올 때, control값이 1이면 출력 y 4로 가고 control 0이면 출력 y 3을 가진다. 만약에 x값이 0이 들어오면 출력 y는 무조건 1을 가진다. y값이 4일 때 입력 x 1이 들어오든 0이 들어오면 출력 y 1을 가리킨다.
 
 
 
 
HW 2. mealy machine
 
Text Editor
 
-- 0039085 Jung Yong Hak
LIBRARY ieee; USE ieee.std_logic_1164.all;
ENTITY mealy_hw IS
             PORT(cl, rst, x : in std_logic;
                             z : out std_logic); 
END mealy_hw;
 
ARCHITECTURE behav of mealy_hw is
             type states is (st0,st1,st2,st3,st4);                         -- 상태표시 타입선언
             signal y : states;             
BEGIN
             p1 : PROCESS(cl,rst)
             BEGIN
                           IF RST='0' then  y<=st0;               
                           ELSIF (cl'event and cl='1') then   -- 클락이 라이징 edge 될 때
                           case y is when st0 => if x='0' then y<=st1; else y<=st0; end if;
                                          when st1 => if x='0' then y<=st1; else y<=st2; end if;
                                          when st2 => if x='0' then y<=st0; else y<=st3; end if;
                                          when st3 => if x='0' then y<=st3; else y<=st4; end if;
                                          when st4 => if x='0' then y<=st2; else y<=st0; end if;
                           end case;
                           end if;
             end PROCESS;
             p2 : PROCESS(y,x)
             BEGIN
                           case y is            when st0 => z<=x;            -- 입력값 출력
                                                     when st1 => z<='0';          -- 무조건 0출력
                                                     when st2 => z<='0';          -- 무조건 0출력
                                                     when st3 => z<=x;            -- 입력값 출력
                                                     when st4 => z<=not(x);     -- 입력값 반대출력
                           end case;
             end PROCESS;
end behav;
 
상태설명
 
5가지 상태(st0,st1,st2,st3,st4)를 가지고 입력 x와 출력 z를 갖는 밀리모델이다.
초기상태 st0에서 입력이 0이면 상태는 st1이고 입력이 1이면 상태는 st0을 가리킨다. st1에서 입력이 0이면 상태는 st1이고 입력이 1이면 상태는 st2를 가리킨다. st2에서 입력이 0이면 상태는 st0이고 입력이 1이면 상태는 st3이다. st3에서 입력이 0이면 상태는 st3이고 입력이 1이면 상태는 st4이다. st4에서 입력이 0이면 상태는 st2이고 입력이 1이면 상태는 st0이다. 각 상태에 따라 출력값은 다르다. st0일 경우 입력값이 출력값이 되고, st1 st2인경우 출력값은 무조건 0이고, st3인경우 입력값이 출력값이 되고, st4인경우 입력값의 역수가 출력값이 된다.
Posted by 용학도리
,