TS-BAT10: Difference between revisions

From embeddedTS Manuals
(Fixed 5vdc indication being backwards)
Line 207: Line 207:
SW1 = 1 << 7,  
SW1 = 1 << 7,  
BELOW33V = 1 << 6,  
BELOW33V = 1 << 6,  
VDC5OK = 1 << 5,
NOVDC5 = 1 << 5,
BACKUPDISABLED = 1 << 4,
BACKUPDISABLED = 1 << 4,
BAT1CHARGING = 1 << 3,
BAT1CHARGING = 1 << 3,
Line 267: Line 267:
printf("Battery is below 3.3V\n");
printf("Battery is below 3.3V\n");


if(value & VDC5OK)
if(value & NOVDC5)
printf("BAT10 is recieving 5VDC Input OK\n");
else
printf("BAT10 is not receiving 5VDC\n");
printf("BAT10 is not receiving 5VDC\n");
else
printf("BAT10 is recieving 5VDC Input OK\n");


if(value & BACKUPDISABLED)
if(value & BACKUPDISABLED)

Revision as of 10:11, 20 April 2012

TS-BAT10
TS-BAT10.jpg
Product Page
Documents
Schematic

Overview

The TS-BAT10 is a PC/104 peripheral that contains two 4.2v 2200mA LiPo batteries wired in parallel to provide a high power battery back up system for Technologic Systems' Single Board computers as well as most other PC/104 SBC modules. The TS-BAT10 acts as both a regulator and a battery back up system, accepting from 5VDC to 30VDC and powering the entire PC/104 stack via the 5+VDC pins on the 64-pin PC/104 connector. The batteries are charged via two dedicated LiPo chargers that will charge the batteries until they reach 4.2 volts or for a maximum of a 6 hour charge time. Each battery has an indication of "charging", "charge complete", or "fault", these three states can be read from userspace by the SBC. Each battery can also have a slow 250mA charge current, or a fast charge 500mA current depending on the current source available.

Getting Started

Be sure to remove all power from the system and install a jumper on position 4 (battery backup disable) of the 2x4 pin header to disable battery power before connecting TS-BAT10 to a PC/104 stack. A jumper also needs be installed in one of the three address decode jumper positions. Exactly one address jumper must be installed, resulting in the TS-BAT10 using one of the following PC/104 address ranges:

  • 0x110-0x11F
  • 0x150-0x15F
  • 0x300-0x30F

On Technologic Systems ARM SBCs, that base address must be added to the 8 bit PC/104 base address for the particular system.

Operation

To use the TS-BAT10 for the first time, add it to a PC/104 stack, with jumpers installed as described above, and provide 5-28V DC on the power input connector. The TS-BAT10 will begin providing a regulated 5V to the SBC. The batteries will not be charging and will be disabled, and none of the status LEDs should be lit. JP4 can now be removed to allow battery backup. With JP4 installed, battery power will never be used.

Once battery backup is enabled, the TS-BAT10 will power the system any time external power is removed. The TS-BAT10 uses a boost regulator in order to boost the 4.2V DC provided by the two LiPo batteries to the necessary 5V DC for the PC/104 system. The input regulator for the external power supply requires at least 4.5V DC in order to provide power to the system. With an input voltage in the range of 4.5-5V DC the boost regulator will bring the voltage up to the proper levels.

Battery Charging Sequence

Once the TS-BAT10 is provided at least 4.5V DC, the host SBC can instruct the battery charging ICs to begin their charging cycle. Using the timers is highly recommended to provide safe charging. The timer on the charging devices is set for 6 hours; if this expires they will immediately stop charging and show a fault.

In order to begin a slow charge with the timers enabled, write 0x78 to the TS-BAT10 address space. Both red "charging" (CHG) LEDs will turn on. This will draw an additional 500mA (250mA for each battery) for the duration of the charge cycle. For a fast charge with the timers enabled, write 0x18 to the TS-BAT10 address space. This will cause the TS-BAT10 to draw an additional 1A of current from the external power supply (500mA for each battery).

The standard 5V DC @ 1A power supply from Technologic Systems will not be able to provide enough current to do a fast charge as well as provide power to the SBC. If the regulated 5V DC line slumps below 4.5V DC it will be unable to charge the batteries properly and will suspend charging until the proper voltage is available. When the power supply cannot handle the required current draw, software can instruct the TS-BAT10 to charge one battery at a time.

The charge controllers are intelligent and commands can continually be issued to the controllers to charge the batteries. They have automatic cutoff when the batteries are at the correct voltage. To maximize the lifetime (number of recharge cycles) of a battery, it is best to wait until the batteries report they are below 3.3V and then begin a full charge cycle. This is recommended for use cases where the system will only use the TS-BAT10 for power for a brief time while it does an orderly shutdown. Note that the battery charge controllers will not automatically begin a charge cycle; they must be commanded to do so via software.

