You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using your library to make data acquisition i noticed that sometimes computeVolt return a bad result, due to some compiler optimisation, like in this output :
Channel 1 and 2 are wrong : rms is rounded as int before calling computeVolt to get Vapp, it should be 0V !
I am running on ESP32 with Arduino_ESP32 library (Arduino IDE version 2.3.2), AdaFruit latest release (2.5.0).
Chips is an ADS1015 (from techniot bought on Amazon)
Original parts of the code producing random wrong value some times:
> > MainPowerChannel.RMSValue = MainPowerChannel.RMSValue / MainSampleRead;
> > MainPowerChannel.RMSValue = sqrt(MainPowerChannel.RMSValue);
> > // Convert to Volt using ADC resolution
> > MainPowerChannel.Vapp = adcComputeVolts(iMainVoltageADC, MainPowerChannel.RMSValue);
>
(source is used to get the right ADC object to used on a list of 2...)
to solve temporarly this problem i had to use the source value before calling computeVolt in my own code (using a printf or another operation. (removing one or the other comment)
reading the current library code, i found that the current operation give priority on the division of the full range value (float) by the resolution BEFORE applying current source value.
float Adafruit_ADS1015::computeVolts(int16_t counts)
{
// see data sheet Table 3
float fsRange;
switch (m_gain) {
case GAIN_TWOTHIRDS:
fsRange = 6.144f;
break;
case GAIN_ONE:
fsRange = 4.096f;
break;
case GAIN_TWO:
fsRange = 2.048f;
break;
case GAIN_FOUR:
fsRange = 1.024f;
break;
case GAIN_EIGHT:
fsRange = 0.512f;
break;
case GAIN_SIXTEEN:
fsRange = 0.256f;
break;
default:
fsRange = 0.0f;
}
return counts * (fsRange / (32768 >> m_bitShift));
}
So i changed the order of the code to do the multiplication first then the division (better for accurancy)
// Change order of operation to do upscaling before downscaling;
return (fsRange*counts) / (32768 >> m_bitShift);
And now i did'nt get any problem with the calculation.
The text was updated successfully, but these errors were encountered:
Searching more for this problem since it still occurs, i fall on a weird bug in espressif SDK with floating point calculation errors due to context switching.
It seems to have been corrected in 5.1.0 version and for the ESP32-S3, but since it is not my target, i suspect that the problem is wider and not corrected on the 4.4 branch too.
Hello,
using your library to make data acquisition i noticed that sometimes computeVolt return a bad result, due to some compiler optimisation, like in this output :
Channel 1 and 2 are wrong : rms is rounded as int before calling computeVolt to get Vapp, it should be 0V !
I am running on ESP32 with Arduino_ESP32 library (Arduino IDE version 2.3.2), AdaFruit latest release (2.5.0).
Chips is an ADS1015 (from techniot bought on Amazon)
Original parts of the code producing random wrong value some times:
(source is used to get the right ADC object to used on a list of 2...)
to solve temporarly this problem i had to use the source value before calling computeVolt in my own code (using a printf or another operation. (removing one or the other comment)
reading the current library code, i found that the current operation give priority on the division of the full range value (float) by the resolution BEFORE applying current source value.
So i changed the order of the code to do the multiplication first then the division (better for accurancy)
And now i did'nt get any problem with the calculation.
The text was updated successfully, but these errors were encountered: