Vhdl 如何将不同的信号分配给单个整数值?
我正在为全加器编写VHDL测试平台 在模拟中,我尝试了这个方法并得到了正确的结果Vhdl 如何将不同的信号分配给单个整数值?,vhdl,Vhdl,我正在为全加器编写VHDL测试平台 在模拟中,我尝试了这个方法并得到了正确的结果 begin A <= '0'; B <= '0'; C <= '0'; wait for 10 ns; A <= '0'; B <= '0'; C <= '1'; w
begin
A <= '0';
B <= '0';
C <= '0';
wait for 10 ns;
A <= '0';
B <= '0';
C <= '1';
wait for 10 ns;
A <= '0';
B <= '1';
C <= '0';
wait for 10 ns;
A <= '0';
B <= '1';
C <= '1';
wait for 10 ns;
A <= '1';
B <= '0';
C <= '0';
wait for 10 ns;
A <= '1';
B <= '0';
C <= '1';
wait for 10 ns;
A <= '1';
B <= '1';
C <= '0';
wait for 10 ns;
A <= '1';
B <= '1';
C <= '1';
wait for 10 ns;
wait;
end process;
开始
A您可以尝试以下方法:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; -- To use integer and unsigned
...
signal stimuli : std_logic_vector(2 downto 0); -- Equivalent of A, B, C
...
inst_full_adder : full_adder
port map
(
i_a => stimuli(0),
i_b => stimuli(1),
i_carry => stimuli(2),
...
);
...
for i in 0 to 7 loop
stimuli <= std_logic_vector(to_unsigned(i,3)); -- Conversion of your integer in std_logic_vector (3 is the size of your vector)
wait for 10 ns;
end loop;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;——使用整数和无符号
...
信号刺激:标准逻辑向量(2到0);--A、B、C的等价物
...
指令全加器:全加器
港口地图
(
i_a=>刺激(0),
i_b=>刺激(1),
i_carry=>刺激(2),
...
);
...
对于0到7循环中的i
刺激可以-VHDL 2008允许聚合分配
use ieee.numeric_std_unsigned.all;
for i in 0 to 7 loop
(A,B,C) <= to_slv(i, 3);
wait for 10 ns;
end loop;
使用ieee.numeric\u std\u unsigned.all;
对于0到7循环中的i
(A,B,C)这项工作在Vivado 2018.1的VHDL93下进行:
loop1: for i in 0 to 7 loop
(a,b,c) <= std_logic_vector(to_unsigned(i,3));
wait for 10ns;
end loop;
这是测试台:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library work;
entity test_tb is
end entity;
architecture Behavioral of test_tb is
signal clk : std_logic;
signal a : std_logic;
signal b : std_logic;
signal c : std_logic;
begin
clkpr : process
begin
clk <='1';
wait for 10ns;
clk <= '0';
wait for 10ns;
end process;
test_pr : process
begin
loop: for i in 0 to 7 loop
(a,b,c) <= std_logic_vector(to_unsigned(i,3));
wait for 10ns;
end loop;
wait;
end process;
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.NUMERIC_STD.ALL;
图书馆工作;
实体测试是
终端实体;
test_tb的体系结构是
信号时钟:标准逻辑;
信号a:std_逻辑;
信号b:标准逻辑;
信号c:标准逻辑;
开始
clkpr:进程
开始
clk numeric_std_unsigned是一个2008库。还有,(A,B,C)是的,我发现多亏了你,我也发布了这个答案,这样想使用VHDL 93的人就可以了。我从未使用过numeric\u std\u unsigned
,也很少看到这个库被使用(但我几乎没有经验)。我已经写了一篇关于库的帖子:也许你可以和我们分享为什么我们应该使用numeric\u std\u unsigned?(a,B,C)前面的两条评论是不准确的。此答案适用于1987年至2008年修订版,使用总分配目标。参见IEEE标准1076-1987 7.3.2汇总,8.3信号分配声明。除了先前支持的元素类型选择(此处a、b、c与std_logic_vector的元素类型兼容)之外,-2008还向聚合添加了聚合类型的选择(在位置或命名关联中)(此处为上下文中的std_logic_vector,表示一系列元素的选择)-1987年至-2002年也允许分配到集合。IEEE Std 1076-2008 9,3.3.2 Array aggregates(第3段)“对于具有离散范围和聚合类型表达式的选择的元素关联,表达式值的每个元素是范围内匹配索引值处聚合元素的值……”,此处不需要。a、 b和c是元素类型,聚合与早期版本兼容。另请参见“VHDL-2008只是新东西”,Ashensen,Lewis,6.4第2段中的章节介绍了-2008变更,无需比较不同修订文本或分析语言变更规范。该问题的标题未正确反映问题。您正在分配不同的信号,而不是整数值。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library work;
entity test_tb is
end entity;
architecture Behavioral of test_tb is
signal clk : std_logic;
signal a : std_logic;
signal b : std_logic;
signal c : std_logic;
begin
clkpr : process
begin
clk <='1';
wait for 10ns;
clk <= '0';
wait for 10ns;
end process;
test_pr : process
begin
loop: for i in 0 to 7 loop
(a,b,c) <= std_logic_vector(to_unsigned(i,3));
wait for 10ns;
end loop;
wait;
end process;
end Behavioral;