Disabling Battery Backup Power

There are five conditions under which the batteries will be disabled from powering the system:

  • Valid external voltage is applied
  • The battery voltage is below 3.1V DC
  • A jumper in position 4 is installed
  • A large current draw has occurred and the regulated 5V DC drops below 4.45V DC
  • The battery backup is disabled by software

Battery backup functionality is enabled by default when the system is first powered up unless JP4 is installed.

LiPo batteries can be severely damaged if the cell voltage drops below 2.3V DC. In order to prevent permanent damage to the cells, the battery backup functionality is automatically disabled if the cell voltage drops below 3.1V DC. LiPo batteries hold their nominal voltage (in this case, 4.2V DC) through the length of their charge. The LiPo discharge curve will drop voltage sharply once the cells can no longer provide adequate current. There is a low battery register that indicates when the cells are below 3.3V DC. When the cells are less than 3.3V DC the LiPos will only be able to provide stable voltage for minutes at most. The recommended procedure is for the system to shut down when the batteries reach 3.3V DC and no external power is available.

The TS-BAT10 will ship with a jumper in position 4 to prevent the batteries from being drained during shipment. When this jumper is installed, the battery backup functionality will never be enabled; however, the batteries can still be charged using normal procedures.

The batteries and boost regulator can provide 4A of current. If that is exceeded under battery operation and the regulated 5V DC line drops below 4.45V DC, the batteries will immediately be disabled until the backup circuit is reset (see "Push Button" below) or external power is restored.

If the battery backup is disabled via software, the power to the PC/104 system will be cut if the external input power is cut. The software disable will reset to its enabled state when external power is re-applied. Power can also be restored to the system via the battery backup by resetting the battery backup circuit (see "Push Button" below).

Battery Notes

LiPo batteries can be severely damaged if the cell voltage drops below 2.3VDC. In order to prevent permanent damage to the cells the battery backup functionality is disabled if the cell voltage drops below 3.1VDC. LiPo batteries hold their nominal voltage (in this case, 4.2VDC) through the length of their charge. The LiPo discharge curve will drop voltage sharply once the cells can no longer provide adequate current. There is low battery detector that can be read to indicate when the cells are down below 3.3VDC. When the cells are less than 3.3VDC the LiPos will only be able to provide stable voltage for minutes at the most. The batteries CANNOT be used until they are charged above 3.1VDC.

Push Button SW1/CN1

A momentary switch is installed on the side of the TS-BAT10. This switch can be read by software (see "Register Layout" above) from the SBC to trigger a custom event. This switch is also used to enable battery backup functionality while power is cut and the battery backup has been disabled (via software, or if the regulated 5V DC dropped below 4.45V DC). Pressing and holding the switch for one second will cause the battery backup to fully take over and provide 5V DC to the PC/104 system.

The two pins labeled CN1, located immediately next to the push button, can be used to connect an external button. If the two pins are shorted together it has the same effect on the system as if the push button were depressed. This can be used to bring out the push button to the outside of an enclosure.

The push button, combined with the low battery state, can be used in a power management application. A userspace process can poll the register; if a low battery condition occurs, or if the push button is depressed, the system can be commanded to safely shut down.

Jumper Configuration

Jumper Function
1 Use 0x110 as base
2 Use 0x150 as base
3 Use 0x300 as base
4 Disable battery backup
CN1 Same as SW1.

Register Map

Status Register (Read only)

This register is available at (PC104 base) + (pins 1-3 TS-BAT10 Base) + 0

Read-only Status Register
Bit 0 0 = Battery 2 charge complete
1 = Battery 2 charge did not complete
Bit 1 0 = Battery 2 charging
1 = Battery 2 not charging
Bit 2 0 = Battery 1 charge complete
1 = Battery 1 charge did not complete
Bit 3 0 = Battery 1 charging
1 = Battery 1 not charging
Bit 4 0 = Battery backup disable jumper installed
1 = Battery backup disable jumper not installed
Bit 5 0 = input voltage not OK
1 = input voltage OK
Bit 6 0 = Battery under 3.3V
1 = Battery over 3.3V
Bit 7 0 = Push switch is being pressed
1 = Push switch is not being pressed
Note: bit 0-1 and 2-3 are also used to indicated a fault in charging. If they are both logic 1 (HiZ state) after initiating a charge cycle, either the timer has expired or the thermal cutoff of the batteries has engaged.

Configuration Register (Write only)

