Battery Monitor: What Bench Testing Taught Me

Battery Monitor: What Bench Testing Taught Me

I put the battery monitor on the bench for two weeks at the end of August, and it turned into a much better learning experience than I expected. Mostly because almost everything I thought I already knew turned out to be wrong in some specific, checkable way.

Quick recap for anyone new here: the battery on my 1972 MGB GT lives under the rear seats. Checking it means taking part of the interior apart. So the plan is a small, always-on battery monitor that reads voltage, logs it, and can eventually tell me whether the alternator is charging properly, without a screen and without touching the original wiring.

None of it has been near the car. The MGB is still fully stripped down, so the only power source I have is a bench supply. This was all breadboard and bench testing.

The divider was wrong before I even started

The voltage divider, the pair of resistors that steps the battery's 12–15V down to something the ESP32's ADC can read, was the single most important part on the whole board.

The original divider values came from an earlier design, and they wouldn't work for what I wanted.

The original divider (37.4kΩ/10kΩ) saturated at 14.9V. My specification requires the monitor to detect an over-voltage fault above 15V. Thus, the monitor could not detect the fault that it was designed to detect. The maximum reading was 93mV below the fault limit.

I found this problem because I measured the saturation point on the bench.

The fix was a 47kΩ/10kΩ divider, which can measure up to approximately 17V. This is more than the charging system will usually supply.

Six runs, each one caused by the last

None of this was planned as a sequence going in. Each run happened because the previous one produced a number I didn't trust, or left a question I couldn't answer yet.

  1. Measure the ADC instead of quoting it. My design notes said the ADC's full scale was 2900mV. That number came from ESP32-S3 documentation, but my board has an ESP32-PICO-D4. The measured full scale was 3145mV. Different chip, different number, and I'd been calibrating against the wrong one. Not sure why I was looking at the wrong document.
  2. A calibration that looked good but was wrong. Calibration means working out the formula that turns an ADC reading into a battery voltage. I measured nine reference points with a multimeter, but only across a narrow voltage range. The formula matched those points closely (within 27mV), so it looked good. The problem was hiding inside the formula. It implied a divider ratio of 4.89, and resistors with 1% tolerance can only give a ratio between approximately 4.67 and 4.82. So the formula wasn't describing my actual circuit. It only fitted the small range I'd tested, and outside that range it went wrong: at 6V it was off by 192mV. A second calibration over a wider range fitted its points slightly less neatly, but its ratio (4.77) was one my resistors can actually have, and at 6V it was only 20mV off.
  3. The rebuilt input circuit. I installed the new 47k/10k divider, a 1kΩ series resistor, and two BAT85 Schottky diodes to clamp the ADC pin. The circuit did not saturate up to 17.1V. Noise decreased to less than 2mV. The calculated ratio (5.677) is now in the range that the resistor tolerances permit.
  4. 30 power cuts. I disconnected USB power during write operations, many times. The aim was to make sure that the log is not damaged when power is lost. Result: 31 of 31 mounts were correct, with no damaged records. Looked like a pass. It wasn't, more on that below.
  5. Power through the correct power path. Seven minutes on the buck converter, which, it turned out, every previous run had skipped. The specs claimed this configuration, but it had never actually been tested.
  6. The soak test. One hour, 3,357 samples, no resets. Write time stayed flat (1078→1080ms) as the log grew from 14kB to 102kB, so at least logging cost isn't going to grow with time. Voltage reading increased by 15mV during the first forty minutes as things warmed up.

Three things that broke, and what I learned from each

A 3.6V Zener diode took half the divider current.

I installed it as a last protection clamp on the ADC pin. It decreased a 12V reading to 7.3V. Working the maths backward:

  • The pin voltage should be 2.53V.
  • The reported value was equal to 1.54V at the pin.
  • The difference is 0.99V across the divider resistance.
  • This gives 126µA of leakage current. This is half of all the current in the divider.

