- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Experts,
could someone give me a hint to make conversion: having a float number: CALIBRATION_CURRENT_LOGAIN : real:= 0.89552238805970152; i wanted to convert it to unsigned(15 downto 0) (declared as UWord) as: constant CALIBRATION_CONSTANT_LOGAIN : UWord := TO_UNSIGNED(integer(CALIBRATION_CURRENT_LOGAIN*real(2**15)),UWord'length); for some funny reasons I get unsigned value as "70F0" instead of "72A0" as it is supposed to be. any ideas where the error comes from? thanks d.Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nope. cant see any problems there.
But may I suggest you look into the new IEEE float_fix_pkg. It means you can start using things like: constant CALIBRATION_CONSTANT_LOGAIN : ufixed(-1 downto -16); Meaning you dont need to keep putting in annoying Bias multiplies in.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or you can do handy things like this:
constant CALIBRATION_CONSTANT_LOGAIN : ufixed(-1 downto -16) := to_ufixed(CALIBRATION_CURRENT_LOGAIN, 0, 16)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I never experienced Quartus issues with real numbers. Did you try a number with less digits?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
actually this is simulated first in modelsim, then implemented in quartus. both of them give exactly the same wrong value :) thanks for hints using the new type. I did not know about it is it a vhdl2000 standard? if so i'd rather avoid as all stuff is 93 standard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its part of the 2008 standard - but you can compile and use the package fine in Quartus. You just import it as part of your project or an external library. Get it from here (these are '93 compliant version of the VHDL - 2008 files) :
http://www.eda.org/fphdl/ Given you had a problem in modelsim, Im guessing there is problem elsewhere. I tried the code you posted exactly as is in modelsim and it worked fine. Are you sure you havent done something like declare the constant you posted in a package then declared it again in the source file, but with the new "wrong" value?
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page