3
\$\begingroup\$

I am working on a project that uses a PIC24F mcu. The power to my pic is backed by a very large capacitor (1F). When there is a main power loss, I can sense that immediately via a port pin but the PIC itself stays powered for several minutes via the capacitor as the charge in the cap slowly dissipates.

Once I detect that the main power is cut, I want to perform some actions (several micro seconds only) and then stop the PIC from doing anything else (sleep or hibernate i guess). But as the caps charge slowly dissipates the power to the pic will VERY slowly decrease below 3.3V down to zero. At any point, if the main power is re-applied, the pic should detect it at the Port Pin, and restart normal operation. I am wondering what would be the best way to handle this in software? I know that the PIC has Brownout detection and some kind of Low Voltage Tracking but I don't quite understand how to use them.

\$\endgroup\$
1
\$\begingroup\$

The easiest way to handle this is to add a pull-down to a pin that can be set up to interrupt on a change. Then put a diode from this pin to VIN and another diode from VIN to VCC. Then you will receive an interrupt when the VIN is removed where you can gracefully shut down and then goto PWRSAV #SLEEP_MODE. When power comes back the system will then get an interrupt which will take the part out of sleep mode. The diodes should be Schottky diode like a bat54c. The capacitor is use to filter out quick changes in VIN.


    PIN --o---|<|----- VIN  ------|>|----- VCC
          |
          o-----
          \    |
          /   ---
          \   ---
          /    |
          o-----
          |
         GND

\$\endgroup\$
1
\$\begingroup\$

Use the instruction "PWRSAV #SLEEP_MODE". This puts the chip into a power save sleep condition where it draws a few microamps. Remember to turn off peripherals before doing this, or they will draw current in sleep. This is a single cycle instruction.

You can set up pin change interrupts to wake the CPU from sleep.

\$\endgroup\$
  • \$\begingroup\$ If the device is in sleep mode, and power slowly drops, will the device "flicker" on and off? If if does will that cause a problem? If it momentarily turns off, then turns back on, will it start back up in sleep mode? \$\endgroup\$ – PICyourBrain Oct 7 '10 at 15:10
  • \$\begingroup\$ The device will not brown out (i.e. suffer a loss of memory and state) if the voltage is above about 2V (the minimum supply voltage.) In practice you could probably go as low as 1.8V before the chip resets completely. If power is lost in sleep mode it could reset, but it depends on what type of brown out (e.g. voltage dipping from 3V to 2.5V would be okay but from 2V to 0V or 2V to 1.5V probably not.) \$\endgroup\$ – Thomas O Oct 7 '10 at 16:08
1
\$\begingroup\$

When your devices power gets too low, your PIC will reset itself. If you have a certain state that you want your pic to be in when it comes back on, you could save settings to eeprom just before putting it to sleep. Then, every time your pic starts you can have it check eeprom for your state settings and act accordingly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.