Low-voltage Zener diodes have leakage current at voltages much lower than their rated voltage. On a high-impedance node, this leakage has the same effect as an unwanted resistor to ground. I replaced the Zener diode with two BAT85 Schottky diodes. Their reverse leakage is approximately one hundred times lower.

A test that passed but did not test anything.

The power-cut test gave 31 of 31 correct results. At first, I thought that this showed the design worked. But a damaged record was only possible during the write window. The write window was only approximately 4% of each cycle.

With 30 cuts, I expected only 1.4 cuts during a write. Thus, a result of zero failures had a probability of approximately 25%, even if the problem was real.

I did the test again with a 30% write window. The result was again zero failures. The probability of this result by chance is less than 1%.

This showed the real answer. LittleFS, the filesystem I use, writes each record as one complete operation. If a write stops, the file stays at its previous length. The failure that I designed the test for comes from an earlier design with an SD card. I did not check this assumption again when I changed the filesystem.

My own diagram caused a fault.

When I supplied power through the buck converter for the first time the output was 0.11V, but it should have been 12.6V. The cause was a TVS diode connected in series with the supply. It must be connected between the supply and ground (a shunt connection).

My architecture diagram shows the fuse, TVS diode, MOSFET and buck converter as four items in the same style. Three of these items connect in series. The TVS diode is a shunt item. The diagram did not show this difference, so I connected it incorrectly.

The other problems in this article are claims that I did not check. This problem is different: the documentation was wrong, and the wrong documentation caused the fault.

What surprised me

The largest surprise: my records showed five things as "working" or "complete" that had never operated.

  • The records showed a reference voltage as removed, but it was still in the code.
  • The records said that SD card logging gave real data. A test script on my laptop made that data. This build has never had an SD card.
  • The records called one firmware version the main version, but it could not compile for its target board.
  • The records showed the buck converter as the power supply for three runs. It supplied no power during those runs.

Each claim was specific and looked correct. Each claim stayed in the records after more than one review. This is the lesson I remember most: when a claim looks confident, people do not check it.

Two smaller surprises:

  • With no input connected, the ADC reads a constant 0.70V. This value is much lower than 6V, which is the lowest real battery reading. Thus, the monitor can detect a disconnected input with no additional parts.
  • A watchdog timer triggered during a log dump. I thought it had damaged my data, but it had not. The real cause was a print loop in my code. The loop stopped another task for nine seconds. The file in flash memory was correct. Only the serial output over USB was damaged. The watchdog was correct, and my first conclusion was wrong.

What the monitor can do now

My test target changed three times in two weeks. I want to be honest about this.

  1. The first target was seven days without supervision, on a car battery.
  2. Then it was a bench battery.
  3. Then it was 48 hours on the bench supply.
  4. The actual test was approximately 3,400 write cycles in one hour, with supervision.

Each change was reasonable at the time. But together, these changes removed the original endurance target.

Results that the tests confirm:

  • The monitor measures 6–16V with an accuracy of ±100mV. The calibration covers two thirds of the ADC range. I checked the calculated resistor ratio against the possible component values.
  • A power cut does not damage the log: 37 cuts, 38 correct mounts, zero damaged records.
  • The write time does not increase as the log gets larger: no significant change across approximately 3,400 writes and 88kB of log growth.

Results that the tests do not confirm:

  • Endurance. The longest continuous run was one hour.
  • Operation in a car. I did not test voltage drops during engine start, alternator noise, vibration or temperature changes. A bench supply cannot make these conditions.
  • Absolute accuracy. My reference meter is only accurate to ±100mV.

What happens next

Almost no physical part of this breadboard will go into the car. I will replace the development board, the evaluation-board converter and the resistors.

Two things will continue to the next design. The first is the firmware, which now measures correctly through a calibrated and tested path. The second is my documentation: twenty decision records and twenty-two findings.

This is the correct result. My first goal was to learn embedded systems design from start to finish. A working device was my second goal. The next step is not to complete this board. The next step is to draw the schematic for the board that can go in the car.