VHDL状态机

时间:2012-06-05 06:04:45

标签: vhdl

我在VHDL中写了一些代码,预计会看到一个旋转开关并反馈给我。它位于什么位置。

当它转动时,它将从转子拨盘读取greycode并将状态切换到相应的greycode状态。

改变状态的行为告诉我转子被扭转的方式,所以我可以在电路的后面的计数器模块上指示上升或下降状态。

如果状态发生变化,它应该触发Mag上的脉冲,并在up_dwn上触发1或0。

我模拟它时不起作用。我在Mag上获得了偶然的昙花一现,但没有up_dwn更改。

我怀疑它处于START状态。

任何人都在关注并告诉我我做错了什么?

[编辑:使用Quartus II版本9]

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY EncoderV2    IS
PORT(
    CH_AB           :   IN  STD_LOGIC_VECTOR (1 downto 0);
    clk             :   IN  STD_LOGIC;
    nReset          :   IN  STD_LOGIC;
    up_dwn, Mag     :   OUT STD_LOGIC);

    END EncoderV2;

ARCHITECTURE a OF EncoderV2 IS  --  
TYPE STATE_TYPE IS ( START, s00, s01, s11, s10);
SIGNAL state:   STATE_TYPE;

BEGIN
PROCESS (clk, nReset)
BEGIN
    IF nReset = '0' THEN                        --    asynch Reset to zero
        state   <=  START;
    ELSIF clk'EVENT AND clk = '1' THEN          --  triggers on PGT
        CASE state IS 
            WHEN START =>
                    IF CH_AB ="00" THEN
                                state   <= s00;
                                Mag <='0';
                    ELSIF CH_AB="01" THEN
                                state   <= s01;
                                Mag <='0';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                Mag <='0';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                Mag <='0';
                    ELSE  state <= START;
                    END IF;

            WHEN s00 =>                 --  S10 <- S00 -> S01
                    IF CH_AB= "00" THEN
                                state   <= s00;
                                Mag <='0';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "01" THEN
                                state   <= s01;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE  state <= START;
                    END IF;

            WHEN s01 =>                 --  S00 <- S01 -> S11
                    IF CH_AB= "01" THEN
                                state   <= s01;
                                Mag <='0';
                    ELSIF CH_AB= "00" THEN
                                state   <= s00;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;

            WHEN s11 =>                 --  S01 <- S11 ->S10
                    IF CH_AB= "11" THEN
                                state   <= s11;
                                Mag <='0';
                    ELSIF CH_AB= "01" THEN
                                state   <= s01;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "10" THEN
                                state   <= s10;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;

            WHEN s10 =>                 --  S11 <- S10 -> S00
                    IF CH_AB= "10" THEN
                                state   <= s10;
                                Mag <='0';
                    ELSIF CH_AB= "11" THEN
                                state   <= s11;
                                up_dwn  <= '0';
                                Mag <='1';
                    ELSIF CH_AB= "00" THEN
                                state   <= s00;
                                up_dwn  <='1';
                                Mag <='1';
                    ELSE state <= START;
                    END IF;





            END CASE;
        END IF;
    END PROCESS;
END a;

1 个答案:

答案 0 :(得分:0)

对我来说很好......用Modelsim模拟

我用50,100和200 MHz模拟了它。 我唯一想知道的是你使用“IF .. nReset ='0'那么”..你确定吗? 在我看到它并在我的刺激文件中更改它之前,花了我2​​0分钟。