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

when 0.000030517578125 multiplied with any number getting result as Zero

Hi

I am reading the sensor data (Irms and Vrms) via I2C protocol and multiplying the read data with 0.000030517578125 to get correct result but i am getting the result as zero

Vrms = ((m_sample[1] << 8) | m_sample[0]);
Irms = ((m_sample[3] << 8) | m_sample[2]);

float Vrms_acc = ((float)Vrms) * (0.000030517578125);
float Irms_acc = ((float)Irms) * (0.00006103515625);


NRF_LOG_INFO("-------------------\r\n");
NRF_LOG_INFO(" Recevied Data.\r\n");
NRF_LOG_INFO(" Vrms = " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(Vrms_acc));
NRF_LOG_INFO(" Irms = " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(Irms_acc));
NRF_LOG_INFO("-------------------\r\n");

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

OUTPUT

ENERGY_METER:INFO:-------------------
ENERGY_METER:INFO: Recevied Data.
ENERGY_METER:INFO: Vrms = 0.000000000000000
ENERGY_METER:INFO: Irms = 0.000000000000000
ENERGY_METER:INFO:-------------------

Thanks in advance 

Parents
  • NRF_LOG_FLOAT_XXX does not support small numbers, since there is no scientific (exponential) display modeand only a limited amount of digits.

    That means numers between 0 and 1e-3 (? Not sure where the limit is exactly) are rounded down to zero.

    You might want to print the (integer?) values for Vrms and Irms directly for debugging.

    Also note that ((float)Vrms) * (0.000030517578125) is a double multiplication (IMHO, the constant is a double number) which must be done in software instead of the Cortex-M4 FPU.

Reply
  • NRF_LOG_FLOAT_XXX does not support small numbers, since there is no scientific (exponential) display modeand only a limited amount of digits.

    That means numers between 0 and 1e-3 (? Not sure where the limit is exactly) are rounded down to zero.

    You might want to print the (integer?) values for Vrms and Irms directly for debugging.

    Also note that ((float)Vrms) * (0.000030517578125) is a double multiplication (IMHO, the constant is a double number) which must be done in software instead of the Cortex-M4 FPU.

Children
No Data
Related