Trying to understand purpose of a component in this soft-power circuit - Page 1
Forum section: electronics / beginners

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 28, 2022, 01:55:05 pm
content: I've been trying to understand what the purpose is of a particular component in this soft-power circuit used for power-on and safe power-off of a Raspberry Pi.The component in question is the 10M resistor R14. I cannot fathom what its purpose is. Its existence doesn't seem to make any sense.My initial thought was that it is acting together with C12 to provide a delay before Q3 is turned on (determined by Vgs(th)), but 10M in combination with 4.7uF is far, far too big of an RC delay, and would mean the user would have to hold S1 for many, many seconds. What I think is instead charging C12 is the default state of the Pi's GPIO4, which is a pulled-up input. I believe the internal pull-ups on a Pi are approx. 50-65k, which makes a more reasonable couple of hundred milliseconds.So what is R14 doing? Is it somehow compensating for some initial period where GPIO4 is in an indeterminate state and doesn't have the default internal pull-up enabled, saving the gate of Q3 from flapping around, counteracting the button press?If anyone has any ideas, please tell.

author: Obin
author_rank: Contributor
timestamp: July 28, 2022, 02:03:41 pm
content: First and foremost, it's providing a barrier between +3V3_PI and GPIO4. If no resistance would be present, they would be shorted, and pin 1 on Q3 would always be high. The RPI would also have trouble toggling GPIO4, since it's trying to force down its own +3V3_PI.The value is very high (10M) because only a small amount of current is necessary to handle Q3.So yeah, as long as GPIO is undetermined, it keeps pin1 of Q3 at 3V3.C12 is there as a "debouncer" i'd reckon, keeping away any high frequency nonsense from pin1 of Q3.

