Using numeric_std packages

H

hssig

Hi,

I am trying to use the VHDL-2008 library "numeric_std_unsigned" to
increment a std_logic_vector by one:

use ieee.numeric_std_unsigned.all;

signal vec : std_logic_vector(15 downto 0) := (others => '0');

vec <= vec + 1 when rising_edge(clk);


Now I have in the same VHDL file the following conversion:

constant cIniVec : std_logic_vector(15 downto 0) :=
std_logic_vector(to_unsigned(1,16));


That means that I have to include both libraries:
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;

Do I use the packages how nature intended it?

Cheers, hssig
 
N

nivparsons

Hi,

I am trying to use the VHDL-2008 library "numeric_std_unsigned" to
increment a std_logic_vector by one:

use ieee.numeric_std_unsigned.all;

signal vec : std_logic_vector(15 downto 0) := (others => '0');

vec <= vec + 1 when rising_edge(clk);


Now I have in the same VHDL file the following conversion:

constant cIniVec : std_logic_vector(15 downto 0) :=
std_logic_vector(to_unsigned(1,16));


That means that I have to include both libraries:
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;

Do I use the packages how nature intended it?

Cheers, hssig

You can do something like this:
my_SLV <= SLV(UNSIGNED(my_SLV) + 1);

where SLV is STD_LOGIC_VECTOR, my_SLV is you vector/signal and then you only need the NUMERIC_STD package. (I think)!
 
K

KJ

Hi,

I am trying to use the VHDL-2008 library "numeric_std_unsigned" to
increment a std_logic_vector by one:

use ieee.numeric_std_unsigned.all;

signal vec : std_logic_vector(15 downto 0) := (others => '0');

vec <= vec + 1 when rising_edge(clk);


Now I have in the same VHDL file the following conversion:

constant cIniVec : std_logic_vector(15 downto 0) :=
std_logic_vector(to_unsigned(1,16));


That means that I have to include both libraries:
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;

Do I use the packages how nature intended it?

No you're not. You should declare vec (and cIniVec) to be of type unsigned.. std_logic_vector is used for an arbitrary collection of bits that have no numeric interpretation as well as for interfacing to the outside world. Your usage doesn't meet either criteria. Also, simply use ieee.numeric_std..all

Kevin Jennings
 
H

hssig

As I already mentioned:

I am trying to increment a std_logic_vector by one (not possible with "numeric_std" but with "numeric_std_unsigned") in a testbench file.
At the same time I want to use conversions that are part of "numric_std" but
not of "numeric_std_unsigned", for example conversion functino "to_unsigend" of an integer.

So how can I use both?

Cheers, hssig
 
K

KJ

As I already mentioned:

I am trying to increment a std_logic_vector by one (not possible with "numeric_std" but with "numeric_std_unsigned") in a testbench file.
At the same time I want to use conversions that are part of "numric_std" but
not of "numeric_std_unsigned", for example conversion functino "to_unsigend" of an integer.

So how can I use both?

I already posted the best way to do that which is to change the type of the signal to unsigned rather than std_logic_vector.

The next best way is to cast them to the proper type

signal vec : std_logic_vector(15 downto 0) := (others => '0');
vec <= std_logic_vector(unsigned(vec) + 1) when rising_edge(clk);

Using ieee.numeric_std.all only

Kevin Jennings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top