2011-01-09 17 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の一定の累乗を持つ場合、シンセサイザーは「正しいことを行います」。

(またはチャールズが書いたように)ieee.numeric_std librarysignedまたはunsignedタイプを使用してください。

ieee.numeric_stdを使用したときに、なぜconv_std_logic_vectorを使用していますか?あなた(またはこれの将来の読者は)FPGAをターゲットにしている(と私はあなたがかもしれ受け入れる場合:

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

はあなたが必要とするものである必要があり、その後、あなたは別に嫌なieee.std_logic_arithライブラリ

(を取り除くことができますそうではありませんが、最近はたくさんの人がいます:)ターゲット周波数が挑戦的であれば、アーキテクチャをパイプライン化する必要があるかもしれません。簡単な眼球合成では、6個以上の加算器、実際の乗算器といくつかのマルチプレクサを1クロックサイクルで実行することができます。特にこれは、私が知っているすべてのFPGAでのハード乗算器の使用を排除します)

+0

具体的には、(x sll 3)の代わりに(x * 8)を使用できます。 – Philippe

1

問題は、あなたが数学を実行するために、整数にあなたのSTD_LOGIC_VECTOR I/Oを変換したが、SRA/SRLのオペランドが唯一のビットまたはブール型の1次元配列上で動作しています。 std_logic_vectors(固有の数値を持たない)と整数(ビットベクトル表現を持たない)を混合するのではなく、符号付きまたは符号なしの型(数字のビットベクトル表現)で作業しようとする方が、

関連する問題