← Back to the notebookPower meter
A working note

Why am I subtracting 1.65?

There are two different midpoint methods in the saved code. The smaller RMS sketch subtracts 1.650 V from voltage and 1.651 V from current. The final sketch collects the raw readings first, calculates a separate mean for each channel, and subtracts that mean before converting the centred values. I find the difference useful because it gives the subtraction an actual job. It’s not just a line that makes an output look more reasonable.

The signal is shifted around a middle value so the ADC can work with it in the intended input arrangement. That shifted signal is what the ADC reads. The AC part I’m interested in is the change around the middle, not the middle itself. If I forget the shift, I can get a digital reading that is perfectly understandable as an ADC-input voltage but interpret it incorrectly as the changing part of the sensor signal. Those are different quantities even though both can be written in volts.

The value 1.65 makes sense as half of 3.3. That relationship gives me an idea of the intended midpoint. A number in the code is a statement about what the program assumes. The circuit has its own behaviour. I need to connect the assumption to the arrangement rather than let the familiar division replace that question.

I'm trying a small numerical example on paper. I used these values to follow the calculation. In this case, the ADC-input voltages are 1.55, 1.65 and 1.75 volts. Around a midpoint of 1.65, the changes are minus 0.10, zero and plus 0.10 volts. That’s the part I want to keep when I'm discussing the changing signal. The three original values are all positive. The three centred values describe movement on both sides of the middle.

Now I can see what goes wrong if I forget the subtraction before calculating RMS. Squaring the original values gives numbers dominated by the 1.65-volt shift. Taking their average and square root gives roughly 1.652 volts for this little set. If I first subtract the midpoint, the squared values are 0.01, zero and 0.01. Their average is about 0.00667, and its square root is about 0.0816 volts. Those two RMS answers describe different things. The arithmetic in both can be correct while only one answers my intended question.

The example also helps me avoid a misleading explanation. I don't subtract 1.65 because it makes the final number smaller and therefore more believable. I subtract the appropriate midpoint because I want the signal relative to that midpoint. The reason comes before the appearance of the answer. Otherwise I might start treating offset removal as a general trick to make a meter display look right, which would make it difficult to recognise when the middle value itself needs investigation.

The later log supplies a concrete scale check too. A value of 13190 counts at 0.125 millivolts per count is 1648.75 millivolts, or 1.64875 V. That’s close to the nominal midpoint, but it is not itself the changing AC component. A centred value answers how far the signal is from its middle; a sensor scale then relates that change to the original quantity. Keeping those meanings separate makes the small subtraction much more interesting than remembering the digits.

The next question is what happens if the assumed midpoint differs from the actual one. If the signal is centred at 1.60 volts but I subtract 1.65. Then even a signal with no change around its own middle leaves a residual minus 0.05 volts in my calculation. Squaring doesn't make that leftover disappear. It becomes part of the RMS result. That’s why a small mismatch can matter. The calculation is doing exactly what I told it to do; my assumption about the signal is the part that needs checking.

I need to keep offset and scale separate. Offset is about the starting level or middle that I remove. Scale is about how a change at one stage corresponds to a change in the quantity being measured. If I multiply an incorrectly centred signal by a different constant, I may change the size of the mistake without correcting its origin. It’s tempting to put everything under calibration and move on. Splitting the questions makes it easier to understand what each adjustment can and cannot do.

The final program gives the mean-estimation approach a definite sequence. It adds each channel's raw readings, divides by TOTAL_SAMPLES and subtracts the resulting mean, cast to int16_t, before computeVolts. The smaller sketch instead subtracts fixed voltages after conversion. Those are different implementations of centring, with different assumptions to examine. An estimated mean still depends on the collection it came from; naming it an offset does not remove the sampling question.

This brings the ADC range back into the question. The shift and the signal together must fit the intended physical input limits and the chosen measurement arrangement. Selecting a conversion scale in software doesn't make every imaginable input safe or meaningful. I want to understand the actual signal range before treating the ADC as a general box that accepts whatever number an equation produces. The circuit has limits that the program can't remove by printing a different unit.

What I enjoy here is that the maths is small enough to do by hand, while the meaning reaches through the whole meter. Three values can show me why the offset must be understood before the next calculation. Then I can return to the full loop and ask whether the same reasoning is present there. It feels much more satisfying than remembering that one line should say minus 1.65 and being unable to explain it when somebody asks.

I can now locate both approaches and explain their purpose. The midpoint positions the input signal; centring isolates the change the AC calculation is meant to describe.

Leaving this here for next time.All the notes ↗