Dear Forum,
I have experienced some strange behaviour using float/double values in a formula calculation.
Using the same static double values the result may differ each time I run the calculation?
I'm using a LPC824 (Cortex M0) with no FPU and KEIL-MDK. No MicroLIB and default compiler version 5
I'm aware of the usage of double/float precision issue. But this problem is when using the same values, the result is different each time I run a calculation.
I have a voltage (double) from a ADC, that is run through a formula, that uses 7 coefs (double).
The formula is this:
dResult = V0[paramIndex] + ( (dTemp-T0[paramIndex])*(P1[paramIndex]+(dTemp-T0[paramIndex])*(P2[paramIndex]+(dTemp-T0[paramIndex])*(P3[paramIndex]+P4[paramIndex]*(dTemp-T0[paramIndex]))))/( 1+(dTemp-T0[paramIndex])*(q1[paramIndex]+q2[paramIndex]*(dTemp-T0[paramIndex]))));
V0[], T0[], P1[], P2[], P3[], P4[], q1[] and q2[] contains static double values. So they do neve change.
dTemp is the double value (voltage) passed to the function containing the formula.
If I also keep the dTemp stable (fixed static value of 27.8125) the dResult is different each time I run the formula. If I use the value of 27.7812 it is the same value each time.
Why do I see this behavior? Why is the result not the same each time?
Thomas
Hi again,
I tried removing more and more code and it seems related to setting the CPU to low power mode.
It is related to this:
cmdData[0] = 12; cmdData[1] = PWR_LOW_CURRENT; cmdData[2] = 12; __disable_irq(); LPC_ROM_API->pPWRD->set_power(cmdData, &response); __enable_irq();
Removing this does the trick. With both the changing value and the precision
Any idea why? Because I need the low power mode.
You've only got a 256 byte stack. You're not far off that with your code and I don't know what the internal ROM routines use.
Have you tried increasing that stack size?
That's probably something you need to take to NXP, then...