What's going on here? Why am I getting an 'operator argument type mismatch', and what can I do to fix it?
--
-- 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;
Thanks
The std_logic_vector type is used for arrays of std_logic variables and signals. The basic VHDL logic operations are defined on this type: and , nand , or , nor , xor , xnor . These must be given two arrays of the same size; they do the operation on ecah position and return another array.
Both std_logic_vector and unsigned are unconstrained arrays of std_logic . As is the signed type. std_logic_vector is declared in the std_logic_1164 package; unsigned and signed are declared in the package numeric_std .
The syntax for declaring signed and unsigned signals is: signal <name> : signed(<N-bits> downto 0) := <initial_value>; signal <name> : unsigned(<N-bits> downto 0) := <initial_value>; Just like with std_logic_vector, the ranges can be to or downto any range.
Try this code:
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
...
nextvalue <= value + "1";
In my case this solution is works!
you can't increment std_logic directly, you need to convert it to unsigned
and the result back to std_logic_vector
using the numeric_std
package.
use ieee.numeric_std.all
...
nextvalue <= std_logic_vector( unsigned(value) + 1 );
See How Do Perform STD_LOGIC_VECTOR Addition Using IEEE.NUMERIC_STD for example.
One more way is to overload the "+" in this case you can write:
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 ;
create a package and include this function in that package and this will do the trick . One more thing do include the ieee numeric_std package because it contains the conversion functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With