Power management

After the PIC24 redesign, it has been my wish to use the realtime clock so that the reports to the serial port can be made with the correct time. Unfortunately when the processor loses power, the clock stops and the time is reset.

To get around this, I figured that I would use a battery and the low power characteristics of the microcontroller. When I designed the board I added the battery holder for a CR2032 and an LTC4411 from Analog/Linear to manage the switching between the power sources.

The LTC4411 is labelled as an "ideal diode" and has a reference design in the datasheet. I connected the "STAT" output to an input on the microcontroller so that the firmware can know when it is on wall power or battery.

For initial testing, instead of using the CR2032, I elected to use an external holder and 2 AA batteries, I could then use alligator clips to connect it to the battery holder. This also allowed me to connect an Ammeter in line so that I can measure the current and see the changes I am making take effect. Bear in mind that these measurements are all taken on my RadioShack 22-812 meter, I don't know how accurate it is, and I have never had it calibrated, but it does serve its purpose.

My first test was to see what the current draw is when the wall power was applied, as expected it was around 40uA. Then without making any code changes I switched the wall power off. The current from the battery jumped up to ~27mA, again not surprising due to the fact that I implemented absolutely no power savings.

I then changed the code to monitor the STAT input. This involved implementing a centralized interrupt on change dispatcher as both the knob code and the power management code (and in the future the buttons code) need use of the interrupt. The most reliable method I found was to poll the STAT pin and when it goes high issue the Sleep() instruction. During initialization, I configure the IOC to interrupt on the falling edge of the STAT input to pull the controller out of sleep.

With this change when disconnecting the wall power, the battery current went to ~10mA. Now it's time to really try to minimize the current.

For the next step, I implemented pause and resume functions for each module (buttons_pause and buttons_resume for example) and turned off the various things that might be consuming current. After turning off internal pull ups in the button code, the current dropped to ~3mA, but it then started climbing back up to ~7mA. I then went through the various modules to make sure that unnecessary interrupts were turned off and that brought the draw down to a steady ~2mA.

At this point, I got bored of this and called the initial implementation done. I need to revisit it so that I can get the current lower, according to the data sheet, 300nA is achievable.

Subject: