使用测试台模拟的 VHDL 计数器为输出提供 'Uninitialized',这是如何解决的?
VHDL counter simulated using a test bench giving 'Uninitialized' for the output, how is this resolved?
下面是一个计数器,它被设计用来表示一个带有 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 输出递增吗?
编辑:
根据 mkrieger1 的回答,将 btnd 设置为 1,在测试台中等待 1ns 以初始化 LED,在此更改后 LED 输出仍为 U。
count
未在 Lab_3_Source_File
内初始化,直到 btnd
设置为 '1'
,它不在测试平台中。
由于led
输出是由count
驱动的,所以它也是未初始化的。 Lab_3_Source_File
的 led
输出的未初始化值然后分配给测试平台中的 led
信号。
因此,要解决此问题,您需要在测试台中将 btnd
设置为 '1'
一次,持续时间非零,然后再将其设置为 '0'
(否则 led
一直保持在 "00000000"
。
下面是一个计数器,它被设计用来表示一个带有 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 输出递增吗?
编辑:
根据 mkrieger1 的回答,将 btnd 设置为 1,在测试台中等待 1ns 以初始化 LED,在此更改后 LED 输出仍为 U。
count
未在 Lab_3_Source_File
内初始化,直到 btnd
设置为 '1'
,它不在测试平台中。
由于led
输出是由count
驱动的,所以它也是未初始化的。 Lab_3_Source_File
的 led
输出的未初始化值然后分配给测试平台中的 led
信号。
因此,要解决此问题,您需要在测试台中将 btnd
设置为 '1'
一次,持续时间非零,然后再将其设置为 '0'
(否则 led
一直保持在 "00000000"
。