Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > type conversion problem

Reply
Thread Tools

type conversion problem

 
 
mahmoud mahmoud is offline
Junior Member
Join Date: Sep 2008
Posts: 2
 
      09-04-2008
hi all,
i am trying to do a simple code using vhdl but the problem presists...i am trying to add a std_logic_vector type elements and i wrote the following

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

entity test is
port (
NBC :in std_logic_vector(3 downto 0);
op ut std_logic_vector(2 downto 0)
);
end test;
architecture arch of test is
signal sum :unsigned (2 downto 0);
begin

sum <=unsigned(std_logic_vector("00"&NBC(0)))+unsigned (std_logic_vector("00"&NBC(1)))+unsigned(std_logic _vector("00"&NBC(2)))+unsigned(std_logic_vector("0 0"&NBC(3)));

op <=std_logic_vector(sum);

end arch;

plz i wanna know where is the problem ........thanks for help
 
Reply With Quote
 
 
 
 
Steff Steff is offline
Junior Member
Join Date: Sep 2008
Posts: 11
 
      09-08-2008
Hi,

if you have typeless vector like "00" and you want to convert it to a concret type you have to do it in the following way:

type'("00")

sum <= unsigned'("00"&NBC(0))+
unsigned'("00"&NBC(1))+
unsigned'("00"&NBC(2))+
unsigned'("00"&NBC(3));

But for your case it is easier to do it this way:

sum <= "00"&NBC(0)+"00"&NBC(1)+"00"&NBC(2)+"00"&NBC(3 );


Hope I could help you!

Bye, Steff
 

Last edited by Steff; 09-15-2008 at 09:32 AM..
Reply With Quote
 
 
 
 
mahmoud mahmoud is offline
Junior Member
Join Date: Sep 2008
Posts: 2
 
      09-08-2008
hi steff,

ur attempt to help is greatly appreciated ....i have tried the line u just has edited now :

sum <= "00"&NBC(0)+"00"&NBC(1)+"00"&NBC(2)+"00"&NBC(3 );

but after introducing a new intermediate signal ...>>>
i wrote the code as follows:

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

entity test is
port (
NBC :in std_logic_vector(3 downto 0);
op ut std_logic_vector(2 downto 0)
);
end test;
architecture arch of test is
signal sum :unsigned (2 downto 0);
signal sum_un :unsigned(3 downto 0);

begin
sum_un<=unsigned(NBC);
sum <= ("00"&sum_un(0))+
("00"&sum_un(1))+
("00"&sum_un(2))+
("00"&sum_un(3 ));

op <= std_logic_vector(sum);
end arch;

Also i have tried to remove this signal ....as u suggested and it worked....i dont know the impact on the synthesis but i'll discover soon ..
thanks for ur help steff

bye
 

Last edited by mahmoud; 09-08-2008 at 02:07 PM..
Reply With Quote
 
Steff Steff is offline
Junior Member
Join Date: Sep 2008
Posts: 11
 
      09-08-2008
Your welcome!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type conversion function for user defined type... zaeminkr@gmail.com C++ 1 05-16-2007 09:00 AM
conversion from const type* to type* allowed? Michal Nazarewicz C Programming 13 01-05-2007 01:54 PM
Conversion from type 'DBNull' to type 'String' is not valid Chris ASP .Net 2 05-11-2006 08:20 AM
conversion from type 'DBNull' to type 'float' is not valid ibiza ASP .Net 2 01-27-2006 09:57 PM
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. luna ASP .Net 1 02-13-2004 01:15 PM



Advertisments