logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Notes index links

Links to all my notes (includes mini-projects and source code etc)

(+) 0001 How do I change the Pi System partition size ?

(+) 0100 Device tree settings

(+) 0201 Power over Ethernet - (PoE)

(+) 0202 Solar Power - (with WiFi)

(+) 0203 Power Bank pass through

(+) 0400 Accessing the SDHC card system image

(+) 0401 Accessing PC shares from the Pi

(+) 0402 Installing samba - (the Pi as a Network Share on your PC)

(+) 0900 Can this approach be scaled up to a PC UPS ?

(+) 1001 Pandora Spotify on the Pi

(+) 1002 Playing movies on the Pi

(+) 1003 Getting VGA from the HDMI socket

(+) 1004 Using the RCA socket

(+) 1005 Using the Pi RS232 serial links

(+) 1006 Using the GPIO pins

(+) 1007 Controlling the Pi Zero ACT LED

(+) 1200 List of standard camera modes

(+) 1300 Auto file names

(+) 6500 How to make the System partition read only ?

(+) 6501 Minimising SDHC corruption on power down

(+) 9000 diode switch

(+) 9001 Auto shut down



(-) 9001 MOSFET switch


How the MOSFET switch works
A simple 'diode switch' passes whichever of 'mains' or PowerBank voltage is the higher. This is fine when we can guarantee (or set) the 'mains' voltage (when present) to be higher than the PowerBank voltage.

However, a USB mains power block voltage is fixed and (whilst adequate) might well be less than the PowerBank voltage. This would mean Vmains is applied to the PowerBank at the same time as VpwrBank is passing power to the Pi - and since a low cost PowerBank does not support 'output' at the same time as 'input', at the very least you can expect it to 'glitch off'.

We thus have to 'detect' Vmains and immediately 'switch off' VpwrBank.

This makes for quite a complex circuit, because it's not just a matter of 'switching' whenever Vmains is present - instead we have to detect when Vmains is high enough to actually run the Pi.

To control the PowerBank output, a (p-channel) MOSFET can be used. To enable the PowerBank the MOSFET Gate has to be driven toward 0v and to disable it, toward 5v. So if we wire Vmains input to the Gate, when the mains is absent (near 0v) the PowerBank will be switched in, and when Vmains is present (near 5v) the PowerBank will be switched out.

Whilst this 'switches to Vmains' when the USB power-block is plugged in, there is a problem when the USB power block is unplugged.

The MOSFET only 'switches on' when it's Gate voltage falls below the Gate-Source 'Vthreshold' voltage. With the Vthreshold of a typical 1A p-channel MOSFET - the NDS356AP - of about 1.6v, this means the PowerBank will only 'turn on' when Vmains drops below VpwrBank-1.6v i.e about 3.4v. Since Vpi will be Vmains-.3, by the time the MOSFET turns on, Vpi will have reached about 3.1v .... and the Pi will have crashed long ago.

So it will be necessary to 'detect' when Vmains is 'too low' to power the Pi, and use that 'detect' to switch between Vmains and VpwrBank. The simplest way to 'detect' voltages is to use a Zener diode. If the Pi needs at least 4.75v and the (dual) Schottky diode voltage drop is .3v, then the 'detect too low' voltage will be 4.75 + 0.3 = 5.05v, so using a 5.1v Zener is 'safe'. 

To drive the MOSFET we can't just wire Vmains+Zener to the Gete. Instead an OpAmp is used to do the compare and amplify the difference (so the MOSFET Gate is switched rapidly from 0v to 5v). Since the OpAmp is powered from Vmains, we need to tie the MOSFET Gate to Gnd (so it turns on when the OpAmp is un-powered)

Photo: ../Raspberry_Pi/photos/PwrBank-MOSFET-switchover-cct.gif
If the USB mains power block is unplugged when switch SW-1 is closed, the OpAmp will be un-powered and it's output 'hi-impedance', so R4 will keep the MOSFET Gate close to GND. This means the MOSFET will pass VpwrBank to Vpi.

When the USB mains power block is plugged in (irrespective of the SW-1 state) the OpAmp will power up. So long as Vmains is less than 5.1v, the Zener will not conduct. This means the '+' input of the OpAmp will be held to Gnd via R3. The '-' input, however, will rise to a voltage above Gnd set by the voltage divider formed by R1 and R2 (the actual voltage will be approx. Vmains/1000, however even this small voltage should be enough for the OpAmp to drive it's output to Gnd, and thus keep the MOSFET 'on').

When Vmains exceeds 5.1v, the Zener starts to conduct and the '+' input rises to Vmains-5.1. When the '+' input (Vmains-5.1) rises above the '-' input (Vmains/1000) = which will happen when Vmains exceeds about 5.11v = the OpAmp output will swing from Gnd to Vmains and the MOSFET will turn off.

With the MOSFET 'off', Vpi will be driven to Vmains-0.3 i.e. at least 5.11-0.3 = 4.81v. So long as Vmains stays above 5.1v Vpi will follow Vmains-0.3.

If the mains power block is unplugged, when Vmains falls below 5.11v the OpAmp output will swing from Vmains to Gnd and the MOSFET will turn on again. The Pi will remain powered by Vmains or the PowerBank until SW-1 is opened.

Notes.
1) You will, of coure, require an OpAmp that works down to at least 3v (eg. LM358) or the MCP6001 (which operates down to 1.8v)
2) The MOSFET D-S 'body diode' has a Vf of about 2v, so can be ignored so long as Vpi is never more than 2v above PowerBank.

This note last modified: 9th Oct 2016 06:42.

[top]

(+) C201 High speed photos

(+) Dec 1969 (no desc)

(+) a000 Display setup - (for PhotoFrame)

(+) a001 go photoframe - (how it works)

(+) a002 set photo - (select for display)

(+) a003 go button script - (photoframe pause control)

(+) a005 get photos - (fetch resize)

(+) a00x Other display utilities

(+) c000 CCTV UPS requirements

(+) c001 countering low speed motion detect

(+) c002 Pi Overclocking

(+) c203 Pi ram disk - (tmpfs)

(+) c901 iR illumination

(+) c902 Viewing a video stream

(+) c905 Image anotation

(+) Dec 1969 (no desc)

(+) raspicamdocs.txt (no desc)

(+) s010 Elevation sensing

Next subject :- index

[top]