首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FSM的测试平台

FSM的测试平台
EN

Stack Overflow用户
提问于 2020-02-22 09:54:50
回答 1查看 187关注 0票数 0

我正在尝试为以下用vhdl创建的有限状态机实现一个测试平台。问题是,目前,我在测试工作台中没有看到任何状态转换。模拟将停留在状态0。

代码语言:javascript
运行
复制
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(每个状态的输出)和count(我处于一个状态的时间),我可能应该在测试平台中使用它们作为驱动程序。感谢您提供的任何意见

代码语言:javascript
运行
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2020-02-25 21:21:41

在测试平台中尝试此操作,以获得运行的时钟和适当的重置

代码语言:javascript
运行
复制
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 is开始

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60348332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档