Fixed-point scaling issue?
Answers
-
Submitted by pete on Mon, 10/21/2013 - 21:23.
Hi Duco, The problem is the fx30.32 '*' (multiply) in the middle. fx30.32 means that you have 30 integer bits and 2 fractional bits in 32 bit word. 1 fractional bit lets you represent multiples of 1/2, 2 fractional bits lets you represent multiples of 1/4, 3 fractional bits gives you multiples of 1/8, and so on. You are feeding the multiply with .25 and .5, the result of which is .125 (or 1/8). You need 3 fractional bits to represent 1/8, but you only allocated 2, so the result is truncated to 0. If you know your largest result will be significantly less than 500 million, then you can move some integer bits to the fractional side and postpone the truncation. Generally you want enough integer bits to handle the largest input value you will see, but no more, as it steals precision away from fractional side.
We could add a warning when results are truncated to zero due to insufficient fractional bits.
Pete
0