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 Reply
  • Thank you 

    Another problem i am facing is when i multiply Vrms and Irms with overall full scale of voltage path (i.e 230v) And

    overall full scale of current path (i.e 90 A) respectively i am getting worng result.

    float Vrms_acc = ((float)Vrms) * ((0.00003051757) * 230);
    float Irms_acc = ((float)Irms) * ((0.00006103515) * 90);

    result:

    Vrms = 0.-02088566784
    Irms = 0.-00202559488

     i am not getting why that - sign is coming.

    Thanks in advance

Children
  • There are not enough sample values to verify.
    I can assume that there is either not enough accuracy float and you need to switch to double.

    I try this code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <debugio.h>
    
    /*********************************************************************
    *
    *       main()
    *
    *  Function description
    *   Application entry point.
    */
    int main(void) 
    {
      uint32_t Vrms = 10;
      uint32_t Irms = 10;
    
      double Vrms_acc = ((double)Vrms) * ((0.00003051757f) * 230.0f);
      double Irms_acc = ((double)Irms) * ((0.00006103515f) * 90.0f);
    
      debug_printf("Vrms : %.9f \n", Vrms_acc);
      debug_printf("Irms : %.9f \n", Irms_acc);
      
    
      for(;;)
      {
      }
    }
    
    /*************************** End of file ****************************/

    And this:

    int main(void) 
    {
      uint32_t Vrms = 10;
      uint32_t Irms = 10;
    
      float Vrms_acc = ((float)Vrms) * ((0.00003051757) * 230);
      float Irms_acc = ((float)Irms) * ((0.00006103515) * 90);
    
      debug_printf("Vrms : %.9f \n", Vrms_acc);
      debug_printf("Irms : %.9f \n", Irms_acc);
      
    
      for(;;)
      {
      }
    }

    the result is the same:

Related