This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

High Current Draw With Floating Point Calculation

I'm attempting to optimize our application for battery life on the nrf52832.

If I execute a floating point calculation to rescale RGB to PWM, I start drawing 6.2mA, eliminating the calculation reduces current to an more reasonable 0.05mA. To be clear I am not using the calculation result to drive the PWM yet, just making the calculation & saving the result globally

volatile uint16_t blue_cmd; void rgb2pwm(uint8_t blue) { float blue_duty_cycle = (float)(blue)/2.55f; blue_cmd = (uint16_t)blue_duty_cycle; }

Is there something that needs to be done to minimize power for floating point calculations?

Parents Reply Children
  • Just saw that the fix is also used when calling nrf_pwr_mgmt_run() (in nrf_pwr_mgmt.c)

    __STATIC_INLINE void pwr_mgmt_fpu_sleep_prepare(void)
    {
        uint32_t fpscr;
        CRITICAL_REGION_ENTER();
        fpscr = __get_FPSCR();
        /*
        * Clear FPU exceptions.
        * Without this step, the FPU interrupt is marked as pending,
        * preventing system from sleeping. Exceptions cleared:
        * - IOC - Invalid Operation cumulative exception bit.
        * - DZC - Division by Zero cumulative exception bit.
        * - OFC - Overflow cumulative exception bit.
        * - UFC - Underflow cumulative exception bit.
        * - IXC - Inexact cumulative exception bit.
        * - IDC - Input Denormal cumulative exception bit.
        */
        __set_FPSCR(fpscr & ~0x9Fu);
        __DMB();
        NVIC_ClearPendingIRQ(FPU_IRQn);
        CRITICAL_REGION_EXIT();
    
        /*
        * Assert no critical FPU exception is signaled:
        * - IOC - Invalid Operation cumulative exception bit.
        * - DZC - Division by Zero cumulative exception bit.
        * - OFC - Overflow cumulative exception bit.
        */
        ASSERT((fpscr & 0x07) == 0);
    }

Related