2011-01-09 50 views
2

我用VHDL編寫了一個算法,但是我有這個消息,我不明白「sra/sla在這種情況下不能有這樣的操作數。」請幫忙嗎?SRA不能有這樣的操作數?

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all; 
use ieee.std_logic_arith.conv_std_logic_vector; 

entity hsl2rgb is 
    generic(
     constant hue : integer := 85; 
     constant sat : integer := 127 
    ); 
    port(
     lum : in std_logic_vector(7 downto 0); 
     ored : out std_logic_vector(5 downto 0); 
     ogreen : out std_logic_vector(5 downto 0); 
     oblue : out std_logic_vector(5 downto 0) 
    ); 
end entity; 

architecture behavioral of hsl2rgb is 
begin 

    process(lum) 
     variable v : integer; 
     variable m : integer; 
     variable sextant : integer; 
     variable fract : integer; 
     variable vsf : integer; 
     variable mid1 : integer; 
     variable mid2 : integer; 
     variable lumx : integer; 
    begin 
     lumx := to_integer(unsigned(lum)); 
     if (lumx < 127) then 
      v := (lumx * (256 + sat)) sra 8; 
     else 
      v := (((lumx + sat) sla 8) - lumx * sat) sla 8; 
     end if; 

     if (v <= 0) then 
      ored <= (others => '0'); 
      ogreen <= (others => '0'); 
      oblue <= (others => '0'); 
     else 
      m := (2 * lumx) - v; 
      sextant := (hue * 6) sra 8; 
      fract := (hue * 6) - (sextant sla 8); 
      vsf := (fract * (v - m)) sra 8; 
      mid1 := m + vsf; 
      mid2 := v - vsf; 

      case sextant is 
       when 0 => 
        ored <= conv_std_logic_vector(v, 6); 
        ogreen <= conv_std_logic_vector(mid1, 6); 
        oblue <= conv_std_logic_vector(m, 6); 
       when 1 => 
        ored <= conv_std_logic_vector(mid2, 6); 
        ogreen <= conv_std_logic_vector(v, 6); 
        oblue <= conv_std_logic_vector(m, 6); 
       when 2 => 
        ored <= conv_std_logic_vector(m, 6); 
        ogreen <= conv_std_logic_vector(v, 6); 
        oblue <= conv_std_logic_vector(mid1, 6); 
       when 3 => 
        ored <= conv_std_logic_vector(m, 6); 
        ogreen <= conv_std_logic_vector(mid2, 6); 
        oblue <= conv_std_logic_vector(v, 6); 
       when 4 => 
        ored <= conv_std_logic_vector(mid1, 6); 
        ogreen <= conv_std_logic_vector(m, 6); 
        oblue <= conv_std_logic_vector(v, 6); 
       when 5 => 
        ored <= conv_std_logic_vector(v, 6); 
        ogreen <= conv_std_logic_vector(m, 6); 
        oblue <= conv_std_logic_vector(mid2, 6); 
       when others => 
        ored <= (others => '0'); 
        ogreen <= (others => '0'); 
        oblue <= (others => '0'); 
      end case; 
     end if; 
    end process; 
end architecture; 

回答

2

對於整數,您必須使用*/運算符。如果他們在正確的位置(即在分界的右邊,乘法的任一側)具有恆定的2的權力,合成器將「做正確的事情」。或(如Charles指出的)使用來自ieee.numeric_std librarysignedunsigned類型。

順便說一句,你爲什麼使用conv_std_logic_vector當你使用ieee.numeric_std

ored <= std_logic_vector(to_unsigned(mid1, 6)); 

應該是您所需要的,那麼你就可以擺脫討厭的ieee.std_logic_arith

(旁白:如果你(或者這是一個未來的讀者)瞄準的FPGA(我接受你可能現在不是很多人,你可能會發現,如果目標頻率具有挑戰性,就有必要將這種體系結構進行一些處理,在短暫的眼球綜合中,有6個以上的加法器,一個幾個實數乘法器和幾個多路複用器 - 全都在一個時鐘週期內,尤其是這會阻止在我所知的所有FPGA中使用硬乘法器)

+0

更具體地說,您可以使用(x * 8)而不是(x sll 3)。 – Philippe 2011-01-13 07:36:29

1

問題是你已經將您std_logic_vector I/O爲整數來進行運算,但SRA/SRL操作數只對bit或boolean類型的一維數組工作。嘗試使用帶符號或無符號類型(這是數字的位向量表示)而不是混合std_logic_vectors(沒有固有數值)和整數(沒有位向量表示),您可能會有更好的運氣。