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

Closed
reinto1234 opened this issue May 28, 2025 · 12 comments
Closed

RMS voltage calculation is incorrect #13

reinto1234 opened this issue May 28, 2025 · 12 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

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 3, 2025

Hi Tobi,

Which microcontroller board are you running the code on?

Best wishes,
Paul

@reinto1234
Copy link
Author

Hello Paul,
I'm running it on a esp32-wroom-32e-n16. For the Tests with the waveform generator I use a board like this: https://www.amazon.de/St%C3%BCcke-ESP32-Entwicklungsplatine-NodeMCU-Modul/dp/B0F446BHYJ?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A29LV1IQJB35CK . But my main application is on a self developed board.
Greetings Tobias

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 4, 2025

Hi Tobi,

I have tested the SparkX ACS37800 Qwiic Power Meter using a 12V isolating transformer and a 12V 5W bulb as the load. The measurements all look correct to me.

I used the SparkFun ESP32 Thing Plus C, running Example 5.

The transformer is rated at 12VAC 2A. The 5W bulb is only drawing 0.48A, so the voltage is much higher than 12V.

The circuit is:

  • Transformer (+) -> Power Meter IP+
  • Power Meter IP- -> Bulb (+)
  • Bulb (-) -> Transformer (-) and Power Meter LO pad

Measurements using an oscilloscope - before connecting the ESP32:
I see 58.4Vpp, 20.8VRMS

Measured using a "True RMS" multimeter (not a Fluke sadly...):
I measure 20.84VRMS

Measurements using an oscilloscope between VINP and VINN/GND at the ACS37800 pins:
40.8mVRMS
118.4mVpp

The SparkX Power Meter uses an 8200 Ohm sense resistor. The divider resistors are all 1M, 4M in total.

With the ESP32 connected, the Example 5 code is reporting:
20.70VRMS
0.48ARMS
9.84W
1.19VAR
10.01VA
Power factor 0.99 Leading (which is expected with a resistive load, with very little inductance)

I moved the multimeter into the circuit to confirm the current. It measured 0.48ARMS.

So, this all looks correct to me. I do not see the need for root-2.

I suspect your issue is caused by feeding the signal direct to the 37800 without using dividing / isolating resistors. I suspect the common ground is causing the negative voltages to clip.

I suggest adding a resistor divider to your circuit. Keep the resistances low: maybe 1K for the sense resistor and 10K for the divider resistors. Isolate the signal generator GND from the ACS37800/ESP32 GND through the divider resistors. You should be OK if the generator and your laptop power supply are both isolating.

Sadly this is all I can suggest. I hope this helps.

Best wishes,
Paul

@PaulZC PaulZC closed this as completed Jun 4, 2025
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