Yesterday’s post showed how with 3 resistors, one capacitor, and a P-MOSFET, you can set up a circuit to measure battery voltage with a voltage divider, even for voltages above VCC.
The whole point of this is that it can be switched off completely, drawing no current between measurements.
While trying this out, I started with a 1 MΩ pull-up on the P-MOSFET gate, and got this:
A very odd switch-off pattern, looked like an oscillation of some kind. Even with with the 100x faster switch-off using a 10 kΩ pull-up instead, the problem persisted:
This turned out to be a problem with the power supply. I was using a little USB plug with a switching regulator. These tend to work fine, but they do create a bit of “ripple voltage”, i.e. the 5V output is not exactly 5V DC. Here are the fluctuations, typical of units like these:
In other words: that little ripple was greatly amplified near the point where the P-MOSFET was starting to turn off, thus creating a regular but highly exaggerated turn-off pattern. Because – in a certain range – MOSFETs act like amplifiers, just like regular transistors.
It all went away when I switched to the lab supply, but it sure took some head-scratching…
Anyway, in real use this won’t matter, since the whole point is to use this with batteries.
You need to drive the DIO pin high after measuring VBatt, to get a clean, rapid turn off. And why waste energy waiting for the PMOS to turn off slowly?
That’s what I do. I toggle DIO between 0 and 1.