2

VHDL でアルゴリズムをコーディングしましたが、「sra/sla can not have such operands in this context.」というメッセージが表示されます。何か助けてください。

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;
4

2 に答える 2

2

整数では*and/演算子を使用する必要があります。適切な場所 (つまり、除算の右側、乗算の両側) に一定の 2 の累乗がある場合、シンセサイザーは「正しいことを行います」。

または (Charles が指摘したように)のsignedorunsigned型を使用しieee.numeric_std libraryます。

conv_std_logic_vectorところで、使用したのになぜ使用しているのieee.numeric_stdですか?

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

必要なものでなければならない場合は、厄介なieee.std_logic_arithライブラリを取り除くことができます

(余談: あなた (またはこれを将来読む人) が FPGA をターゲットにしている場合 (そうでないかもしれないことは認めますが、最近は多くの人がそうです :) ターゲット周波数が簡単な目玉合成では、半ダース以上の加算器、数個の実際の乗算器、および数個のマルチプレクサがあり、すべて単一のクロック サイクルで使用されます。私が知っているすべてのFPGAの乗算器)

于 2011-01-10T15:37:48.267 に答える
1

問題は、計算を実行するために std_logic_vector I/O を整数に変換したことですが、sra/srl オペランドはビットまたはブール型の 1D 配列でしか機能しません。std_logic_vectors (固有の数値を持たない) と整数 (ビットベクトル表現を持たない) を混在させるよりも、signed または unsigned 型 (数値のビットベクトル表現) を使用する方がうまくいくでしょう。

于 2011-01-10T00:55:40.310 に答える