Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to convert fixed points to the nearest std_logic_vector?

Status
Not open for further replies.

JKR1

Junior Member level 3
Joined
Aug 24, 2015
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
208
hi
is there any function for converting fixed point numbers (for example (7 downto -8)) to the nearest std_logic_vector(7 downto 0)?
if yes which packages and libraries shoulld be added?
thanks
 

what do you mean by "nearest" std_logic_vector?

whats wrong with just:
my_slv <= to_slv( my_ufxied(7 downto 0) );
 

thanks for answering,
I want to convert the number 119.7(ufixed(7 downto -8)) to 119(std_logic_vectror(7 downto 0)).
I meant rounding the numbers by nearest .

- - - Updated - - -

this error happens when I use
Code:
my_slv <= to_slv( my_ufxied(7 downto 0) );
** Error: C:\modeltech_6.5c\examples\main1.vhd(83): Target type ieee.NUMERIC_STD.UNSIGNED in variable assignment is different from expression type ieee.std_logic_1164.STD_ULOGIC_VECTOR.
 

sounds like you declared the my_slv as an unsigned and not a std_logic_vector
for this, you need:

my_us <= unsigned( my_ufixed(7 downto 0) );
 
  • Like
Reactions: JKR1

    JKR1

    Points: 2
    Helpful Answer Positive Rating
thanks for answering,
I want to convert the number 119.7(ufixed(7 downto -8)) to 119(std_logic_vectror(7 downto 0)).
I meant rounding the numbers by nearest .

Then you mean you want to convert from 119.7 to 120? you're example shows 119.7 to 119, which is truncation not rounding.

If you want to round (don't know if there is a function or package for it) compare ufixed(-1)='1' and add a 1 to the truncated value.
 
  • Like
Reactions: JKR1

    JKR1

    Points: 2
    Helpful Answer Positive Rating
thanks for answering,
I want to convert the number 119.7(ufixed(7 downto -8)) to 119(std_logic_vectror(7 downto 0)).
I meant rounding the numbers by nearest .

- - - Updated - - -

this error happens when I use
Code:
my_slv <= to_slv( my_[B]ufxied[/B](7 downto 0) );

It looks like you copied the typo verbatim...

it should be 'ufixed', not 'ufxied'
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top