位序检测器计数器不起作用(VHDL)

时间:2016-01-29 13:51:18

标签: vhdl

我构建了一个带有16位输入的4位序列检测器。 我现在想知道序列出现在16位中的频率。

为此,我使用此代码:

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

ENTITY seqdec IS
PORT    (   X:      IN      std_logic_vector(15 DOWNTO 0);
            CLK:    IN      std_logic;
            RESET:IN        std_logic;
            LOAD:   IN      std_logic;
            Y:      OUT std_logic);
END seqdec;

ARCHITECTURE SEQ OF seqdec IS
TYPE        statetype IS (s0, s1, s2, s3, s4);
SIGNAL  state, next_state: statetype;
SIGNAL  counter: std_logic_vector(3 DOWNTO 0) :="0000" ;
SIGNAL  temp:   std_logic_vector(15 DOWNTO 0);
SIGNAL  so:     std_logic;

    BEGIN
    STATE_AKT: PROCESS (CLK, RESET)
        BEGIN   
            IF RESET = '1' THEN     
                state <= s0 ;
                counter <= (OTHERS => '0') ;
            ELSIF CLK = '1' AND CLK'event THEN
                state <= next_state ;
            END IF;
        END PROCESS STATE_AKT;

    PISO:       PROCESS (CLK, LOAD, X)
        BEGIN
            IF (LOAD = '1') THEN
                temp(15 DOWNTO 0) <= X(15 DOWNTO 0);
            ELSIF (CLK'event and CLK='1') THEN
                so <= temp(15) ;
                temp(15 DOWNTO 1) <= temp(14 DOWNTO 0);
                temp(0) <= '0';
            END IF;
        END PROCESS PISO;



    STATE_CAL: PROCESS (so,state)
        BEGIN
            CASE state IS
                WHEN s0 =>  IF so = '0' THEN next_state <= s0  ;
                                ELSE next_state <= s1 ;
                                END IF;
                WHEN s1 =>  IF so = '0' THEN next_state <= s1;
                                ELSE next_state <= s2 ;
                                END IF;
                WHEN s2 =>  IF so = '0' THEN next_state <= s3 ;
                                ELSE next_state <= s2 ;
                                END IF;
                WHEN s3 =>  IF so = '0' THEN next_state <= s0 ;
                                ELSE next_state <= s4 ;
                                END IF;
                WHEN s4 =>  IF so = '0' THEN next_state <= s0;
                                ELSE next_state <= s2 ;
                                END IF;
                WHEN OTHERS => NULL;
            END CASE;
        END PROCESS STATE_CAL;

    STATE_Y: PROCESS (state)
        BEGIN
            CASE state IS
                WHEN s4 =>      
                    Y <= '1'; 
                    counter <= counter + '1';
                WHEN OTHERS =>  Y <= '0' ;
            END CASE;
        END PROCESS STATE_Y;
END SEQ;

但我的计数器重置和计数器的增加都没有起作用。 其余的工作完美无缺。

有人对我有暗示或想法吗?

1 个答案:

答案 0 :(得分:0)

该程序现在在ModelSim中运行良好,但我很难将其放在主板上。

我在ModelSim中对它进行了多次模拟,具有不同的参数并且工作正常,因此功能部分很好。

我的代码现在看起来像这样:

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

ENTITY seqdec IS
PORT    (   X:          IN      std_logic_vector(15 DOWNTO 0);
            CLK:        IN      std_logic;
            RESET:  IN      std_logic;
            LOAD:       IN      std_logic;
            DIGIT:  OUT std_logic_vector(6 DOWNTO 0) := "1111110";
            COUT:       OUT std_logic_vector(2 DOWNTO 0);
            Y:          OUT std_logic);
END seqdec;

ARCHITECTURE SEQ OF seqdec IS
TYPE        statetype IS (s0, s1, s2, s3, s4);
SIGNAL  state: statetype;
SIGNAL  next_state: statetype:=s0;
SIGNAL  counter: std_logic_vector(2 DOWNTO 0) :="000" ;
SIGNAL  temp:   std_logic_vector(15 DOWNTO 0);
SIGNAL  so:     std_logic := 'U';

-------------------Aktualisierung des Zustandes--------------------------------
    BEGIN
    STATE_AKT: PROCESS (CLK, RESET)
        BEGIN   
            IF RESET = '1' THEN     
                state <= s0;
            ELSIF CLK = '1' AND CLK'event THEN
                state <= next_state ;
            END IF;
        END PROCESS STATE_AKT;

---------------------Counter---------------------------------------------------
    COUNT:  PROCESS (state, RESET)
        BEGIN   
            IF (RESET = '1') THEN   
                counter <= (OTHERS => '0');
            ELSIF (state = s4) THEN
                counter <= counter + '1';
                COUT <= counter;
            END IF;
    END PROCESS COUNT;

-------------------PiSo für die Eingabe des zu Prüfenden Vektors---------------
    PISO:       PROCESS (CLK, LOAD, X)
        BEGIN
            IF (LOAD = '1') THEN
                temp(15 DOWNTO 0) <= X(15 DOWNTO 0);
            ELSIF (CLK'event and CLK='1') THEN
                so <= temp(15);
                temp(15 DOWNTO 1) <= temp(14 DOWNTO 0);
                temp(0) <= '0';
            END IF;
        END PROCESS PISO;

-------------------Zustandsabfrage und Berechnung------------------------------
    STATE_CAL: PROCESS (so,state)
        BEGIN
            CASE state IS
                WHEN s0 =>  IF so = '0' THEN next_state <= s0  ;
                                ELSIF (so = '1') THEN next_state <= s1 ;
                                END IF;
                WHEN s1 =>  IF so = '0' THEN next_state <= s1;
                                ELSIF (so = '1') THEN next_state <= s2 ;
                                END IF;
                WHEN s2 =>  IF so = '0' THEN next_state <= s3 ;
                                ELSIF (so = '1') THEN next_state <= s2 ;
                                END IF;
                WHEN s3 =>  IF so = '0' THEN next_state <= s0 ;
                                ELSIF (so = '1') THEN next_state <= s4 ;
                                END IF;
                WHEN s4 =>  IF so = '0' THEN next_state <= s0;
                                ELSIF (so = '1') THEN next_state <= s2 ;
                                END IF;
                WHEN OTHERS => NULL;
            END CASE;
        END PROCESS STATE_CAL;

-------------------Ausgang-----------------------------------------------------
    STATE_Y: PROCESS (state)
        BEGIN
            CASE state IS
                WHEN s4 =>      
                    Y <= '1'; 
                WHEN OTHERS =>  Y <= '0' ;
            END CASE;
        END PROCESS STATE_Y;

-------------------7 Segment---------------------------------------------------
    SEVEN_SEG: PROCESS (counter, CLK)
        BEGIN
            IF (RESET = '1') THEN
                DIGIT <= "1111110";
            END IF;
            CASE counter IS
                WHEN "000" => DIGIT <= "1111110";
                WHEN "001" => DIGIT <= "0110000";
                WHEN "010" => DIGIT <= "1101101";
                WHEN "011" => DIGIT <= "1111001";
                WHEN "100" => DIGIT <= "0110011";
                WHEN "101" => DIGIT <= "1011011";
                WHEN OTHERS => NULL;
            END CASE;
        END PROCESS SEVEN_SEG;


END SEQ;

当我把它放在棋盘上时,7段会显示&#34; 3&#34;。 我认为,由于功能部分似乎很好,它必须对时间做一些思考,但我无法找到任何解决方案。如果有一些经验VHDL程序员可以给我一个很好的新提示。

祝你好运 阿德里安