author: Peabody
author_rank: Super Contributor
timestamp: July 28, 2022, 06:01:08 pm
content: But if everything starts at ground, when power comes up it's going to take a long time for C12 to charge up enough to turn on Q3. So it appears to bias the power off for a long time unless the button is still being pressed, or GPIO4 goes active high. Maybe it has something to do with powering down. Still a mystery.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: July 28, 2022, 09:14:40 pm
content: Without knowing what the signals are, it's anyone's guess.If the purpose is to start an MCU, and if there is a 3.3V regulator from the +5V_PI, and +3V3_PI is derived from it, and the MCU itself is powered from same, or something closely related; then: it might be a minimum on-time for S1, so you have to press and hold for... well about 47 seconds, or less if the MCU forces GPIO4 high sooner (hopefully with a pullup resistor, so it doesn't have to source/sink short-circuit current into that fat bastard 4.7uF!).Note that D5+R11 acts to turn off Q2, if Q3 hasn't turned on yet. I don't really know why, perhaps they thought it necessary to somewhat decrease turn-off time?Q4 is also turned off immediately on switch press; presumably GPIO17 is a wake signal, or maybe a confirm-power-off signal. You'd think +3V3_PI going up would be reason enough to wake, but... again, can only go on assumptions here.Note that Q2 needs to be a pretty big bastard itself, to have any hope of clearing a 2.5A fuse. Not to mention the +5V supply, likewise. This will never open on a typical 5V supply e.g. USB or net rated charger/PSU, which will brown out before opening a fuse. Which may lead to excess power dissipation in Q2 (as it can only pull down to -Vgs(th) plus a bit). It will be useful when the power supply has excess capacity (enough to clear the fuse, say 10A+).I'd rather the fuse be placed at the inlet, since the purpose of a fuse is almost always to protect the wiring, and there is a potential short-circuit path through Q2 and Q3 (transistors typically fail as three-way short when they do, at least until their bondwires or leads fuse). If for current limiting, I'd much rather just use a USB style load switch with integrated current limiting, ditch the discrete circuit.Tim

author: ledtester
author_rank: Super Contributor
timestamp: July 29, 2022, 04:36:47 am
content: Where did you find this circuit?

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 29, 2022, 10:27:32 am
content: Quote from: T3sl4co1l on July 28, 2022, 09:14:40 pmYes, it's intended to provide startup and controlled shutdown of a Raspberry Pi board. The +3V3_PI is generated on board the Pi, derived from the incoming +5V_PI - so, the 3.3V doesn't come up until the Pi is powered on.As I said previously, yes, I do believe there is supposed to be a minimum 'long press' on-time that S1 needs to be pressed for to initiate a power on. But as you say, 47 seconds would be ridiculous! It's my understanding that it is indeed actually an internal pull-up resistor on GPIO4 that is sourcing the current to charge the 4.7uF of C12. The Raspberry Pi technical documentation says that all GPIOs are inputs by default at reset, some with pull-up, some with pull-down; GPIO4 has a default pull-up (of approx. 50-65k).So given that, I don't believe R14 is acting in any way to provide this minimum on-time for S1.Quote from: T3sl4co1l on July 28, 2022, 09:14:40 pmDon't you mean "turn on" Q2? It is a P-channel MOSFET... Unless you meant "turn off" the gate, as in pulling the gate to ground.Edit:I've just realised while playing around with the simulator that D5 & R11 don't appear to be strictly necessary - if that's why you were questioning them. It seems to work fine without them, although I'm thinking that perhaps they're present to provide plenty of wetting current through S1 - 5mA versus 45uA.Quote from: T3sl4co1l on July 28, 2022, 09:14:40 pmGPIO17 is intended to be an input to read the state of the power switch once the Raspberry Pi has booted up. At that point it is used as a shut-down signal. The idea is that you run a software daemon on the Pi that monitors the state of GPIO17, and if it finds the button has been held down (i.e. GPIO17 is high) for >1s, it initiates a controlled shut down of the system. The init system is also configured such that the very last thing the Pi does on shutdown is toggle GPIO4 from a pulled-up input to a low output, which dumps the charge from C12, shuts off Q3, which in turn shuts off Q2, cutting power to the Raspberry Pi.(As I write this, I realise a series resistor should be added between GPIO4 and C12. IIRC, the GPIOs aren't rated to sink much current - something like 16mA - so dumping 4.7uF of charge through GPIO4 probably isn't a great idea. Will probably add a 1k resistor here.)Quote from: T3sl4co1l on July 28, 2022, 09:14:40 pmQ2 is going to be a 10A-rated SO-8 MOSFET, so hopefully a big-enough bastard.Likewise, the supply should be capable of around 5-6A. I would use a fast-blow fuse here too. I only added the fuse because the Raspberry Pi 4 actually ditched the on-board fuse (earlier models include a Bourns 2.5A MF-MSMF250/X), so thought it'd be prudent to have one on the off-board supply instead.Quote from: T3sl4co1l on July 28, 2022, 09:14:40 pmI see what you mean about the potential short-circuit path. I'll move the fuse.Quote from: ledtester on July 29, 2022, 04:36:47 amThis is the circuit used (with minor variation) in thePimoroni OnOff SHIM. I actually found the circuit schematic first, posted on a forum, and only later found it was from this product.By looking at the photos of the PCB on that page, I can see that it does indeed actually have a 10M resistor populated. Theremustbe a reason why they designed it like that.I've since been simulating the circuit:link.If I completely remove the 10M resistor (and its connection to 3.3V), the circuit functions perfectly well without it. So I am still mystified as to the purpose of this resistor.

author: ledtester
author_rank: Super Contributor
timestamp: July 29, 2022, 12:34:49 pm
content: Found this:https://github.com/tdamdouni/Raspberry-Pi-DIY-Projects/blob/master/_WebArticles/on-off-shim-notes.mdSee where it mentions the weak 10M pull-up.

author: Peabody
author_rank: Super Contributor
timestamp: July 29, 2022, 01:31:05 pm
content: I still don't understand. How would the GPIO become disconnected if the 3.3V rail is still present?And what exactly does D5 do?Also, it seems the entire circuit driving GPIO17 could be replaced by a single diode if its internal pullup were enabled.Edit: Looking at the SHIM picture, it seems the 3.3V regulator is on the SHIM, not the Pi. Or at least it looks like a regulator. It's still a puzzling circuit.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: July 29, 2022, 01:50:15 pm
content: The function of R14 can be explained in this way:If GPIO4 does anything, it will override the 10M resistor, so it only does something when GPIO4 is not active.And that is only when the Raspi is off, and +3V3 is not present.In that case it keeps the gate of Q3 low.I assume GPIO4 is a 5V tolerant pin, and it may float upward without R14.If GPIO4 has a normal ESD diode to +3V3, then this will probably keep the gate of Q3 low enough to prevent it from turning on.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 29, 2022, 01:53:31 pm
content: Quote from: ledtester on July 29, 2022, 12:34:49 pmThanks.It says:"OnOff SHIM has a weak ~10Mohm onboard pull-up resistor to prevent the need for a long press. Otherwise without the shutdown pin connected it would be floating and potentially subject to random noise induced shutdowns."The whole statement doesn't make any sense.First, the 10M resistordoesn'tprevent the need for a long button press to turn on. The mere existence of the 4.7uF cap ensures that some kind of extended period of button press is necessary. My simulation of the circuit proves this.Second, I understand the principle that the gate of Q3 will be floating without the resistor (because drain and source of that FET are always connected to un-switched 5V and ground, but gate is otherwise effectively unconnected when Pi is un-powered), but I still doubt whether it'sactuallydoing anything, because the 3.3V it's nominally pulling up to isn't live until the Raspberry Pi is powered on, when the Pi's GPIO4 internal pull-up (~50k) will then be in effect anyway!Quote from: Peabody on July 29, 2022, 01:31:05 pmIt needs some kind of voltage level translation between 5V and 3.3V. But I think I know what you mean, I'll try simulating it. It will invert the 'button down' logic level from high to low, though.

author: Peabody
author_rank: Super Contributor
timestamp: July 29, 2022, 02:06:34 pm
content: The diode would block 5V, so the push button can only bring GPIO17 low when pushed. Otherwise the internal pullup will keep it at 3.3V.

author: Bud
author_rank: Super Contributor
timestamp: July 29, 2022, 02:09:39 pm
content: Are you sure GPIOs internal pullups are hardwired and always on? Most of MCUs can have IOs in high impedance state (disconnected) until internal pullups are configured as part of code execution. Therefore 3.3V will turn on at power on but GPIOs remain floating until configured.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 29, 2022, 02:56:28 pm
content: Quote from: Bud on July 29, 2022, 02:09:39 pmTheRaspberry Pi documentationsays:"All GPIO pins revert to general-purpose inputs on power-on reset. The default pull states are also applied, which are detailed in the alternate function table in the ARM peripherals datasheet. Most GPIOs have a default pull applied.".Documentation of the default pull states can be foundhere, where it can be seen that the default pull for GPIO4 is up, and GPIO17 is down.So, unless configured otherwise at run-time, all GPIOs default to inputs with virtually all having a defined pull up/down enabled.Maybethere's a very brief period between power being applied and the BCM processor coming out of reset? And that is what the 10M pull-up is handling? But then surely that would be only a few milliseconds at most, during which period the user will still have their finger on the button anyway, meaning that if Q3 flaps around, it doesn't matter.