问题描述
下面是一个计数器,用于表示带有 8 个 LED 的 8 位二进制数,正在使用测试台对其进行模拟,但是在运行模拟时,输出仅显示 LED 的 UU。
这是我要测试的主要实体:
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_unsigned.all;
entity Lab_3_Source_File is
generic(N_BITS : integer := 8);
port(
btnd : in STD_LOGIC ;
clk : in STD_LOGIC;
led : out STD_LOGIC_VECTOR(7 downto 0)
);
end Lab_3_Source_File;
architecture counter of Lab_3_Source_File is
signal count: STD_LOGIC_VECTOR(7 downto 0);
begin
process(clk,btnd)
begin
if btnd = '1' then
count <= (others => '0');
elsif rising_edge(clk) then
count <= count + 1;
end if;
end process;
led <= count;
end counter;
这是我尝试映射到主要实体的测试台:
use IEEE.STD_LOGIC_1164.ALL;
entity Count_TestBench is
end Count_TestBench;
architecture Behavioral of Count_TestBench is
signal btnd,clk : STD_LOGIC;
signal led : STD_LOGIC_VECTOR(7 downto 0);
begin
UUT : entity work.Lab_3_Source_File port map (btnd => btnd,clk => clk,led => led);
process
begin
btnd<='1';
wait for 1 ns;
btnd<='0';
led<= (others => '0');
for i in 1 to 100 loop
clk<='1';
wait for 10 ns;
clk<='0';
wait for 10 ns;
led<=led;
end loop;
end process;
end Behavioral;
请有人帮助我了解如何启用模拟以显示 LED 输出递增?
编辑:
将 btnd 设置为 1,并在测试台中等待 1ns 以初始化 LED,根据 mkrieger1 的回答,此更改后 LED 输出仍为 U。
解决方法
count
不会在 Lab_3_Source_File
内初始化,直到 btnd
设置为 '1'
,它不在测试平台中。
由于 led
输出由 count
驱动,因此它也未初始化。然后将 led
的 Lab_3_Source_File
输出的未初始化值分配给测试平台中的 led
信号。
因此,要解决此问题,您需要在测试平台中将 btnd
设置为 '1'
一次以保持非零持续时间,然后再次将其设置为 '0'
(否则 {{1} }} 经常在 led
举行)。