vhdl - vhdl 中的 4 位比较器问题
问题描述
我是 VHDL 新手,在编写 4 位比较器时遇到问题。当我想比较不同的输入集时,所有输入都只有一个输出。而且我不知道如何解决这个问题。我只想有一个输出,如果 A 小于 B,则需要显示 0000,如果 A 大于 B,则需要显示 1111,如果它们相等则需要显示 0011。有人可以帮我解决我的问题吗?
这是我的代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity comp_4 is
port ( A:IN STD_LOGIC_VECTOR(3 downto 0);
B:IN STD_LOGIC_VECTOR(3 downto 0);
output:OUT STD_LOGIC_VECTOR(3 downto 0)
);
end comp_4;
architecture dataflow of comp_4 is
begin
process
begin
if (A=B) then
output <= "0011";
elsif (A>B) then
output <= "1111";
else
output <= "0000";
end if;
wait;
end process;
end dataflow;
还有我的测试台:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY Comparator_test IS
END Comparator_test;
ARCHITECTURE Ctest OF Comparator_test IS
COMPONENT comp_4 IS
port( A:IN STD_LOGIC_VECTOR(3 downto 0);
B:IN STD_LOGIC_VECTOR(3 downto 0);
output:OUT STD_LOGIC_VECTOR(3 downto 0)
);
END COMPONENT;
SIGNAL a : STD_LOGIC_VECTOR(3 downto 0);
SIGNAL b : STD_LOGIC_VECTOR(3 downto 0);
SIGNAL c : STD_LOGIC_VECTOR(3 downto 0);
BEGIN
uut : comp_4 PORT MAP(a, b , c);
a <= "0100" , "1111" After 10 NS;
b <= "0101" , "1100" AFTER 10 NS;
END Ctest;
我的模拟看起来像这样:
解决方案
您需要将输入放在敏感度列表中。
注意,wait;
无限停止过程(仅在模拟中,无法合成)。
解决方案1:
使用进程的敏感度列表,并删除wait;
.
architecture dataflow of comp_4 is
begin
process(A, B)
begin
if (A = B) then
output <= "0011";
elsif (A > B) then
output <= "1111";
else
output <= "0000";
end if;
end process;
end dataflow;
解决方案2:
使用 的敏感度列表wait
。
architecture dataflow of comp_4 is
begin
process
begin
if (A = B) then
output <= "0011";
elsif (A > B) then
output <= "1111";
else
output <= "0000";
end if;
wait on A, B;
end process;
end dataflow;
推荐阅读
- java - Java 7 全局问题
- php - 循环中的雄辩关系
- sql-server - sqlsrv_execute 返回游标我无法从我的方法返回
- python - 从 python 中的 Web 服务 URL 下载 XML 文件
- python - Tkinter 菜单显示
- angular-universal - Pm2/forever angular Universal server start throws buffer is deprecated 错误
- c# - 通用存储库中的 Ef 核心多对多关系
- javascript - 渲染中的 VueJS 错误:“TypeError:_vm.img.loadImg 不是函数
- arrays - 只想显示分配的 wordpress 类别
- selenium - 无法使用 Selenium IDE 选择选项