VHDL中的状态机 - 未知(无法识别)的输出值

时间:2016-02-09 14:55:11

标签: vhdl

我是VHDL编码的初学者,我的简单状态机有问题。我只是希望这台机器在状态改变时改变输出值loc_RL。当我模拟时,loc_RL没有任何价值(例如' U')。

这是我的代码:

library ieee;
use ieee.std_logic_1164.all;

entity RL is
    port (clk, reset, pon_RL, rtl_RL, ACDS_RL, LADS_RL, REN_RL, LLO_RL, MLA_RL, GTL_RL : in std_logic;
                                     loc_RL : out std_logic);
    end RL;

architecture behavioral of RL is

    type STATE_TYPE is (LOCS, REMS, LWLS, RWLS);
    signal state : STATE_TYPE;

begin
    process(clk, reset)
            begin
                if reset='1' then
                 state <= LOCS;
                elsif (rising_edge(clk)) then
                    case state is
                        when LOCS =>
                            if pon_RL = '1' then
                                state <= REMS;
                            else
                                state <= LOCS;
                            end if;
                        when REMS =>
                            if pon_RL = '1' then
                                state <= LWLS;
                            else
                                state <= REMS;
                            end if;
                        when LWLS =>
                            if pon_RL = '1' then
                                state <= RWLS;
                            else
                                state <= LWLS;
                            end if;
                        when RWLS =>
                            if pon_RL = '1' then
                                state <= LOCS;
                            else
                                state <= RWLS;
                            end if;
                    end case;
                end if;
    end process;


    process(state)
            begin
                case state is
                    when LOCS =>
                        loc_RL <= '1';
                    when REMS =>
                        loc_RL <= '0';
                    when LWLS =>
                        loc_RL <= '1';
                    when RWLS =>
                        loc_RL <= '0';
                end case;
    end process;

end behavioral;

测试平台:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity RL_tb is
end RL_tb;

architecture testbench of RL_tb is
    component RL
    port (clk, reset, pon_RL, rtl_RL, ACDS_RL, LADS_RL, REN_RL, LLO_RL, MLA_RL, GTL_RL : in std_logic;
                                     loc_RL : out std_logic);
    end component;

    --wejscia
    signal tclk : std_logic;
    signal treset: std_logic;
    signal tpon_RL : std_logic;
    signal trtl_RL : std_logic;
    signal tACDS_RL : std_logic;
    signal tLADS_RL : std_logic;
    signal tREN_RL : std_logic;
    signal tLLO_RL : std_logic;
    signal tMLA_RL : std_logic;
    signal tGTL_RL : std_logic;

    --wyjscia
    signal loc_RL : std_logic;

    --definicja zegara
    constant clk_period : time := 40 ns;

begin
    --inicjalizacja UUT

    uut: RL port map (
                tclk,
                treset,
                tpon_RL,
                trtl_RL,
                tACDS_RL,
                tLADS_RL,
                tREN_RL,
                tLLO_RL,
                tMLA_RL,
                tGTL_RL
            );


    process
    begin
        tclk <= '0';
        wait for clk_period/2;
        tclk <= '1';
        wait for clk_period/2;
    end process;

    process
    begin
        treset <= '1';
        wait for 10 ns;
        treset <= '0';
        tpon_RL <= '1';


    end process;

end;

正在编译,我可以进行模拟。我正在使用Cadence的NCLaunch。在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

分析,详细说明和模拟您的设计和测试平台给出了:

rl_tb.png

看着测试平台显示:

architecture testbench of RL_tb is
    component RL
        port (
            clk,
            reset,
            pon_RL,
            rtl_RL,
            ACDS_RL,
            LADS_RL,
            REN_RL,
            LLO_RL,
            MLA_RL,
            GTL_RL:     in  std_logic;
            loc_RL:     out std_logic
        );
    end component;

    --wejscia
    signal tclk:        std_logic;
    signal treset:      std_logic;
    signal tpon_RL:     std_logic;
    signal trtl_RL:     std_logic;
    signal tACDS_RL:    std_logic;
    signal tLADS_RL:    std_logic;
    signal tREN_RL:     std_logic;
    signal tLLO_RL:     std_logic;
    signal tMLA_RL:     std_logic;
    signal tGTL_RL:     std_logic;
    --wyjscia
    signal loc_RL:      std_logic;
    --definicja zegara
    constant clk_period:  time := 40 ns;

begin
    --inicjalizacja UUT
uut: 
    RL 
        port map (
            tclk,
            treset,
            tpon_RL,
            trtl_RL,
            tACDS_RL,
            tLADS_RL,
            tREN_RL,
            tLLO_RL,
            tMLA_RL,
            tGTL_RL
        );

    process
    begin
        tclk <= '0';
        wait for clk_period/2;
        tclk <= '1';
        wait for clk_period/2;
    end process;

    process
    begin
        treset <= '1';
        wait for 10 ns;
        treset <= '0';
        tpon_RL <= '1';
    end process;

end architecture;

否则除了clk,reset和tpon_RL之外,还有哪个分配给被测设备输入的赋值或初始值。

查看RL流程,我们发现LOCS的实际状态分支取决于重置不是&#39; 1&#39;:

    process (clk, reset)
            begin
                if reset = '1' then
                 state <= LOCS;
                elsif (rising_edge(clk)) then
                    case state is
                        when LOCS =>
                            if pon_RL = '1' then
                                state <= REMS;
                            else
                                state <= LOCS;
                            end if;
                        when REMS =>

您的测试平台刺激中缺少的是释放重置。

在未标记的过程中:

    process
    begin
        treset <= '1';
        wait for 10 ns;
        treset <= '0';
        tpon_RL <= '1';
    end process;

你错过了最后的等待声明:

    process
    begin
        treset <= '1';
        wait for 10 ns;
        treset <= '0';
        tpon_RL <= '1';
        wait;            -- added
    end process;

这会阻止您立即将重置分配给&#39; 1&#39;再次。在没有暂停的情况下,一个过程将循环,在将重置设置为“0”后,它只会暂停在一个等待语句中。它会立即将其设置为&#39; 1&#39;在流程暂停之前,重置只会有一个&#39; 1&#39;值。任何过程处于活动状态时都不会更新信号,任何时间内只有一个投影输出波形值,包括当前模拟时间。分配给&#39; 1&#39;将作业改写为&#39; 0&#39;。

修复提供:

rl_tb_fixed.png

现在我们看到状态机处于活动状态。