在ModelSim模拟器中没有来自实体的输出 - VHDL

时间:2017-03-17 22:47:21

标签: vhdl modelsim

我在VHDL中编写了一个简单的实体来使LED闪烁并尝试在ModelSim中模拟它,但输出没有转换。

以下是LED_Blink实体的HDL文件:

Library IEEE;
use IEEE.Std_logic_1164.all;

entity LED_Blink is

generic (
    g_SYSTEM_CLOCK_PERIOD   : in time := 10 ns; -- 100 MHz clock period
    g_LED_ON_TIME           : in time := 1 sec
);

port(
    system_clock    : in Std_logic; 
    reset_fpga_L    : in Std_logic;

    led_out         : out Std_logic
);
end entity LED_Blink;

architecture RTL of LED_Blink is
    signal led_state : Std_logic;
    constant COUNTER_RELOAD_VAL : natural := g_LED_ON_TIME/g_SYSTEM_CLOCK_PERIOD;
begin
    process(reset_fpga_L, system_clock)
        variable counter : natural range 0 to COUNTER_RELOAD_VAL := COUNTER_RELOAD_VAL;
    begin
        if reset_fpga_L = '0' then
            counter := COUNTER_RELOAD_VAL;
            led_state <= '0';
        elsif rising_edge(system_clock) then
            if counter = 0 then
                led_state <= not led_state;
                counter := COUNTER_RELOAD_VAL;
            else
                counter := counter - 1;
            end if;            
        end if;

        led_out <= led_state;
    end process;
end architecture RTL;

这是我的测试平台:

Library IEEE;
use IEEE.Std_logic_1164.all;

entity LED_Blink_TB is
end entity LED_Blink_TB;

architecture RTL of LED_Blink_TB is

    signal reset_fpga_L : Std_logic := '0';
    signal system_clock : Std_logic := '0';

    signal led_out      : Std_logic := '0';

begin

    G1: entity work.LED_Blink(RTL) port map(reset_fpga_L, system_clock, led_out);

    CLK: process
    begin
        while now <= 5 sec loop
            system_clock <= not system_clock;
            wait for 5 ns;
        end loop;
        wait;
    end process CLK;

    STIM: process
    begin
        reset_fpga_L <= '0';
        wait for 100 ns;
        reset_fpga_L <= '1';
        wait for 4 sec;
        reset_fpga_L <= '0';
        wait for 50 ns;
        reset_fpga_L <= '1';
        wait;
    end process STIM;

end architecture RTL;

我无法弄清楚为什么当我在模拟器中运行我的测试平台时,led_out上没有看到任何转换。我已注意将system_clockreset_fpga_Lled_out的wave添加到跟踪视图中。您是否在我的代码中看到任何可能存在问题的内容?谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

可以使用第二种形式的测试平台,因为生成LED_Blink的输入取决于作为泛型提供的值:

library ieee;
use ieee.std_logic_1164.all;

entity led_blink_tb is
end entity;

architecture foo of led_blink_tb is
    constant CLK_PERIOD:    time := 100 ms;
    constant LED_ON:        time := 500 ms;
    signal clk:             std_logic := '0';
    signal reset_n:         std_logic;
    signal led:             std_logic;
begin
DUT:
    entity work.led_blink
        generic map ( CLK_PERIOD, LED_ON)
        port map (
            system_clock => clk,
            reset_fpga_l => reset_n,
            led_out => led
        );
CLOCK:
    process
    begin
        wait for CLK_PERIOD/2;
        clk <= not clk;
        if now > 2.5 sec then
            wait;
        end if;
    end process;
STIMULI:
    process
    begin
        reset_n <= '0';
        wait for CLK_PERIOD * 2;
        reset_n <= '1';
        wait;
    end process;
end architecture;

这个想法,测试平台和模型都依赖于作为泛型提供的常量,因此更改参数需要的工作量更少。

另请注意,端口映射中的关联列表使用命名关联。

如果我们看看原始的testbench端口映射:

G1: entity work.LED_Blink(RTL) port map(reset_fpga_L, system_clock, led_out);

我们看到与正式system_clock的第一个位置关联与实际的reset_fpga_L相关联,而表示正式reset_fpga_L的第二个位置关联与实际的system_clock相关联。

两个实际关联的顺序相反。