inv_sqrt() function will increases power

1.SDK:SDK17.1

2.IAR V9.2

3.

static float inv_sqrt(float x)
{
float xhalf = 0.5f * x;

int i = *(int *)&x;

i = 0x5f375a86 - (i >> 1); // this is magic.
x = *(float *)&i;
x = x * (1.5f - xhalf * x * x); // 1st newton iteration.
x = x * (1.5f - xhalf * x * x); // repeating increases accuracy, this can be remove.
return 1 / x;
}

volatile float vf_value = 0.0;

int main(void)
{

...

vf_value= inv_sqrt(1.1);

...

}

 ble_app_hrs_freertos demo will alway  5mA.

but ble_app_beacon is normal.

Parents
  • Hi,

    What is normal current when you use ble_app_beacon?

    This issue might be related to Floating Point Unit (FPU).
    You could take a look at these two cases - first, and second.

    How long do you use FPU?
    Do you have any FPU interrupts?

    Best regards,
    Dejan

  • I still don't know how to fix it.

    1. I only execute this function once

    2.No  FPU interrupts

    ------------------------------------------------------------

    a. It is 5mA

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;

    i = 0x5f375a86 - (i >> 1); // this is magic.
    x = *(float *)&i;
    return 1 / x;
    }

    b. It is normal, is it use FPU?

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;
    x = *(float *)&i;
    return 1 / x;
    }

    c.It is normal, is it use FPU?

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;

    i = 0x5f375a86 - (i >> 1); // this is magic.
    x = *(float *)&i;
    return  x;
    }

Reply
  • I still don't know how to fix it.

    1. I only execute this function once

    2.No  FPU interrupts

    ------------------------------------------------------------

    a. It is 5mA

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;

    i = 0x5f375a86 - (i >> 1); // this is magic.
    x = *(float *)&i;
    return 1 / x;
    }

    b. It is normal, is it use FPU?

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;
    x = *(float *)&i;
    return 1 / x;
    }

    c.It is normal, is it use FPU?

    static float inv_sqrt(float x)
    {

    int i = *(int *)&x;

    i = 0x5f375a86 - (i >> 1); // this is magic.
    x = *(float *)&i;
    return  x;
    }

Children
Related