Author Topic: Trying to understand purpose of a component in this soft-power circuit  (Read 1322 times)

0 Members and 1 Guest are viewing this topic.

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1480
  • Country: gb
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.
 

Offline Obin

  • Contributor
  • Posts: 38
  • Country: be
  • Hi
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.
« Last Edit: July 28, 2022, 02:15:13 pm by Obin »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2008
  • Country: us
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.

 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21696
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Where did you find this circuit?
 

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1480
  • Country: gb
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!).

Yes, 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.

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?

Don'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.

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.

GPIO17 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.)

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+).

Q2 is going to be a 10A-rated SO-8 MOSFET, so hopefully a big-enough bastard. ;D 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.

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.

I see what you mean about the potential short-circuit path. I'll move the fuse. :-+

Where did you find this circuit?

This is the circuit used (with minor variation) in the Pimoroni 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. There must be 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. :-//
« Last Edit: July 29, 2022, 11:55:11 am by HwAoRrDk »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2008
  • Country: us
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.
« Last Edit: July 29, 2022, 01:58:44 pm by Peabody »
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3367
  • Country: nl
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.
 

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1480
  • Country: gb
Found this:

https://github.com/tdamdouni/Raspberry-Pi-DIY-Projects/blob/master/_WebArticles/on-off-shim-notes.md

See where it mentions the weak 10M pull-up.

Thanks. :-+ 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 resistor doesn't prevent 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's actually doing 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!

Also, it seems the entire circuit driving GPIO17 could be replaced by a single diode if its internal pullup were enabled.

It 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.
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2008
  • Country: us
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.
 

Offline Bud

  • Super Contributor
  • ***
  • Posts: 6912
  • Country: ca
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.
Facebook-free life and Rigol-free shack.
 

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1480
  • Country: gb
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.

The Raspberry Pi documentation says: "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 found here, 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.

Maybe there'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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf