Compare 三电平比较器

Compare 三电平比较器,compare,vhdl,Compare,Vhdl,我想做一个有一定公差的比较器 我已经计算了两个信号之间的差异(希望如此) 现在我想比较一个数字(稍后再决定),分别转发相等notequal和可接受的信号 我让评论部分帮助您理解我的方法 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; use ieee.std_logic_unsigned.all; entity threelvlcomp is port ( input1 :

我想做一个有一定公差的比较器

我已经计算了两个信号之间的差异(希望如此) 现在我想比较一个数字(稍后再决定),分别转发相等notequal和可接受的信号

我让评论部分帮助您理解我的方法

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;

entity threelvlcomp is
    port ( 
        input1    : in  std_logic_vector(15 downto 0);
        input2    : in  std_logic_vector(15 downto 0);
        outputeq  : out std_logic;
        outputneq : out std_logic
    );
end threelvlcomp;

architecture Behavioral of threelvlcomp is

signal temp : std_logic_vector(15 downto 0);
signal dif  : std_logic_vector(15 downto 0);
--CONSTANT limit      : INTEGER := 1;

begin

  dif <= std_logic_vector(unsigned(input1)) + std_logic_vector(unsigned(not(input2) + 1));
  --dif <= input1 + not(input2)+ "1";
  --dif <= input1 + not(input2) + "1"; 

    outputeq <= '1' when dif < '1'  else
            '0';
        outputneq <= '1' when dif > '1' else
            '0';


-- IF dif = "0000" THEN
-- outputeq   <= '1';
-- outputneq  <= '0';
-- outputacc  <= '0';
--ELSE IF dif /= '0' THEN
-- outputeq   <= '0';
-- outputneq  <= '1';
--outputacc  <= '0';
--ELSE IF dif <= "0.5"; 
-- outputeq   <= '0';
-- outputneq  <= '0';
-- outputacc  <= '1';
--ELSE
-- outputeq   <= '1';
-- outputneq  <= '1';
-- outputacc  <= '1';
--END IF; 

--  If(dif = 0) then outputeq <='1'; else outputeq <= '0';end if;
--  If(dif >= -0.5 and dif <= 0.5) then outputacc <='1'; else outputacc <= '0';end if;
--  If(dif /= 0) then outputneq <='1' else outputneq <= '0';end if;

end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用ieee.numeric_std.all;
使用ieee.std_logic_unsigned.all;
实体3LVLCOMP是
港口(
输入1:标准逻辑向量(15到0);
输入2:标准逻辑向量(15到0);
outputeq:输出标准逻辑;
输出NEQ:输出标准逻辑
);
结束三次LVLCOMP;
三层LVLCOMP的体系结构是
信号温度:标准逻辑向量(15至0);
信号dif:标准逻辑向量(15到0);
--常量限制:整数:=1;
开始

dif我还没有测试这个代码。但在我看来,这就是你想要做的。它至少可以帮助您解决已签名/未签名问题

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
--use ieee.std_logic_unsigned.all; --do not use this it is confusing you

entity threelvlcomp is
    port ( 
        input1    : in  std_logic_vector(15 downto 0);
        input2    : in  std_logic_vector(15 downto 0);
        outputeq  : out std_logic;
        outputneq : out std_logic
    );
end threelvlcomp;

architecture Behavioral of threelvlcomp is

signal temp : unsigned(15 downto 0);
signal dif  : signed(16 downto 0);
--CONSTANT limit      : INTEGER := 1;

begin

-- you want a signed number here so we need to signed extend with a zero
  dif <= (signed('0'input1)) + (not signed('0'&input2)) + 1; 
  --dif <= input1 + not(input2)+ "1";
  --dif <= input1 + not(input2) + "1"; 

    outputeq <= '1' when dif < 1  else
            '0';
        outputneq <= '1' when dif > 1 else
            '0';
end Behavioral;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用ieee.numeric_std.all;
--使用ieee.std_logic_unsigned.all--不要用这个,它会把你弄糊涂
实体3LVLCOMP是
港口(
输入1:标准逻辑向量(15到0);
输入2:标准逻辑向量(15到0);
outputeq:输出标准逻辑;
输出NEQ:输出标准逻辑
);
结束三次LVLCOMP;
三层LVLCOMP的体系结构是
信号温度:无符号(15至0);
信号dif:有符号(16至0);
--常量限制:整数:=1;
开始
--你想要一个有符号的数字,所以我们需要一个有符号的零扩展

dif您指的是什么错误?唯一能立即跳出来的是,您正在混合带有冲突的unsigned声明的包—Synopsys包std_logic_unsigned将引用Synopsys包std_logic_arith和IEEE包numeric_std中的unsigned。理顺您的use子句,在最坏的情况下,您必须更改“”运算符(假设为-2008,只使用包数字\u std\u unsigned)。不清楚为什么不使用相等运算符(“=”),你的问题是什么?预期的结果是什么?请用一个数学公式来指定它。你确定吗<可以使用相等运算符(
=
)确定code>outputeq
。然后,
outputneq
就是
outputeq
的反数值。不,你的权利,我不确定。。。要知道用户想要什么有点困难。但按照我的解释,它将成为一个2级/3状态的比较器。另一种方法是普通的比较器(1级/2状态)。我现在看到,对于1的差异,您的设计输出
outputeq='0'
以及
outputeq='0'
。好的,这将是第三种状态。你应该在你的回答中指出这一点,因为它很容易被监督。