I was reading this thread
https://www.eevblog.com/forum/projects/power-bank-issues/msg3474652/#msg3474652 and it reveals the problem with using some of these power banks, thinking that they are only batteries. They decide to turn off if there is not enough current being drawn. A while ago, I bought a Jackery Giant+ - 12000 mAh and, although it does charge a phone, it is useless for powering small circuits…just like the thread talked about.
There was even a link to some newer packs with “Always On” technology…some interesting videos and so on. Consequently, I got the idea to build one for my pack and searched around. Many use a 555 type IC circuit which put me off a bit, not that there’s anything wrong with that
Here is a pretty nice one and I like the micro approach
https://blog.zakkemble.net/smart-power-bank-keep-alive/So, I thought I would try my hand at designing/programming/building one. Here is what I came up with so far, and, it works! I used what I had and what I knew how to do and what I could figure out.
Simple schematic (EDIT:
Corrected):
Simple program:
/*
* -> USE AT YOUR OWN RISK <-
*
* File: main.c
* Author: DrG
*
* Created on February 26, 2021, 12:06 PM
* MPLAB X IDE v5.40
* XC8 2.31
* DFP 1.4.56
* NOTE: Make sure that the backup reset condition flags option
* is selected under MPLAB X Project Properties > XC8 Linker > Runtime
* GP1 Current load
* GP2 on LED
*/
#include <xc.h>
#define _XTAL_FREQ 4000000
// These values worked for my Jackery
#define WDTcounts 12 //~2.3 sec / count
#define PULSETIME 150 // load presentation time (msec)
#pragma config MCLRE = OFF, CP = OFF, WDTE = ON
__persistent uint8_t counter;
void main(void) {
// these are needed for any resets
OPTION=0b11011111;
TRIS = 0b111001; // configure GP1 and GP2 as outputs
if( (__powerdown==1) && (__timeout==1) ){
// POR reset
GPIO = 0b000110; // GP1 and GP2 on
__delay_ms(1000);
GPIO = 0b000000;
counter=0;
}
else{
// it is a WDT reset
counter+=1;
if(counter==WDTcounts){
GPIO=0b000110; // GP1 and GP2 on
__delay_ms(PULSETIME);
GPIO=0b000000; // LEDs off
counter=0;
}
}
SLEEP();
}
By using the “lowly” PIC10F202, it is very easy to change the program parameters.
Normally, I would have programmed the 202 using asm. With MPASM going away, however, I felt like I either had to go to their new asm or try it in C. I chose the latter....C in that tiny space, heh - turns out that there is plenty of space to spare.
While it is a very simple program, I was completely unaware of how you get to the status register bits in XC8 and spent longer than I would like to admit proving that, indeed, XC8 has startup code (also present on any reset/restart) that smashes the status bits.
I was also completely unaware that XC8 allows a persistent variable type that will keep its value across a WDT reset from sleep. I might actually have been able to deliver enough current for the battery to stay on using just the three output ports on the PIC, but I decide that the 4401 would be a good idea in case I wanted/needed to increase the load for other batteries. I also did not know for sure how much current would be needed for this pack to stay on.
I have mclr disabled - so, POR, and WDT during sleep was all I needed to consider. The only other reset would, potentially, be from some kind of spurious pin change during sleep, but I would handle it as I would a WDT reset, so I am not even looking for it in code.
I tried to be systematic about figuring out the interval between no load and when it shuts down – hand timing it at first and then backing off the value for the WDT time out counts. So, hand timing and watching a meter, showed a shutdown at ~30 sec. Using the maximum WDT prescaler yields ~2.3 sec to time out. Thus, I decided on counting 12 WDT resets or ~27.6 sec before turning on the "load".
I also tried to be systematic about deciding on the duration of the load pulse. I ended up with 150 msec, which is longer than I would have thought, but at 100 msec, it showed inconsistent results.
It does what I wanted it to do, but now comes the hard part (for me)…getting it off of a breadboard and into an enclosure. I have lots of projects still sitting on breadboards…some of them even work