Altera_Forum
Honored Contributor
10 years ago'real' bit-accuracy, and bypassing 'integer' to make 'signed/unsigned' constant value
Greetings All:
I am currently working on some DSP filtering. I create constant values for the coefficients required based on the generic values. For example...
calc_coef := to_signed(integer(MATH_E**(-(MATH_2_PI * (actual_fc_real(rep)/real(clock_rate)))) * 2.0**(coef_width - 1)), coef_width); The 'actual_fc_real(rep)' is a 'real' generic and the 'clock_rate' is an integer in this case, but could be a 'real' generic. The 'coef_width' scales the coefficient to the 'signed' fixed point. It works fine most of the time, however, every now and then I receive an error if the coef_width is >= 32, and coefficient value is closer to 1.0, sometimes it passed through using > 32 bits when it's 0.0003~ value for example. The two questions I have are: First: What is the bit-accuracy is the 'real' type in VHDL? I noticed the value I used...
-- 3.1 MATH_REAL package declaration
------------------------------------------------------------------------
--
-- Copyright 1996 by IEEE. All rights reserved.
--...
constant MATH_2_PI : REAL := 6.28318_53071_79586_47693;
--... ...has 21 decimal digits, which means log2(10**21) = ~69 bit-accuracy, which exceeds the 'double' floating point used on the PC computer. Anyway, the reason I'm looking, float uses 32-bit format, with only 24-bit mantissa. I couldn't find much information of that on the web, and if the accuracy of the 'real' is around 24-bits, there's no point calculating a > 32-bit signed for the coefficient. Second: I usually use the width of the hardware math functions using 36-bits if the 18-bit range is passed. 18-bit isn't very accurate for coefficients near 0.0 or 1.0, ie. the 0.0003~ I mention earlier. I have been limited to the 32-bit because of the 'integer' range specified by VHDL. Is there a way to bypass the intermediate 'integer' phase since the 'real' handles the numbers (providing accuracy, or course) and the 'signed' handle the width, the 'integer' range blocks the path I'm looking for. Bonus Question: If the 'integer' limit isn't passable, I was planning to send the generic values to my computer and calculate the information coefficients and return them as a signal. I'm also working on an assembler compiler, which needs access to the same generic values as well. It's very simple to read an 'integer' generic value, request it with an rs232 command, and return the 4 bytes on rs232 TX port. Is there a way to extract the float or double's 4 or 8 bytes of a 'real' generic so I can send the information to the computer, preferably in the float or double format. I hope my questions are interesting and beneficial for all involved. David K.