Electronic – Set STD_LOGIC_VECTOR with constant integer

vhdl

Is it possible to set a STD_LOGIC_VECTOR(6 DOWNTO 0) with a constant like so:

signal s1: std_logic_vector(6 downto 0);
s1 <= 12;

Or do I have to define it as a set of bits?

Best Answer

You can do it, but not directly. Something like this should work:

s1 <= std_logic_vector(to_unsigned(12,7));

or

s1 <= std_logic_vector(to_unsigned(12,s1'length)); 

Of course at the begining of your file you should declare:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;