Controlled Shutdown of PIC via Supercapacitor

Thread Starter

dmarciano84

Joined Oct 1, 2023
36
I am attempting to design a temporary backup for a PIC MCU using a supercapacitor. The goal is that the MCU can detect when power is lost, perform its cleanup tasks, and then shutdown completely by disconnecting from the supercapacitor. I have never worked with supercapacitors or MOSETS (as I've never had a need) but I came up with this initial design. I am sure there are many problems with it and I am hoping I can get some feedback and guidance on what I am missing/need to change. This is the circuit.

1701269768560.png

My thought process was:
1. When the MCU turns on, it enables Q1 and Q2 via RD0 and RC0, respectively. Q2 is acting as a sensor for the main power via the emitter into RC1. When this drops (which the MCU will detect via a falling edge interrupt) it will know main power is lost and start shutting down. Q1 is also enabled so that the supercapacitor is also connected.
2. After the shutdown is completed, it will turn off Q1 by bring RD0 low, thereby disconnecting the supercapacitor from the circuit.
3. D1 is to prevent the supercapacitor from feeding back into the LM7805
4. D2 is to prevent the LM7805 from feedback backwards into the MOSEFT
5. C3 & C4 are the recommended decoupling capacitors from the datasheet
6. R1 is to limit the current into RC1 to 20mA
7. D3 is to ensure that Q2 is only detecting power from the LM7805 and not from the supercapacitor

As I said, I am sure there are multiple problems here so any help/guidance is greatly appreciated. TIA.
 

MrChips

Joined Oct 2, 2009
30,456
I don't know if you really need Q2, R1, R2.
It would seem to me that if you measured the voltage of the 7805 output or the voltage across D3 you can determine when you have lost 7805 power.
 

Lo_volt

Joined Apr 3, 2014
311
MrChips is correct. All you need to do is measure the supply voltage via an analog input on the PIC.

Note that your super cap will only be charged to 5 volts minus two diode drops and will supply the PIC via another diode drop as well as the drop across the MOSFET. Although, looking again, I wouldn't bother with D1, D2 or Q1. Is there some reason you think you'll need the MOSFET? Are you planning on using it to switch off power to the PIC? It's fine to charge the super cap from the regulator, but I don't see any need for D1 or D2. There's nothing that they are protecting.

D3 should stay to avoid any unnecessary load on the super cap.
 

Thread Starter

dmarciano84

Joined Oct 1, 2023
36
MrChips is correct. All you need to do is measure the supply voltage via an analog input on the PIC.

Note that your super cap will only be charged to 5 volts minus two diode drops and will supply the PIC via another diode drop as well as the drop across the MOSFET. Although, looking again, I wouldn't bother with D1, D2 or Q1. Is there some reason you think you'll need the MOSFET? Are you planning on using it to switch off power to the PIC? It's fine to charge the super cap from the regulator, but I don't see any need for D1 or D2. There's nothing that they are protecting.

D3 should stay to avoid any unnecessary load on the super cap.
1. The voltage drop isn't too big of a concern. The PIC says it can run from 2.8 - 5.5V, so even with a 0.5V drop across the diode (which seems to be the very high end for Schottky's) the voltage should still be fine to power everything.

2. The point of the MOSFET was so that after the PIC performs its shutdown sequence, it will turn of the MOSEFT and completely disconnect power, instead of just staying on until the cap is completely drained.

3. Regarding D2 I thought that would be necessary, or at least recommended, to ensure that current only flow through Q1. I wasn't sure though so I put it just in case.

4. Yes, I see now that the D1/D2 aren't needed. The circuit was originally slightly differently (i.e., the NPN was in front of the D3) and the PIC wouldn't be able to tell that main power was lost. I realized this and moved the NPN to before the D3, making the other diodes unnecessary and forgot to remove them.

I don't know if you really need Q2, R1, R2.
It would seem to me that if you measured the voltage of the 7805 output or the voltage across D3 you can determine when you have lost 7805 power.
Thinking about it more, I guess I could eliminate the NPN and simply connect the power to the pin since I don't actually need to know what the voltage is, simply when it drops to low.

Based on this feedback, I have modified the circuit as such:
1701274152557.png
 

MrChips

Joined Oct 2, 2009
30,456
There are two power loss situations, (1) total black out, and (2) brownout.
If you are only interested in black out, that would be fine.
I would use a voltage divider or a power loss detect IC for when supply voltage drops below a certain threshold or when the diode stops conducting current.
 

Lo_volt

Joined Apr 3, 2014
311
2. The point of the MOSFET was so that after the PIC performs its shutdown sequence, it will turn of the MOSEFT and completely disconnect power, instead of just staying on until the cap is completely drained.
The PIC16F18877 has a SLEEP mode that draws very little power. That may be an option instead of using the MOSFET. Otherwise, I like what you've got now.
 
Top