vhdl 中的 4 位比较器问题

时间:2021-04-28 13:08:15

标签: vhdl hardware comparator xilinx xilinx-ise

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

1 个答案:

答案 0 :(得分:0)

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

注意,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;
相关问题