Испытательный стенд для FSM - PullRequest
0 голосов
/ 22 февраля 2020

Я пытаюсь реализовать testbench для следующего fsm, созданного в vhdl. Проблема в том, что в настоящее время я не вижу никаких переходов между состояниями в тестовом стенде. Симуляция остается в состоянии 0.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;


entity FPGA_Challenge is
    Port ( led : out STD_LOGIC;
           clk_in : in STD_LOGIC;  -- 100 MHZ internal clock 
           reset : in STD_LOGIC;  -- is reset necessary 
           button : in STD_LOGIC;
           data_line : in STD_LOGIC);
end FPGA_Challenge;

architecture Behavioral of FPGA_Challenge is

type state_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20);

signal state: state_type;

signal x:std_logic;
signal y:std_logic;

signal count : integer:= 0; 
--signal tmp: std_logic:= '1';


begin

process(clk_in, reset)
    begin 
        if rising_edge(clk_in)then
            if reset = '1'then  -- Goes back to known state (state 0)
                state <= s0;
                count <= 0;
            else
                count <= count + 1;


            case state is 
                -- Initial state- if button is pressed, then LED is lit and machine goes to state 2, if not it stays in state 1
                when s0 =>
                    if (button <= '1') then
                        led <= '1';
                        state <= s1; 
                    else 
                        state <= s0;
                        led <= '0';  --is this necessary? 

                    end if;
                -- Beginning of preamble detection(states 1-17) 
                -- Count = ((freq in) / (freq out))/ 2  -1 = (100 MHz/ 2 MHz)/ 2 -1 = 50/2 - 1 (due to 50% duty cycle) 
                when s1=>  -- do I need to put led = '1' in each state because it stays on ? 
                    if (count = 25 -1) then 
                        count <= 0;
                        if (data_line = '1')then
                            y <= '0';
                --      led = '1';
                            state <= s2;

                        else
                  --     led = '1';
                            y <= '0'; 
                            state <= s1;
                        end if;

                    else
                        count <= count + 1; 
                    end if;

                      --clock_out <= tmp;


                when s2 =>
                    if (count = 25-1) then
                        count <= 0;
                        if (data_line = '0')then
                            y <= '0';
                       -- led = '1';
                            state <= s3;

                        else 
                            state <= s2;
                            y <= '0';
                       -- led = '1';
                        end if;

                    else
                        count <= count + 1; 
                    end if;

                         --clock_out <= tmp;

                when s3 =>
                    if (count = 25-1)then
                        count <= 0; ----reinitializes count 

                        if (data_line <= '1')then
                            y <= '0';
                       -- led = '1';
                            state <= s4; 

                        else 
                            state <= s1;
                            y <= '0';
                       -- led = '1';
                        end if;

                    else
                            count <= count + 1; 


                    end if;
                       -- clock_out <= tmp;


                 when s4 =>
                    if (count = 25-1)then
                        count <= 0;

                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s5;

                        else 
                            state <= s2;
                            y <= '0';
                        --led = '1';
                        end if;   

                    else
                        count <= count + 1; 
                    end if;

                      --  clock_out <= tmp;


                 when s5 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s6;

                        else 
                            state <= s4;
                            y <= '0';
                        --led = '1';
                        end if;

                    else
                        count <= count + 1; 
                    end if;

                        --clock_out <= tmp;


                 when s6 =>
                    if (count= 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s7;

                        else 
                            state <= s2;
                            y <= '0';
                       --led = '1';
                        end if;
                    else
                         count <= count + 1; 
                    end if;

                        -- clock_out <= tmp;

                 when s7 =>
                    if (count = 25-1)then
                        count<= 0;

                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s7;

                        else 
                            state <= s2;
                            y <= '0';
                       --led = '1';
                            end if;
                    else
                         count <= count + 1; 
                    end if;


                         --clock_out <= tmp;                         

                 when s8 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='1')then
                            y <= '0';
                       -- led = '1';
                            state <= s9;

                        else 
                            state <= s1;
                            y <= '0';
                        --led = '1';
                        end if;
                    else
                        count <= count + 1; 

                    end if;
                       -- clock_out <= tmp;


                 when s9 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                       -- led = '1';
                            state <= s10;

                        else 
                            state <= s2;
                            y <= '0';
                       --led = '1';
                        end if;

                    else
                        count <= count + 1; 

                    end if;
                         --clock_out <= tmp; 


                 when s10=>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='1')then
                            y <= '0';
                        --led = '1';
                            state <= s11;

                        else 
                            state <= s1;
                            y <= '0';
                        --led = '1';
                        end if;

                    else
                        count <= count + 1; 
                    end if;

                      --  clock_out <= tmp;

                when s11 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s12;

                        else 
                            state <= s2;
                            y <= '0';
                        --led = '1';
                        end if;
                    else
                        count <= count + 1; 

                    end if;
                        --clock_out <= tmp;

                when s12 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        --led = '1';
                            state <= s13;

                        else 
                            state <= s2;
                            y <= '0';
                        --led = '1';
                        end if;
                    else
                        count <= count + 1; 

                    end if;
                       -- clock_out <= tmp;

                when s13 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        -- led = '1';
                            state <= s14;

                        else 
                            state <= s2;
                            y <= '0';
                        -- led = '1';
                        end if;
                    else
                        count <= count + 1; 

                    end if;
                       -- clock_out <= tmp;

                when s14 =>
                    if (count = 25-1)then
                        count <=0;
                        if (data_line <='0')then
                            y <= '0';
                        -- led = '1';
                            state <= s15;

                        else 
                            state <= s2;
                            y <= '0';
                        -- led = '1';
                         end if;
                    else
                        count <= count + 1; 

                    end if;
                        --clock_out <= tmp;

                when s15 =>
                    if (count = 25-1)then
                        count <=0;
                        if (data_line <='0') then
                            y <= '0';
                        -- led = '1';
                            state <= s16;

                        else 
                            state <= s2;
                            y <= '0';
                        -- led = '1';
                        end if; 
                    else
                        count <= count + 1; 

                    end if;
                       -- clock_out <= tmp;

                when s16 =>
                    if (count = 25-1) then
                        count <= 0;
                        if (data_line <='0')then
                            y <= '0';
                        -- led = '1';
                            state <= s17;

                        else 
                            state <= s2;
                            y <= '0';
                        -- led = '1';
                        end if;
                    else
                        count <= count + 1; 

                    end if;
                        --clock_out <= tmp;

                when s17 =>
                    if (count = 25-1)then
                        count <= 0;
                        if (data_line ='1')then
                            y <= '1';
                        -- led = '1';
                            state <= s18;

                        else 
                            state <= s1;
                            y <= '0';
                        --led = '1';
                            end if; 
                    else
                        count <= count + 1; 

                    end if;
                        --clock_out <= tmp;

                when s18 => -- no real condition here except varying period of clock 
                    if (count = 25)then  
                        count <= 0; ----reinitializes count
                        state <= s19; 
                    else
                        count <= count + 1; 
                    end if;

                       -- clock_out <= tmp;


                when s19=> -- no real condition here except varying period of clock 

                    if (count = 25)then  
                        count <= 0; ----reinitializes count
                        state <= s0; 
                    else
                        count <= count + 1; 
                    end if;
                        --clock_out <= tmp;


                when others=>
                    null; 

            end case;

        end if;
    end if;

