Other Parts Discussed in Thread: TM4C1290NCPDT
Hi all,
I've done some looking around here and I've seen several questions about floating point, but nobody seems to be getting such a blatantly wrong result as I am. This is unusual, and moreover it's only happened recently - older versions of this code seem to get the right result. As far as I'm aware, we haven't changed anything, not even versions of Code Composer or libraries, so I'm pretty confused. Here's the code that's messing up:
double energy_since_last_period = (rms_current * rms_voltage) * LINE_RMS_TIMER_PERIOD;
Here, both rms_current and rms_voltage are double-precision, and LINE_RMS_TIMER_PERIOD was a #define of 0.01.
With a current of 2.5A and a voltage of 240V, I was seeing an energy_since_last_period of 1.13e-6 Watt-seconds. The correct answer, however, is 6.0 Watt-seconds.
Thinking this was a problem with the #defined constant, I changed it to a double-precision number as well:
double t_period = LINE_RMS_TIMER_PERIOD;
double energy_since_last_period = (rms_current * rms_voltage) * t_period;
However, I still get the same result.
My confusion is multiplied in that all the other math operations in the product seem to work just fine, but this is one of the only areas we do any multiplication. The number's far enough off that it seems very strange for it to be so wrong. Any ideas on what could be causing it?
My compiler settings (not including include paths) are as follows:
-mv7M4 --code_state=16 --float_support=FPv4SPD16 --abi=eabi -me -Ooff --fp_mode=strict -g --gcc --define=ARM_MATH_CM4 --define=PART_TM4C1290NCPDT
(the ARM_MATH_CM4 is for the ARM CMSIS library, which allows me access to the DSP instructions on this part. I use them to compute the RMS current and RMS voltage numbers here)