Page 1 of 1

Converting code to fixed point

PostPosted: Nov 14, 2003 @ 5:42pm
by Pam

PostPosted: Nov 15, 2003 @ 1:58pm
by Pam

PostPosted: Nov 15, 2003 @ 6:42pm
by Dan East
I haven't had time to go through and find the problem. However I have a suggestion.

If you multiply an int against a fixed point value then the result is a fixed point value (32.0 * 24.8 = 24.8 ). You are converting "power" to fixed point to multiply it against a fixed point value, so you have to shift back after the fixed point mult. Just multiply power as a regular int against what you want to scale, and you don't have to right shift afterward, and you will have an extra 8 bits of range to work with.

The primary problem you will run into with fixed point math is overflow. I'll let you know if I see anything else.

Dan East

PostPosted: Nov 15, 2003 @ 6:48pm
by Dan East
cos and sin are floating point routines that accept radians. You are converting radians to fixed point and passing that to sin and cos, so those will return off the wall results. You need to create your own fixed point LUT for sin / cos. Instead of passing radians pass something like 0 to 2047, where 2048 is equivalent to 2*pi.

Dan East

PostPosted: Nov 15, 2003 @ 7:22pm
by Pam
Thanks Dan. You are, of course, right as usual.

Pam

PostPosted: Nov 15, 2003 @ 8:53pm
by Dan East