Electronics > Projects, Designs, and Technical Stuff

(yet another) Power Bank Stay-On Circuit

(1/7) > >>

DrG:
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:


--- Code: ---/*
 *                    -> 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();

}

--- End code ---

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


Peabody:
That looks pretty good to me.  I just wonder if there might be a way to put the circuit inside the powerbank so you wouldn't have to mess with the connectors.  Of course then you would need an on/off switch for it.

I'd like to ask a question about the Zak Kemble circuit you found.  He has an opamp driving the gate of a P-channel mosfet as the load.  But this kinda violates everything I know about high and low side switching.  It seems it should be an N-channel mosfet.  With the P-channel, as the opamp turns it on, the source voltage would drop, which would turn it back off again.  But I've always been impressed with Zak's work, and he's selling the device on Tindie, so I assume it works.  But how?  Does the P-channel provide a kind of negative feedback for the opamp?

DrG:

--- Quote from: Peabody on February 27, 2021, 04:49:40 am ---That looks pretty good to me.  I just wonder if there might be a way to put the circuit inside the powerbank so you wouldn't have to mess with the connectors.  Of course then you would need an on/off switch for it.

I'd like to ask a question about the Zak Kemble circuit you found.  He has an opamp driving the gate of a P-channel mosfet as the load.  But this kinda violates everything I know about high and low side switching.  It seems it should be an N-channel mosfet.  With the P-channel, as the opamp turns it on, the source voltage would drop, which would turn it back off again.  But I've always been impressed with Zak's work, and he's selling the device on Tindie, so I assume it works.  But how?  Does the P-channel provide a kind of negative feedback for the opamp?

--- End quote ---

Since anything I make is a "prototype" :) I am likely to just slap it on a perfboard and try not to solder my fingers together....maybe I will add a couple of pieces of plexiglas or invest in some shrink wrap tape or some other fakakta method. But, I only need one and this one does what I want, so it is a success in my book....and that's always fun.

Yeah, it would be nice to fit it into the power bank in this video (he uses a 555 type circuit) he did that (although not much in the way of seeing it inside there.




I don't know enough about that aspect of Kemble's circuit, I am ok admitting that...I might be able to figure it out, but only after many hours. I have only used mosfets in 'very safe' and simple switches. His circuit is nice in that he is using a pot input to the 601 to control current. I'm sure that there are others around who could weigh in: toward that end, here is the schematic (from https://blog.zakkemble.net/smart-power-bank-keep-alive/ ):

Peabody:
I posted a question on his blog, and got this response:

"The circuit is a typical constant current source, but without an output load which then makes the MOSFET the load, dissipating all of the power. The load would normally sit between drain and ground."

I guess to me it's a constant (or adjustable) current sink, which would call for an N-channel mosfet.  But it may be that his design makes the pot adjustment a lot less touchy.  If I have time I'll breadboard it and see how it behaves.

wizard69:
funny how I came across these keep awake circuits this week.   In any event if the power bank is to be used to power your own circuits, would it not make sense to integrate the keep awake tech into your custom project?   It is one thing if the circuit is to be used to power a cell phone or other closed device, but if you are building a project that will use a power bank it would seem to me that the project should take care of its power needs.   It would save the stress of finding the cable or modifying the pack.

In any event throwing a microprocessor at this, with the simple circuit you have, sets an example.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version