With the high-side DC power switch circuit working, there’s room to tweak things just a teeny bit further.
Summary: we’re switching DC power on and off through a MOSFET, and measuring the voltage drop across that same MOSFET with a bit of amplification to get better readout sensitivity.
Let’s add one more feature: the ability to detect whether a disk is connected. But first, the complete schematic:
The R1 resistor protects the op-amp from negative voltages, which occur when the MOSFET (Q1) is open and a device has been attached.
R2 and R3 put the op-amp in 11x amplification mode, referenced to VCC.
The C1 capacitor was added to smooth out the analog readings a bit (R1 + C1 form a low-pass filter).
The R5 resistor makes it possible to detect whether there is anything connected to OUT or not: when Q1 is open, R5 creates a pull-up, forcing the “+” side of the op-amp to VCC, unless there’s a device attached. At 1 MΩ, the pull-up is so weak that any device will pull it down to ground potential (keep in mind that Q1 is open). When Q1 is closed, then R5 no longer matters since it gets shorted out.
And lastly, R4 was added as pull-up to avoid a startup glitch as the JeeNode is powering up (i.e. while DIO is still floating). Note that Q1 will conduct when DIO is low.
Here are some readings under different conditions. These are referenced to VCC and converted to mV x 11, i.e. 0.3V under VCC on the op-amp “+” pin reads out as 3300. The three values are low, high, and averages, sampled 50 times over a 5 second interval:
- OFF, no device: 0 / 16 / 6
- OFF, device switched off: 9 / 48 / 16
- OFF, device switched on: 3280 / 3287 / 3280
- ON, no device: 0 / 0 / 0
- ON, device switched off: 0 / 0 / 0
- ON, device switched on, start: 1267 / 2761 / 2348
- ON, device switched on, stable: 925 / 1096 / 983
When OFF, there’s a clear difference between a device waiting to get power and no device at all, or one which has been physically switched off. When ON, the readout becomes proportional to the amount of current drawn.
According to the lab power-supply readout, the startup current goes to about 1A, and then once stable it drops back to about 380 mA. The device is a “Green Power” WD 500 Gb hard disk in a no-brand external USB enclosure.
This concludes the “high-side” experiment (all related posts have been collected on the wiki). For a stand-alone setup, it should work fine, but after all this floating ground trickery I’ve come to the conclusion that a COMMON ground setup will be more useful if this were ever to be turned into a plug…