2014-09-04 36 views
0

如何在赋值中使用无符号文字?VHDL中的无符号文字

看看这个例子:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use ieee.numeric_std.all; 

entity myTest is 
    Port (clk : in STD_LOGIC); 
end myTest; 

architecture Behavioral of myTest is 

    signal testSignal : unsigned (31 downto 0); 

begin 
    process (clk) is 
    begin 
     if (rising_edge (clk)) then 

      -- this compiles fine: 
      testSignal <= testSignal + 1; 

      -- this causes an error. Why? 
      testSignal <= 1; 

     end if; 
    end process; 
end Behavioral; 

行:

  testSignal <= 1; 

导致在赛灵思ISE以下错误信息:

Line 22. Type of testSignal is incompatible with type of 1.

谁能解释为什么以及如何解决这个问题?

回答

2

对于unsignedinteger+运营商ieee.numeric_std超载,这就是第一条线路工作的原因;但是,赋值不是(也不是),并且由于1是一个整数字面值,所以不能将其直接赋值给unsigned(它是一个向量)。它必须先转换。标准方法是:

testSignal <= to_unsigned(1, testSignal'length); 

to_unsigned()需要两个参数:一个natural来转换,以及矢量长度转换到。

+0

谢谢。现在有道理。 – 2014-09-04 19:12:13

+2

除了fru1tbat的回答之外,还可以使用像这样的二进制或十六进制值的直接向量分配,例如'testSignal <= x“00023AD5”;或者将每个位设置为零,如'testSignal <= (others =>'0');你应该添加一个初始化值到你的计数器的信号声明:) – Paebbels 2014-09-05 08:15:14