end process;

end architecture;

Ниже приведен тестовый стенд, который у меня есть. У меня есть внутренние сигналы, такие как y (вывод для каждого состояния) и счетчик (счетчик того, как долго я нахожусь в состоянии), который я, вероятно, должен использовать в качестве драйверов в тестовом стенде. Любой вклад приветствуется

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;



entity FPGA_tb is
--  Port ( );
end FPGA_tb;

architecture Behavioral of FPGA_tb is

component FPGA_Challenge is
    Port( led : out STD_LOGIC;
        clk_in : in STD_LOGIC;  -- 100 MHZ internal clock 
        reset : in STD_LOGIC;  -- is reset necessary 
        button : in STD_LOGIC;
        data_line : in STD_LOGIC);

end component; 

    signal led : STD_LOGIC;
    signal clk_in :  STD_LOGIC;  -- 100 MHZ internal clock 
    signal reset :  STD_LOGIC;  -- is reset necessary 
    signal button :  STD_LOGIC;
    signal data_line :  STD_LOGIC;

    type state_type is (s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20);

    signal state: state_type;

    signal  x,y: std_logic; 

    signal count : integer:= 0; 


begin

UUT: FPGA_Challenge
      PORT MAP(
              led => led,
              clk_in => clk_in,
              reset => reset, 
              button => button,
              data_line => data_line 
              );

Testing: Process
begin

--wait until rising_edge(clk_in);
--wait until rising_edge(clk_in);

clk_in <='0';
reset <= '1';
button <= '0';
data_line <= '0';
WAIT For 10ns;

clk_in <='1';
reset <= '0';
button <= '1';
data_line <= '0';
WAIT For 10ns;

clk_in <='1';
reset <= '1';
button <= '0';
data_line <= '1';
WAIT For 10ns;

clk_in <='0';
reset <= '1';
button <= '0';
data_line <= '0';
WAIT For 10ns;

clk_in <='1';
reset <= '1';
button <= '0';
data_line <= '0';
WAIT For 10ns;

end process;
end Behavioral;

1 Ответ

0 голосов
/ 25 февраля 2020

Попробуйте в тестовом стенде запустить часы и выполнить правильный сброс

signal clk_in :  STD_LOGIC := '1';  -- 100 MHZ internal clock 
signal reset :  STD_LOGIC := '1';  -- is reset necessary  

clk_in <=NOT clk_in after 10ns;
reset <= 0 after 30ns;

играть с кнопкой после сброса. то есть от 40 нс

...