Cannot continue because of fatal error (sfixed to integer)

Status
Not open for further replies.

fanwel

Full Member level 3
Joined
May 26, 2011
Messages
178
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,878
Hi all;

It is possible if I want to convert from sfixed to floating point? For example: convert 000001000 to 0.483..
I try to write like below, but its working for convert integer..
-------------------------------------------------------
library ieee;
library ieee_proposed;
use ieee_proposed.fixed_pkg.all;
use IEEE.STD_LOGIC_SIGNED.ALL;
use IEEE.numeric_std.all;

entity try is
port (A: in sfixed(4 downto -4);
clk: in bit;
out_A: out integer range -127 to 127);
end try;

architecture try of try is
begin
process (clk)
begin
if (clk'event and clk='1') then

out_A <= to_integer(signed(A));

end if;
end process;
end try;
-----------------------------------------------------------
There are no problems when I compile in quartus. But, a fatal error occur when I simulate in ModelSim. Need helps..Thanks
 

A is a 9 bit sfixed. You are converting it to signed so the range is -256 to 255, so this conversion:

out_A <= to_integer(signed(A));

is going out of range.
Either change the range of out_A a to -256 to 255
or change A to sfixed(3 downto -4)
 

If I change A: in sfixed(3 downto -4) the same fatal error is occur.
Btw Tricky, my system will calculate an input integer multiply by 0.483 (n x 0.483).
First, I convert 0.483 and the input integer to sfixed. Then, the output of course will be sfixed.
What I want is the final answer will be an integer/floating point.
It is possible? If possible how can I convert them? thanks for reply..
 

First of all - please post the actual errors you are getting in modelsim. is it a compile error, or are you getting an error during simulation?

Secondly - do you want it to be an integer or a floating point number? they are completly different things. Firstly an integer cannot have a fractional part. Secondly, you cannot synthesis floating point number. So please say what you want to do with the number.

I dont think you fully understand what you are doing.

sfixed(4 downto -4) is in the range -16 to +15.9375
the conversion you did moves it to the range -256 to +255
You can convert it back, but only if you understand what you're doing.
 

First - This is the error in ModelSim:
Fatal error in Process line__15 at H:/altera/Daubechies_Wave/sfixed_integer_tb/try.vhd line 19

Second- I want it to be a floating point number. I want to check whether the output is right or not.
For example: A<="000001000" , out_A<="000000000001000000" (0.483x1)
I want to show the answer as 0.483. Thanks for reply..
 

First - This is the error in ModelSim:
Fatal error in Process line__15 at H:/altera/Daubechies_Wave/sfixed_integer_tb/try.vhd line 19

That doesnt say what the error is, thats just where it is.

Second- I want it to be a floating point number. I want to check whether the output is right or not.
For example: A<="000001000" , out_A<="000000000001000000" (0.483x1)
I want to show the answer as 0.483. Thanks for reply..

for a start 000001000 (or the other longer value) is not 0.483. It is 0.5 in the sfixed format you have specified.
So you cannot show 0.483, because it has been rounded to the nearest value, which is 0.5. You have lost preceision. You may need to add more fractional bits to your sfixed specification.

If you really want a floating point value, convert it to a real type:

out_A : out real;

....
out_A <= to_real(A)

you cannot compile this in quartus, but you can simulate it in modelsim.
 

    V

    Points: 2
    Helpful Answer Positive Rating
"You may need to add more fractional bits to your sfixed specification."
If I write 00000100000 (4 downto -6), what the rounded value in sfixed format? How to know?
Thanks for reply..
 

00000100000 is still 0.5.
with fixed point, each bit represents 2^n, where n is the bit position in binary (with the MSB being the sign bit with signed numbers)

So with (4 downto -4) = 00100.1010 = 2^2 + 2^-1 + 2^-3 = 4 + 0.5 + 0.125 = 4.625

---------- Post added at 10:21 ---------- Previous post was at 10:18 ----------

Btw, sfixed is just a convenient package for an integer. It is still a 2s complement integer, but the array indeces show the offset of the separation between integer bits and fractional bits.
 
Reactions: fanwel

    fanwel

    Points: 2
    Helpful Answer Positive Rating
the error is not in the code you posted. its in the try_tb.vhd file.

Try reading your errors before posting here!
 

you forgot a ")" at the end of the port

Please Please Please Please try and sort these problems yourself before posting here. The errors do often tell you what is wrong!
 

I have fixed the problems. Thank you Tricky for your helps..
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…