2012-10-01 16 views
1

我想比較兩個變量:在此VHDL代碼中,什麼原因導致「數據類型未針對運算符'COMPARE'」實現?

variable E1, E2 : unsigned(5 downto 0); 

有:

if (E1 < E2) then 
lt_val := '1'; 
end if; 

但錯誤出現,當我嘗試編譯。

我不知道我在做什麼錯。

編輯:這是完整的文件,我改變了unsigned回到std_logic_vector並使用numeric_std庫。

library IEEE; 
use IEEE.std_logic_1164.all; 
use IEEE.numeric_std.all; 

entity FPA is 
    port (clk, st : in std_logic; 
      d1  : in std_logic_vector(15 downto 0); 
      d2  : in std_logic_vector(15 downto 0); 
      sum  : out std_logic_vector(15 downto 0); 
      rdy  : out std_logic); 

end FPA; 

architecture behav of FPA is 

    type state is (s0, s1, s2, s3, s4, s5, s6, s7); 
    signal new_state : state; 
    signal norm  : std_logic; 
    signal lt, gt : std_logic; 

begin 

    process is 
     variable curr_state : state := s7; 
    begin 
     if clk = '1' then 
      case curr_state is 
       when s0 => 
        if st = '1' then curr_state := s1; 
        end if; 
       when s1 => 
        curr_state := s2; 
       when s2 => 
        if gt = '1' then curr_state := s4; 
        end if; 
        if lt = '1' then curr_state := s3; 
        end if; 
        if not((lt = '1') or (gt = '1')) then 
         curr_state := s5; 
        end if; 
       when s3 => 
        curr_state := s1; 
       when s4 => 
        curr_state := s1; 
       when s5 => 
        if norm = '1' then 
         curr_state := s6; 
        else 
         curr_state := s7; 
        end if; 
       when s6 => 
        curr_state := s7; 
       when s7 => 
        if st = '0' then curr_state := s0; 
        end if; 
      end case; 
      new_state <= curr_state; 
     end if; 
     new_state <= curr_state; 
     wait on clk; 
    end process; 

    process is 
     variable E1    : std_logic_vector(5 downto 0); 
     variable E2    : std_logic_vector(5 downto 0); 
     variable sum_val   : std_logic_vector(15 downto 0); 
     variable X, Y    : std_logic_vector(11 downto 0); 
     variable SGR    : std_logic_vector(11 downto 0); 
     variable rdy_val, norm_val : std_logic; 
     variable gt_val, lt_val : std_logic; 
    begin 

     -- defaults 

     rdy_val := '0'; 
     case new_state is 

      when s0 => 
       sum_val := "ZZZZZZZZZZZZZZZZ"; 
       E1  := d1(15 downto 10); 
       X  := "01" & d1(9 downto 0); 
       E2  := d2(15 downto 10); 
       Y  := "01" & d2(9 downto 0); 
      when s1 => 
       if (E1 < E2) then 
        lt_val := '1'; 
       end if; 
       if (E1 > E2) then 
        gt_val := '1'; 
       end if; 
       SGR := X + Y; 
      when s2 => 
       if SGR(11) = '1' then 
        norm_val := '1'; 
       end if; 
      when s3 => 
       X := X ror 1; 
       E1 := E1 + "000001"; 
      when s4 => 
       Y := Y ror 1; 
       E2 := E2 + "000001"; 
      when s5 => 
      when s6 => 
       SGR := SGR ror 1; 
       E2 := E2 + "000001"; 
      when s7 => 
       sum_val := E2 & SGR(9 downto 0); 
       rdy_val := '1'; 
     end case; 

     rdy <= rdy_val; 
     lt <= lt_val; 
     gt <= gt_val; 
     sum <= sum_val; 
     norm <= norm_val; 

     wait on new_state; 
    end process; 

end behav; 
+2

可以包含的代碼較寬的部分?例如包含您的代碼的函數或過程和包或架構。你還可以添加你的'library'和'use'子句嗎?請再提一下你的編譯器。 – wap26

+0

lt_val的聲明在哪裏? – FarhadA

+0

我添加了完整的文件 – ryanm

回答

1

除非使用非標準包,否則不會爲std_logic_vector定義比較運算符。我不知道看上去就像你做你所提到的更改之前的代碼,但是代碼,現在你應該可以通過改變線

if (E1<E2) then 

解決這個問題,以

if (unsigned(E1) < unsigned(E2)) then 

請注意,「+」運算符也未針對std_logic_vector定義,因此無論何時對它們進行算術運算,您都必須在無符號和std_logic_vector之間來回轉換E1和E2。在你的情況下,最好將E1和E2定義爲unsigned而不是std_logic_vector,只要你使用numeric_std包並且不要使用IEEE庫中的其他非標準包,這應該可以正常工作。 (如std_logic_unsigned)

+0

我試圖將所有向量轉換爲無符號,並使用std_logic_arith而不是numeric_std,但是我得到相同的錯誤。我也嘗試了你提到的方式,並獲得相同的錯誤。 – ryanm

+0

std_logic_arith包是一個非標準包,應該在新設計中避免。我不知道爲什麼它不能與std_logic_arith一起工作,但numeric_std包也定義了帶有諸如「>」和「+」之類操作的無符號數據類型。 – pc3e

1

聲明E1E2unsigned是正確的選擇,但還不夠。

您需要聲明其他幾個變量unsigned,動態轉換輸入從std_logic_vectorunsigned和dynmically轉換您的變量sum_valstd_logic_vector分配輸出sum

修補以下線條看起來OK(至少它在編譯的ModelSim):

variable E1    : unsigned(5 downto 0); 
    variable E2    : unsigned(5 downto 0); 
    variable sum_val   : unsigned(15 downto 0); 
    variable X, Y    : unsigned(11 downto 0); 
    variable SGR    : unsigned(11 downto 0); 
    -- ... 
    E1  := unsigned(d1(15 downto 10)); 
    X  := unsigned("01" & d1(9 downto 0)); 
    E2  := unsigned(d2(15 downto 10)); 
    Y  := unsigned("01" & d2(9 downto 0)); 
    -- ... 
    sum <= std_logic_vector(sum_val); 
+0

我得到同樣的錯誤 – ryanm

0

更改所有的向量回unsigned(它們所代表的數字畢竟)。

如果仍然無法編譯,你可能有一個有缺陷的編譯器(它在的ModelSim對我來說)

相關問題