Skip to content
Build Documentation2SVII Internal Work

Building a mains power quality logger for unstable grid supply

An isolated voltage and frequency logger built to characterise supply quality at sites where equipment was failing without explanation.

Author
Samuel Okine2SVII, co-founder
Published
Reading time
2 min

Equipment at two sites was failing at a rate the supplier could not account for. The suspicion was supply quality, but nobody had measurements — only the observation that failures clustered after outages. This build was to get the measurements.

The first approach was unsafe

The obvious cheap design is a resistive divider straight into an ADC input. It is documented widely and it is the wrong answer here: it bonds the logic ground of the device to mains neutral. That is tolerable where neutral is reliably at earth potential. At these sites it was not, which is part of why we were measuring in the first place.

Splitting the measurement

Magnitude and timing turned out to have different requirements. Magnitude needs amplitude accuracy but tolerates latency; frequency and dropout detection need edge timing but almost no amplitude resolution. Measuring them with one front end meant paying for both properties in a single expensive part.

Magnitude path
Split-core current transformer into a burden resistor and a 12-bit ADC. Isolated by construction, no galvanic path to the logic side.
Timing path
Optocoupled zero-cross detector into a hardware capture input. Gives cycle-accurate frequency and unambiguous dropout timing.
Observed supply behaviour, site A, 14-day window.
MeasurementValue
Nominal voltage230 V
Observed range184 – 261 V
Excursions beyond ±10%312
Dropouts under 200 ms47
Longest continuous outage6 h 41 m

The 47 sub-200-millisecond dropouts were the finding that mattered. They are too short to register as an outage to anyone on site, and long enough to reset equipment mid-write. The failure pattern stopped being mysterious.

Open questions

  • CT calibration drift over temperature is being tracked monthly and is not yet characterised.
  • Three units is not a sample. These figures describe two sites, not a grid.
  • The logger records; it does not yet correlate against equipment failure timestamps automatically.

Build log

Prototype
  1. 01Resistive divider, direct ADC sample

    Sampling the divider directly against the microcontroller ground tied the logic ground to mains neutral. Safe only while neutral genuinely is at earth potential, which at these sites it was not. Abandoned before any extended run.

    Failed

  2. 02Isolated amplifier front end

    An isolation amplifier fixed the safety problem and worked, but part cost dominated the build and the gain drift over temperature was worse than the specification implied.

    Superseded

  3. 03Current transformer + optocoupled zero-cross

    Splitting the measurement — a CT for magnitude, an optocoupled zero-cross detector for frequency and dropout timing — removed the galvanic path entirely and cut part cost by roughly 60%.

    Succeeded

  4. 04Extended deployment

    Three units running since February 2026. Calibration drift is being tracked monthly.

    In progress

Editorially Reviewed Contribution

Measuring firmware power draw without a lab bench

A contributor's method for getting usable sleep-current measurements from battery-powered firmware using commonly available equipment.

1 min read

A. Contributor · Journal