Hi Folks,
Could somebody explain that circuit (3)?
It's a latching circuit that works with only 1 GPIO.
The whole video is here:
I'm trying to figure out what that circuit does.
Step 1
So this is a P Channel MOSFET there:
When the device is first powered the gate of the MOSFET is pulled high.
So , OK it makes the MOSFET non conductive.
What is the capacitor for here ?
Step 2
As soon as the push button is pushed, it gives a path to ground.
So, OK it makes the P Channel MOSFET conductive because its gate is pulled to low.
So now the current can flow to Vin (and power the Arduino).
Step 3
First line of code of the Arduino would be to activate the GPIO pin as INPUT
and activate the pull-up resistor on that INPUT.
So it pulls up the gate of the N Channel MOSFET.
And that would maintain a path to the ground for the gate of the P Channel (the one on the top). So that P Channel MOSFET would remain conductive.
What is the R3 330Ω for ?
If we use the internal resistor of the Arduino, why do we need it ?
Step 4
It's mentioned the R2 1MegΩ is used to pull the gate of the MOSFET low when the device is off.
So I understand this works as a pulldown resistor to avoid floating input at the gate of the MOSFET.
So, if we have 5V at the pin when the Arduino is on
(with the internal resistor of the Arduino at 50KΩ):
Voltage between R3 and R2 = 5*(1MΩ/(1MΩ + 330Ω +50KΩ) ) = 0.95V
Is that enough to get the gate high when the Arduino is on ?
When the Arduino is off (floating input 5V for instance)
Voltage between R3 and R2 = 5*(1MΩ/(1MΩ + 330Ω) ) = 0.99V
Would that get the gate high when the Arduino is off and there is a floating input at 5V ?
Step 5
When the push button is pressed down again,
it gives a path to the ground.
What I don't understand is that it would set the input pin to LOW,
so the gate of the N Channel MOSFET would be pulled down.
And the first MOSFET would be back to non conductive state.
Or maybe the fact that the INPUT put has the internal resistor activated,
it keeps the gate of the N Channel MOSFET activated and
at the same time we can still read the input for the push button as LOW ?
Step 6
When we detect a long press,
we can switch the GPIO as an OUTPUT pin and drive it LOW.
This I understand would pull the gate of the N Channel MOSFET LOW.
So that would stop maintaining a path to the ground for the gate of the P Channel (the one on the top). So that P Channel MOSFET would be non conductive (back to conditions of Step 1).
I would appreciate if somebody could clarify what I'm missing out.
That'd be great.
Thanks.
Cheers!