首页 > 解决方案 > 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;

我的模拟看起来像这样: 在此处输入图像描述

标签: vhdlhardwarecomparatorxilinxxilinx-ise

解决方案


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

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

推荐阅读