Smart charger and 5V portable power supply

 

SMART CHARGERNowadays almost every electronic gadgets are powered or recharged by a USB port (full size, mini o micro) as well as many of consumer products we use every day, including our smartphone. To recharge or give power to such products, there are many portable rechargers which have a rechargeable lithium battery and the electronics necessary to convert the battery voltage to 5V and to recharge the internal cell. The cost of these smart chargers is very affordable but we’re hardware makers, aren’t we? So why don’t to do it by ourselves to give power to our Raspberry Pi, arduino or Beaglebone black? We’ll show you a possible way to design one of these intelligent portable power supply.

Smart charger powering Raspberry Pi and chipKIT Pi. A metal candies’ box has been choosen for the prototype.

Smart charger powering Raspberry Pi and chipKIT Pi. A metal candies’ box has been choosen for the prototype.

We need three sections in our project: a step-up, a USB dedicated charging port controller and current limiting power switch, a lithium battery charger and a controlling section. There are many possible solutions for each of them; we’ve choosen LT1308A for the step-up, MCP73831 (500mA max) or LTC4054ES5-4.2 (800 mA max) for the battery charger, TPS2511 as the DCP and a PIC12F683 microcontroller to switch the battery between the charger and the power supply using TPS2061 and TPS2065C:

SCHEMATICThe C code for the PIC12F683 is very simple and it could be like this:

#include <xc.h>
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO
// oscillator: I/O function on RA4/OSC2/
// CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin INTERNALLY TIED TO VCC
#pragma config CP = OFF // Code Protection bit (Program memory code
// protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory
// code protection is disabled)
#pragma config BOREN = ON // Brown Out Detect (BOR enabled)
#pragma config IESO = OFF // Internal External Switchover bit
// (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit
// (Fail-Safe Clock Monitor is disabled)
#define LED GPIObits.GP2 // PIN 5 LED
#define USB GPIObits.GP5 // PIN 2 SHDN + TPS2069 (USB)
#define MINIUSB GPIObits.GP1 // PIN 6 ICSPCLK ENABLE TPS 2051 (CONNECT BATTERY TO MCP)
#define STAT GPIObits.GP0 // PIN 7 STAT TO CHECK IF BATTERY IS CHARGED
#define _XTAL_FREQ 32000
void main (void)
{
OSCCON=0b00000011; // 32 KHz
ANSEL=0; // ALL DIGITAL I/O
CMCON0bits.CM2=1;
CMCON0bits.CM1=1;
CMCON0bits.CM0=1; // COMPARATORE OFF
TRISIO=0b000001; // ALL GPIO OUTPUT EXCEPT GP0, WHICH IS INPUT
IOCbits.IOC0=1;
INTCONbits.GPIF=0;
INTCONbits.GPIE=1;
INTCONbits.GIE=1;
LED=1;
USB=1;
MINIUSB=1;
__delay_ms(1500);
if (STAT==0){
__delay_ms(10);
MINIUSB=1;
__delay_ms(10);
LED=1;
USB=1;
__delay_ms(10);
}
else {
USB=0;
__delay_ms(10);
LED=0;
__delay_ms(10);
MINIUSB=0;
__delay_ms(10);}
while(1){
__delay_ms(100);
asm(“sleep”);
}}
void interrupt pinchange (){
if (INTCONbits.GPIF==1){
INTCONbits.GPIF=0;
if (STAT==0){
MINIUSB=1;
__delay_ms(10);
LED=1;
__delay_ms(10);
USB=1;
}
else {
USB=0;
__delay_ms(10);
LED=0;
__delay_ms(10);
MINIUSB=0;}
}
}

 In order to use standard cables, we’ve decided to use USB port as power supply output and the mini USB to recharge the internal lithium battery.

Leave a Reply

Your email address will not be published. Required fields are marked *