2011-01-09 32 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(没有固有数值)和整数(没有位向量表示),您可能会有更好的运气。

相关问题