Write-only Configuration Register
Bit 0 0 = Enable battery backup
1 = Disable battery backup
Bit 1 0 = Enable battery 1 charge timer
1 = Disable battery 1 charge timer
Bit 2 0 = Enable battery 2 charge timer
1 = Disable battery 2 charge timer
Bit 3 0 = Disable battery 1 charge
1 = Enable battery 1 charge
Bit 4 0 = Disable battery 2 charge
1 = Enable battery 2 charge
Bit 5 0 = Charge battery 1 at 500mA
1 = Charge battery 1 at 250mA
Bit 6 0 = Charge battery 2 at 500mA
1 = Charge battery 2 at 250mA
Bit 7 Reserved

Example Code

This example simply prints whenever a value changes on the status register. It will also set the to batteries to charge fast. The Pc104 8bit IO base is for the TS-7800, but you can replace this with any other baseboard. If you are using a Ts-Socket or other board with a memwindow PC104, you will need to replace the peek and poke functions.

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

// This is for the TS-7800
#define PC1048BASE 0xEE000000
#define BAT10_OFFSET 0x110 // Assumes Jumper 1 is on

static int mem = 0;
void *base = 0;

void print_settings(uint8_t value);
void poke8(int offset, uint8_t value);
uint8_t peek8(int offset);

typedef enum
{
	SW1 = 1 << 7, 
	BELOW33V = 1 << 6, 
	NOVDC5 = 1 << 5,
	BACKUPDISABLED = 1 << 4,
	BAT1CHARGING = 1 << 3,
	BAT1CHARGED = 1 << 2,
	BAT2CHARGING = 1 << 1,
	BAT2CHARGED = 1 << 0
} StatusFlags;

typedef enum
{
	RESERVED = 1 << 7,
	BAT2NOFASTCHARGE = 1 << 6,
	BAT1NOFASTCHARGE = 1 << 5,
	BAT2CHARGEEN = 1 << 4,
	BAT1CHARGEEN = 1 << 3,
	BAT2TIMERDISABLE = 1 << 2,
	BAT1TIMERDISABLE = 1 << 1,
	SOFTDISABLE = 1 << 0
} ConfigurationFlags;

int main(int argc, char **argv)
{
	uint8_t bat10_status = peek8(BAT10_OFFSET);

	printf("======= INITIAL Status =======\n");
	print_settings(bat10_status);
	printf("==============================\n");

	// Begin fast charging both batteries
	poke8(BAT10_OFFSET, BAT1CHARGEEN | BAT2CHARGEEN);

	while(1)
	{
		uint8_t update = peek8(BAT10_OFFSET);

		if(update != bat10_status)
		{
			bat10_status = update;
			printf("======= Update Status ========\n");
			print_settings(bat10_status);
			printf("==============================\n");
		}
		usleep(500000);
	}

	return 0;
}

void print_settings(uint8_t value) 
{
	if(value & SW1)
		printf("SW1 is off\n");
        else
		printf("SW1 is on\n");
	
	if(value & BELOW33V)
		printf("Battery is above 3.3V\n");
	else
		printf("Battery is below 3.3V\n");

	if(value & NOVDC5)
		printf("BAT10 is recieving 5VDC Input OK\n");
	else
		printf("BAT10 is not receiving 5VDC\n");

	if(value & BACKUPDISABLED)
		printf("Backup is not disabled (JP4)\n");
	else
		printf("Backup is disabled\n");

	if(value & BAT1CHARGING)
		printf("Battery 1 is not charging\n");
	else
		printf("Battery 1 is charging\n");

	if(value & BAT1CHARGED)
		printf("Battery 1 is not charged\n");
	else
		printf("Battery 1 is charged\n");

	if(value & BAT2CHARGING)
		printf("Battery 2 is not charging\n");
	else
		printf("Battery 2 is charging\n");

	if(value & BAT2CHARGED)
		printf("Battery 2 is not charged\n");
	else
		printf("Battery 2 is charged\n");

}

void poke8(int offset, uint8_t value)
{
	if (mem == 0)
		mem = open("/dev/mem", O_RDWR|O_SYNC);

	if(base == 0)
		base = mmap(0,
	                getpagesize(),
        	        PROT_READ|PROT_WRITE,
                	MAP_SHARED,
	                mem,
        	        PC1048BASE);

	volatile uint8_t *addr;
 
	addr = (volatile uint8_t*)(base + offset);
	*addr = value;
}

uint8_t peek8(int offset)
{
	if (mem == 0)
		mem = open("/dev/mem", O_RDWR|O_SYNC);

	if(base == 0)
		base = mmap(0,
	                getpagesize(),
        	        PROT_READ|PROT_WRITE,
                	MAP_SHARED,
	                mem,
        	        PC1048BASE);

	volatile int8_t *addr;
 
	addr = (volatile uint8_t*)(base + offset);
	return *addr;
}