正如Brian所指出的,对X(和I)的赋值是不正确的。
还有一种情况是,X始终都是X,有两个驱动因素。对X的并发信号分配和未标记过程中的分配。此外,未标记的进程将无法成功初始化X,因为在第一次分配到“0000”和内部while循环中的第一次分配之间没有中断进程。
克服当前测试台中的问题也可能涉及简化:
library ieee;
use ieee.std_logic_1164.all;
entity mux_sche_tb is
end entity mux_sche_tb;
architecture foo of mux_sche_tb is
use ieee.numeric_std.all;
component mux_sche
port (
x3: in std_logic;
x2: in std_logic;
x1: in std_logic;
x0: in std_logic;
i0: in std_logic;
i1: in std_logic;
y: out std_logic
);
end component;
-- signal x3: std_logic := '0';
-- signal x2: std_logic := '0';
-- signal x1: std_logic := '0';
-- signal x0: std_logic := '0';
-- signal i0: std_logic := '0';
-- signal i1: std_logic := '0';
signal y: std_logic;
-- ---------- new variable ----------
signal x: unsigned(3 downto 0);
signal i: unsigned(1 downto 0);
-- signal j: integer := 0;
-- signal k: integer := 0;
begin
-- x <= x3 & x2 & x1 & x0;
-- i <= i1 & i0;
uut:
mux_sche
port map (
x3 => x(3),
x2 => x(2),
x1 => x(1),
x0 => x(0),
i0 => i(0),
i1 => i(1),
y => y
);
tb:
process
begin
-- x <= "0000";
-- i <= "00";
wait for 10 ns; -- show initial state
for j in 0 to 3 loop
I <= to_unsigned(j, 2);
for k in 0 to 15 loop
X <= to_unsigned(k, 4);
wait for 10 ns;
end loop;
end loop;
wait;
-- while(j < 4) loop
-- while(k < 8) loop
-- x <= x + '1';
-- wait for 10 ns;
-- end loop;
-- i <= i + '1';
-- wait for 10 ns;
-- end loop;
end process;
end architecture;
而不是在循环语句中使用迭代方案的while循环。
Brian关于分配X元素的建议扩展到了I,并且只为其中一个元素提供了一个分配,从而消除了多个驱动因素。
for循环迭代器是在循环语句迭代方案中隐式声明的变量,并从其默认类型的整数转换为无符号X和I。
无符号X和I的元素与mux\u sche的std\u逻辑形式端口具有相同的基类型,可以用作实际值(正如Brian建议的那样)。
提供一个
Minimal, Complete and Verifiable example
必须提供兼容的mux\U SCH:
library ieee;
use ieee.std_logic_1164.all;
entity mux_sche is
port (
X3: in std_logic;
X2: in std_logic;
X1: in std_logic;
X0: in std_logic;
I0: in std_logic;
I1: in std_logic;
Y: out std_logic
);
end entity;
architecture foo of mux_sche is
begin
process (X3, X2, X1, X0, I0, I1)
variable I: std_logic_vector (1 downto 0);
begin
I := TO_X01(I1 & I0);
case I is
when "00" =>
Y <= TO_X01(X0);
when "01" =>
Y <= TO_X01(X1);
when "10" =>
Y <= TO_X01(X2);
when "11" =>
Y <= TO_X01(X3);
when others =>
Y <= 'X';
end case;
end process;
end architecture;
在对测试台和测试台进行分析、阐述和模拟之前进行分析时,我们得出以下结论:
X
s和递增的X和I。
此测试台版本依赖于numeric\u std包到自然范围整数的无符号转换,注意X和I的范围在循环迭代方案隐式声明中指定。
可以使用原始测试台吗?没有对j和k进行阈值测试。将发生的是,k将经历8次迭代,然后j将经历4次迭代:
将while循环与信号迭代器结合使用比将for循环与变量迭代器结合使用要困难一些。