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;

在Xilinx ISE上导致以下错误消息:

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

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

unsignedintegerieee.numeric_std中的+运算符过载,这就是第一行工作的原因;然而,赋值不是(也不可能是),并且由于1是整数文字,因此它不能直接赋值给unsigned(它是向量);它必须首先转换。标准方法是:

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

to_unsigned()需要两个参数:一个要转换的natural,以及要转换为的向量长度。

最新更新