unsigned + std_logic

A

aleksazr

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

I have an adder with carry out as std_logic,
and I have a number as unsigned.

signal limit, originallimit : unsigned(14 downto 0);
signal cy : std_logic;

limit <= originallimit + cy;

I have searched the net, but can't find out how to
convert std_logic to unsigned.

If I declare CY as unsigned(0 downto 0) then it works,
but it complains on the ADDER side (also, it makes more
sense to declare it as std_logic... right?)
 
A

aleksazr

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

I have an adder with carry out as std_logic,
and I have a number as unsigned.

signal limit, originallimit : unsigned(14 downto 0);
signal cy : std_logic;

limit <= originallimit + cy;

I have searched the net, but can't find out how to
convert std_logic to unsigned.

If I declare CY as unsigned(0 downto 0) then it works,
but it complains on the ADDER side (also, it makes more
sense to declare it as std_logic... right?)

OK, I got it to work by introducing another signal:
signal cy2 : std_logic_vector(0 downto 0);

cy2(0) <= cy;
limit <= originallimit + unsigned(cy2);

but its a bit clumsy.. any better way?
 
A

Anssi Saari

OK, I got it to work by introducing another signal:
signal cy2 : std_logic_vector(0 downto 0);

cy2(0) <= cy;
limit <= originallimit + unsigned(cy2);

but its a bit clumsy.. any better way?

How about

limit <= originallimit + 1 when cy = '1' else originallimit;
 
U

usevhdl

Hi,
Your expression is legal in VHDL-2008, numeric_std package.
limit <= originallimit + cy;

Many tools should support it now. OTOH, if not,
you can use any of the following:
limit <= originallimit + ("" & cy) ; -- "" = null array
limit <= originallimit + (1 => cy) ; -- aggregate array
limit <= originallimit + ('0' & cy) ; -- aggregate array

Make sure to use the parentheses. In VHDL-2008, the last
one will result in an error without them.

Best,
Jim Lewis
SynthWorks
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top