题
这里发生了什么?为什么我会收到“运算符参数类型不匹配”的消息,我该如何修复它?
--
-- 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;
谢谢
解决方案
你不能直接增加std_logic,你需要将它转换为 unsigned
结果返回 std_logic_vector
使用 numeric_std
包裹。
use ieee.numeric_std.all
...
nextvalue <= std_logic_vector( unsigned(value) + 1 );
其他提示
试试这个代码:
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
...
nextvalue <= value + "1";
在我的情况下,这种解决方案的作品!
另一种方式是重载的“+”在这种情况下,可以写为:
function "+" ( a : std_logic_vector; b : integer ) return std_logic_vector is
variable result : unsigned(a'range);
begin
result := unsigned( a ) + 1 ;
return std_logic_vector( result ) ;
end function ;
创建一个包,并包括在该程序包该功能,这将达到目的。一件事情要做包括IEEE numeric_std包,因为它包含的转换函数。
在除了那些已经提供的答案,可以重写代码,定义nextvalue
作为具有unsigned
数据类型(下文)。注意,这里使用的nextvalue <= to_unsigned(0, 32);
清除计数器,以及使用rising_edge(clk)
来触发上升沿的关闭。
-- 32-bit counter with enable and async reset
architecture synthesis1 of counter_32bit is
signal nextvalue : unsigned ( 31 downto 0 );
begin
ff:process( clk, rst )
begin
if( rst = '1' ) then
nextvalue <= to_unsigned(0, 32); -- reset the count
elsif rising_edge(clk) then
if( ena = '1' ) then
nextvalue <= nextvalue + 1; -- increment the count
end if;
end if;
end process ff;
-- Concurrent assignment statement
value <= std_logic_vector(nextvalue);
end synthesis1;
并发分配的这种形式似乎是从更新我在书发现和网上计数器的首选方法。
另外,如果你继续使用std_logic_vector
的nextvalue
类型,用于清除它的首选方法似乎nextvalue <= (others => '0');
而不仅仅是nextvalue <= 0;
。
概括地说,STD_LOGIC_VECTOR就是这样,比特的向量。这意味着本身没有什么,所以你不能指望VHDL语言语义假设增量操作将在它的工作。这里的其他职位约其转换为一个无符号应该做的伎俩。
这也将工作:
nextvalue <= value + '1';
不知道你是真的很好用VHDL精通。以下语法是逻辑上正确的,如果使用的是std_logic_arith包
不隶属于 StackOverflow