为什么我不能增加这个`std_logic_vector`

Mar*_*rty 12 vhdl

这里发生了什么?为什么我得到'运算符参数类型不匹配',我该怎么做才能修复它?

--
-- 32-bit counter with enable and async reset
--
architecture synthesis1 of counter_32bit is    
signal nextvalue : std_logic_vector ( 31 downto 0 );    
begin

  --
  -- combo
  --
  nextvalue <= value + 1; -- here

  --
  -- sequential
  --
  ff:process( clk, rst )
  begin

    if( rst = '1' ) then
      value <= 0; -- and here...
    elsif( clk'event and ( clk ='1' ) ) then
      if( ena = '1' ) then
         value <= nextvalue;
      end if;
    end if;

  end process ff;    

end synthesis1;
Run Code Online (Sandbox Code Playgroud)

谢谢

dan*_*poe 24

你不能直接增加std_logic,你需要将其转换unsigned为结果并返回std_logic_vector使用numeric_std包.

use ieee.numeric_std.all
...
nextvalue <= std_logic_vector( unsigned(value) + 1 );
Run Code Online (Sandbox Code Playgroud)

例如,参见如何使用IEEE.NUMERIC_STD执行STD_LOGIC_VECTOR添加.

  • 实际上它并不那么挑剔,事实上它非常明确.`std_logic_vector`只是一个位数组,所以它没有数值.在VHDL-2008中,有两个名为`IEEE.Numeric_Std_Unsigned`和`IEEE.Numeric_Std_Signed`的包,它们可以直接在`std_logic_vector`上进行算术运算.我不确定我是否认为这是一件好事,因为VHDL的一个重要方面是显性.但至少它是在那里,如果你想用Verilog风格. (3认同)

Vla*_*lav 5

试试这个代码:

use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
...
nextvalue <= value + "1";
Run Code Online (Sandbox Code Playgroud)

在我的情况下,这个解决方案是有效的!