VHDL中具有最终状态机结构的计数器。石英

时间:2018-11-07 18:21:53

标签: vhdl counter fsm quartus

我已经生成了此VHDL代码,并使用VWF文件对其进行了测试,似乎可以正常工作。但是我的代码生成的有限状态机(我可以使用QUARTUS工具“状态机查看器”看到它)似乎是错误的。在此FSM中,似乎在每种状态下都可能到达任何其他状态。 根据我的项目目标,我需要一个从0到9计数的计数器,该计数器根据两个输入信号w0和w1的值来改变其值。如果w0和w1均为零,则计数器进入其当前状态;如果w0为0并且w1为1,则计数器加1;如果w0为1,而w1为0,则计数器加2;如果w0和w1均为1计数器递减一。还有一个时钟信号和一个复位信号。

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY counter IS
    PORT(clk, reset :in std_logic;
                      w :in std_logic_vector(1 DOWNTO 0);
                  cont :out std_logic_vector(3 DOWNTO 0););
END;


ARCHITECTURE arch_counter OF counter IS

TYPE state IS (zero, one, two, three, four, five, six, seven, eight, nine);
SIGNAL numbCorr, numbFuture :state;

BEGIN



    PROCESS(w, numbCorr)
        BEGIN

            CASE numbCorr IS
                WHEN zero => IF w = "00" THEN numbFuture <= zero; 
                            ELSIF w = "01" THEN numbFuture <= one;  
                            ELSIF w = "10" THEN numbFuture <= two;  
                            ELSIF w = "11" THEN numbFuture <= zero; 
                             END IF;
                             cont <= "0000";
                WHEN one => IF  w = "00" THEN numbFuture <= one;
                             ELSIF w = "01" THEN numbFuture <= two;
                             ELSIF w = "10" THEN numbFuture <= three;
                             ELSIF w = "11" THEN numbFuture <= zero;
                             END IF;
                             cont <= "0001";
                WHEN two => IF   w = "00" THEN numbFuture <= two;
                             ELSIF w = "01" THEN numbFuture <= three;
                             ELSIF w = "10" THEN numbFuture <= four;
                             ELSIF w = "11" THEN numbFuture <= one;
                             END IF;
                             cont <= "0010";
                WHEN three => IF     w = "00" THEN numbFuture <= three;
                             ELSIF w = "01" THEN numbFuture <= four;
                             ELSIF w = "10" THEN numbFuture <= five;
                             ELSIF w = "11" THEN numbFuture <= two;
                             END IF;
                             cont <= "0011";
                WHEN four => IF      w = "00" THEN numbFuture <= four;
                             ELSIF w = "01" THEN numbFuture <= five;
                             ELSIF w = "10" THEN numbFuture <= six;
                             ELSIF w = "11" THEN numbFuture <= three;
                             END IF;
                             cont <= "0100";
                WHEN five => IF w = "00" THEN numbFuture <= five;
                             ELSIF w = "01" THEN numbFuture <= six;
                             ELSIF w = "10" THEN numbFuture <= seven;
                             ELSIF w = "11" THEN numbFuture <= four;
                             END IF;
                             cont <= "0101";
                WHEN six => IF   w = "00" THEN numbFuture <= six;
                             ELSIF w = "01" THEN numbFuture <= seven;
                             ELSIF w = "10" THEN numbFuture <= eight;
                             ELSIF w = "11" THEN numbFuture <= five;
                             END IF;
                             cont <= "0110";
                WHEN seven => IF     w = "00" THEN numbFuture <= seven;
                             ELSIF w = "01" THEN numbFuture <= eight;
                             ELSIF w = "10" THEN numbFuture <= nine;
                             ELSIF w = "11" THEN numbFuture <= six;
                             END IF;
                             cont <= "0111";
                WHEN eight => IF     w = "00" THEN numbFuture <= eight;
                             ELSIF w = "01" THEN numbFuture <= nine;
                             ELSIF w = "10" THEN numbFuture <= nine; 
                             ELSIF w = "11" THEN numbFuture <= eight;
                             END IF;
                             cont <= "1000";
                WHEN nine => IF      w = "00" THEN numbFuture <= nine;
                             ELSIF w = "01" THEN numbFuture <= nine; 
                             ELSIF w = "10" THEN numbFuture <= nine; 
                             ELSIF w = "11" THEN numbFuture <= eight;
                             END IF;
                             cont <= "1001";
                END CASE;


        END PROCESS;

        PROCESS(clk)
            BEGIN 
                IF (rising_edge(clk)) THEN 
                    IF reset = '0' THEN numbCorr <= numbFuture ;
                    ELSE numbCorr <= zero; 
                    END IF;
                END IF;

            END PROCESS;



END;

我认为使用此代码是不可能的,如果当前状态为“零”,则未来状态将为“七”(从FSM查看器看来是可能的)。是对还是我错了?

这是quartus生成的FSM(numberState是意大利语,因为我的原始代码是意大利语)

{{3}}

0 个答案:

没有答案