vhdl 中的 4 位比较器问题 解决方案 1:解决方案 2:

问题描述

我是 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;

我的模拟是这样的:

enter image description here

解决方法

您需要将输入放在敏感度列表中。

注意,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;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...