Skip to content

RMS voltage calculation is incorrect #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
reinto1234 opened this issue May 28, 2025 · 9 comments
Open

RMS voltage calculation is incorrect #13

reinto1234 opened this issue May 28, 2025 · 9 comments

Comments

@reinto1234
Copy link

Hello,
for getting the real VRMS there is a multiplication by sqrt(2) missing. I don't exactly know why but i tasted it with a Waveform generator without resistors and a Fluke. I don't get the correct VRMS values if I use the function written down here i Have to multiply with sqrt(2).
Here's how i changed the code:
ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS)
{
ACS37800_REGISTER_20_t store;
ACS37800ERR error = readRegister(&store.data.all, ACS37800_REGISTER_VOLATILE_20); // Read register 20

if (error != ACS37800_SUCCESS)
{
if (_printDebug == true)
{
_debugPort->print(F("readRMS: readRegister (20) returned: "));
_debugPort->println(error);
}
return (error); // Bail
}

//Extract vrms. Convert to voltage in Volts.
// Note: datasheet says "RMS voltage output. This field is an unsigned 16-bit fixed point number with 16 fractional bits"
// Datasheet also says "Voltage Channel ADC Sensitivity: 110 LSB/mV"
float volts = (float)store.data.bits.vrms;
if (_printDebug == true)
{
_debugPort->print(F("readRMS: vrms: 0x"));
_debugPort->println(store.data.bits.vrms, HEX);
_debugPort->print(F("readRMS: volts (LSB, before correction) is "));
_debugPort->println(volts);
}
volts /= 65536; //Convert from codes to the fraction of ADC Full Scale (16-bit)
volts /= 1.19; //Convert from codes to mV (110 LSB/mV)
volts *= 250; //Convert to mV (Differential Input Range is +/- 250mV)
volts /= 1000; //Convert to Volts
volts *= sqrt(2); //Convert to RMS (AC voltage)
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
volts *= resistorMultiplier;
if (_printDebug == true)
{
_debugPort->print(F("readRMS: volts (V, after correction) is "));
_debugPort->println(volts);
}
*vRMS = volts;

@PaulZC
Copy link
Collaborator

PaulZC commented May 28, 2025

Hi @reinto1234 ,

Thanks for reporting this.

You say you tested it "with a Waveform generator without resistors". Did you remove the voltage divider resistors on the SparkX breakout? Or have you designed your own board? Have you set _dividerResistance and _senseResistance correctly?

Best wishes,
Paul

@reinto1234
Copy link
Author

reinto1234 commented May 28, 2025

Hello Paul,
i designed my own board. Basically its just the sensor. Divider resistance is set to 0. Sense resistor to 1. Example: Vpp waveform generator: 150mV, FLuke: 53mV AC VRMS, ACS: 0.05V VRMS (with multiplication by sqrt(2).
Greetings Tobi

@PaulZC
Copy link
Collaborator

PaulZC commented May 28, 2025

Hi Tobi,

Could this be a grounding issue?

Please post a link to your waveform generator. Is its output isolated? Is GND / 0V common between the waveform generator and the ACS37800 circuit? Does the 150mVp-p output have a DC bias?

Cheers,
Paul

@reinto1234
Copy link
Author

That's the Datasheet: https://beyondmeasure.rigoltech.com/acton/attachment/1579/f-001b/0/-/-/-/-/file.pdf
I'm working on a laptop so my ESP32 isn't connected to the same GND as the Rigol i also tried with the charger connected and it still had the same values. I rechecked the DC bias on the rigol it says 0 and the fluke also doesnt recognize any.

@PaulZC
Copy link
Collaborator

PaulZC commented May 28, 2025

OK - thanks.

What happens if you add a 75mV DC offset to the 150mVp-p?

I suggest looking again at your GND path. I suspect the voltage going to the ACS37800 is negative for half of each wave, preventing the ACS37800 from measuring it?

Please confirm if these are your connections:

  • Laptop (USB?) GND -> ESP32 GND -> ACS37800 GND -> ACS37800 VINN -> Waveform Generator GND (BNC Outer)
  • ACS37800 VINP -> Waveform Generator Out (BNC Inner)

@reinto1234
Copy link
Author

reinto1234 commented May 28, 2025

If I add the Offset i run into a problem of the sensor: it doesnt calculate VRMS if 0V isn't crossed if I add: mySensor.setBypassNenable(false, true);
It seems necessary that the sinus is without offset. This also leads to problems in my other project :-/
Yes the voltage is negative but there is no 0 crossing without negative voltage and the datasheet says -125 to 125mV.
The connections are correct.

Im really confused with the sensor since 3 days so if we resolve this this would help me really much.
Greetings Tobi

@PaulZC
Copy link
Collaborator

PaulZC commented May 28, 2025

Do you have an oscilloscope? If you do, probe the voltage between VINP and GND/VINN. Does it look sinusoidal? Or is it clipped?

Maybe try AC-coupling? Add a small capacitor (~10pF) between the waveform generator and VINP. Does that help?

@reinto1234
Copy link
Author

I have an oscilloscope, sine looks fine. The values stay the same. There is no offset.

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 2, 2025

Hi Tobi,

OK. Thank you. I will try to replicate this in the next ~2 days.

Best wishes,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants