5
\$\begingroup\$

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?

asked Jan 30, 2014 at 16:49
\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

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;
answered Jan 30, 2014 at 17:27
\$\endgroup\$
1
  • \$\begingroup\$ And of course, if you are representing numbers, you should be using either the un/signed vector types, or an integer type. \$\endgroup\$ Commented Jan 31, 2014 at 14:51
3
\$\begingroup\$

wzab's answer is precisely what you asked. So I'll just remind that you can go the other way round. You could declare s1 as an integer, say:

signal s1: integer range 0 to 127;

and that will keep your code free from type conversions, at least until you have to push the signals out of the chip. Depending on the amount of operations, this can make your code significantly cleaner.

answered Jan 30, 2014 at 21:16
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.