【问题标题】:4-bit comparator issue in vhdlvhdl 中的 4 位比较器问题
【发布时间】:2021-04-28 13:08:15
【问题描述】:

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

我的模拟看起来像这样:

【问题讨论】:

    标签: vhdl hardware comparator xilinx xilinx-ise


    【解决方案1】:

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

    注意,wait; 无限停止进程(仅在模拟中,无法合成)。

    解决方案一:

    使用进程的敏感度列表,删除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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多