Hi!
I've a strange coding issue with multiplication of floats in IAR. Here is the code snippet:
unsigned int TEST (FS *fs){ float x0, x1, x2; x0 = 1.0 * fs->x; x1 = -2.0 * fs->x_1; x2 = 1.0 * fs->x_2; return 0;}The fs structure contains unsigned ints containing 10 bit ADC values. For any value of member x, the x0 = 1.0 * fs->x; row yields 2*x value in the debugger. For example x=377, then x0=756.0.
The debugger correctly translates x0 as a float. What is the problem here?
What do you get if you do not do the float multiply?
That is, if you try "x0 = fs->x;" instead of "x0 = 1.0*fs->x;", what is the result of x0?
Hi OCY,
thank you for your help. Please check the following screenshot, it contains both the problem and your tip.
Yes, I see.
But I tried to do the same and the results are correct as expected. The compiler you used may have a bug. Or you somehow tricked it.
By the way, the chip you used has fixed point MAC hardware. Using fixed point DSP will be fast. Using floating point is not so good.
I'm going to port the whole project into CCS to check if this is a compiler issue. In fact, I'm working on simple 2nd order HP filter using the MPY32 hardware and just wanted calculate some FP multiplications to verify my hardware multiplier code.