2013-04-14 38 views
1

我在使用2位greater than Comparator和2位equality Comparator創建4位比較器時遇到麻煩。比比較使用2位Comperator的VHDL 4位Comperator

更大

entity bit2com is     
    Port (a,b: in STD_LOGIC_vector(1 downto 0); 
      y : out STD_LOGIC); 
end bit2com; 

architecture Behavioral of bit2com is 

signal p0,p1,p2:std_logic; 

begin 

p0 <= a(1) and not b(1); 
p1 <= a(0) and a(1) and not b(0); 
p2<=a(0) and not b(0) and not b(1); 
y <= p0 or p1 or p2; 

end Behavioral; 

平等比較

entity comaeqb is 

    Port (a,b: in STD_LOGIC_vector(1 downto 0); 
      y : out STD_LOGIC); 
end comaeqb; 

architecture Behavioral of comaeqb is 

signal p0,p1,p2,p3:std_logic; 
begin 

p0 <= a(0) and a(1) and b(0) and b(1); 
p1 <= a(0) and not a(1) and b(0) and not b(1); 

p2<=not a(0) and not a(1) and not b(0) and not b(1); 
p3<=not a(0) and a(1) and not b(0) and b(1); 
y <= p0 or p1 or p2 or p3; 

我如何可以用它來做出比比較大的4位?

+1

將A,B聲明爲numeric_std。[un] signed,並在A> B else'0'時寫入'Y <='1';' –

回答

0

正如我所看到的,您試圖從2位比較器(>=)創建4位比較器。但我認爲有兩個答案,你的問題:

  1. 如果你只是想沒有任何比較(獨立的),請聲明A and B作爲signedunsigned比較創建4位比較(你可以轉換到這種類型如果你使用std_logic_vector)。有兩個庫可供使用:arithnumeric_std(只使用其中之一,兩者都被違反)。
  2. 如果您必須使用2位比較器。使用這種方式:

建議A = [A3 A2 A1 A0]B = [B3 B2 B1 B0]。運行兩個步驟:

步驟1比較兩個MSB與你的比較:

if [A3 A2] > [B3 B2] then 
    A_greater_than_B <= '1'; 
elsif [A3 A2] < [B3 B2] then 
    A_greater_than_B <= '0'; 
else -- [A3 A2] = [B3 B2] 
-- next step >>> 
end if; 

步驟2比較兩個LSB與你的比較器,具有類似的方法與步驟1。此分支發生在[A3 A2] =[ B3 B2]步驟2的結果是4位比較器的結果。例如,如果[A1 A0] = [B1 B0]則是A = B

+0

thanx非常多! – user2280448