This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM48L952: Erroneous floating point arithmetic results when interrupts are enabled

Part Number: RM48L952

Hello

I'm periodically seeing some erroneous floating point arithmetic results when having interrupts enabled.  

To be clear, these calculations are being done in a function periodically called from the main loop. Most of the time the results are correct, but periodically I'm seeing the result going to zero when using the same multiplicand/multiplier/etc.
 
My routine does several floating point multiplications, divisions, etc.
 
I noticed that when I disable interrupts, the results are correct and consistent.

An example of code snippet is as follows:

static real32 A;
static real32 B;

A = 100.0 * 1500.0;
B = ((A / 20000.0F) * 100);

The value of B goes to 0.0 randomly sometimes.

Could you please provide some insight on this? 

 

  • Hello Uday,

    The interrupt will not affect the result of floating operation. Did you enable the floating point? Please enable it with _coreEnableVfp_();

    This is my test code. I enabled the floating point and RTI interrupt (every 1 second), and run the floating operation repeatedly in a while(1) loop. I don't see the problem as expected.

    int main(void)
    {
    /* USER CODE BEGIN (3) */
    static float32 A;
    static float32 B;
    uint32_t err = 0;

    _coreEnableVfp_();

    A = 100.0 * 1500.0;
    B = ((A / 20000.0F) * 100);

    rtiInit();

    /* Set high end timer GIO port hetPort pin direction to all output */
    gioSetDirection(hetPORT1, 0xFFFFFFFF);

    /* Enable RTI Compare 0 interrupt notification */
    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);

    /* Enable IRQ - Clear I flag in CPS register */
    /* Note: This is usually done by the OS or in an svc dispatcher */
    _enable_IRQ();

    /* Start RTI Counter Block 0 */
    rtiStartCounter(rtiCOUNTER_BLOCK0);

    while(1){
    A = 100.0 * 1500.0;
    B = ((A / 20000.0F) * 100);
    if (B != 750.00)
    err++;
    }

    /* Run forever */
    while(1);
    /* USER CODE END */

    return 0;
    }


    /* USER CODE BEGIN (4) */
    void rtiNotification(uint32 notification)
    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* Toggle HET pin 0 */
    gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ 0x00000001);
    }
    /* USER CODE END */
  • Hello QJ Wang

    Sorry for my delayed response.

    In our codebase, UsingFPU was not enabled for the particular task responsible for the floating point arithmetic. When it was enabled, then we no longer see the issue of Erroneous floating point arithmetic results anymore.

    Thanks a lot.