Battery Montor


Home


 
Kits are available for this project from
Talking Electronics for $10.00 plus postage.


PIC12F629 Data Sheet (.pdf  4,926KB)
Instruction Set for PIC12F629
blank12F629.asm template

PIC12F629.inc

See more projects using micros:
Elektor,EPE,Silicon Chip

Notepad2.zip     Notepad2.exe 
Library of Sub-routines "Cut and Paste
"
Library of routines:   A-E   E-P    P-Z 
 

 

This project monitors the current taken from a battery and provides a reading in AMP-HOURS. 
Three versions are available.  0-2.5amp  0-12amp  and 0-25amp  The only difference between them is the "monitoring Resistor." This is the 0.1 ohm or 0.025ohm or 0.01 ohm
The project can be connected to 12v or 24v batteries.

HOW TO USE THE PROJECT
Simply remove the spade terminals from the battery you will be testing and fit the leads that come with the project. Connect the spade terminals that are connected to the load,  to the terminals on the project.
The project monitors the current taken from the battery and when the button is pressed, the display shows the number of AMP-HOURS removed from the battery.
For instance, if you have a 1.2amp-hr battery, the display will show up to about 1.1A-Hr, at which time the battery will be almost completely exhausted, and will need recharging.
It is best to not go beyond 1A-Hr for this capacity battery as further discharging is called deep discharging and will shorten the life of the battery.
If you have a 7AHr battery, the discharge can be as much as 5.5AHr.
Any capacity battery can be monitored but you must use the correct version of the project, according to the maximum current that will be taken.
Sometimes the maximum current is not known, and you will need to do some homework.
Most globes and motors have a wattage rating. For 12v devices, each 12watts represents a current of 1 amp.
For instance, a 25 watt globe will draw 2 amps. A 200 watt motor will take 16.6 amps. The wattage of a motor is the maximum under ideal conditions. If the motor is on an electric bike for example, the wattage will be under acceleration conditions, on an incline or with head-wind and will be less for most of the duration of the ride.
Because the current consumption is so variable, it is very difficult to know how much energy has been taken from the battery. The same with an electric scooter or wheelchair.
It is impossible to know 
 




 


The CIRCUIT
The circuit operates exactly the same as the watt-hour meter fin your electricity-box. The current turns an aluminium disk at a rotational speed that is proportional to the current-flow. Our project measures the amount of current at any particular instant and counts the number of seconds. The multiplication of these two values produces a "mA-sec"  value. When the current changes, a new value is generated and added to the previous value.
Unlike the "eddy-current meter" in your electricity box, this project does not detect every milliamp increase in current but detects steps of 10mA and the time-duration is incremented every 10 seconds.
This reduces the size of the accumulated values so they can be stored in two registers. We don't need an accurate result as the energy taken from a battery cannot be more than 80% of the total capacity without getting into "deep-cycle" problems.
It's just handy to know when the limits are being reached so the battery can be recharged.
 




THE 0.1 OHM RESISTOR
The heart of the circuit is the 0.1 ohm resistor. It is the only component in the circuit. The circuit consists of input terminals and output terminals with a 0.1 ohm resistor between the negative terminals and the two positive terminals connected together. All the rest of the circuit consists of detecting and displaying.
The program monitors the current through the 0.1 ohm resistor by using Ohm's law.  We cannot actually measure the current flowing through the resistor but we can measure the voltage developed across it when a current flows. The PIC chip can detect 1mV increments when one of the pins is turned into an analogue input.  The current required to produce 1mV across 0.1 ohm is 10mA.
This is obtained by Ohm's Law:
When a current of 10mA flows, a voltage of:
V= IR   V = 0.01 x 0.1   V= 0.001v   V= 1mV  is developed across the resistor.
This means we can measure a minimum of 10mA and increments of 10mA.
100mA = 10mV     1,000mA = 100mV  and 2.500mA = 250mV
This means a voltage of 250mV is developed across the 0.1 ohm resistor when a current of 2.5amps flows.
The voltage to the load is between 1mV and 250mV less than battery voltage but when you are dealing with a battery voltage of 12.6v, this slightly lower voltage is not noticeable.
We need a special 0.1 ohm resistor. It must be small but capable of carrying a very high current.
This type of resistor is not available and so it must be home-made.
It is made by winding 34.5cm of 0.25mm wire on a 1k  0.25w resistor.
This makes it capable of carrying 50 amps without being damaged. We need to have a high current resistor, just in case the terminals are short-circuited by mistake. The resistor must not burn out as this would put 12v across the pins of the micro and it will be damaged.
You cannot measure the resistance of the resistor with a digital meter. Even though these meters measure increments of 0.1ohm, you cannot zero the meter and the leads impose a resistance of about 0.5 ohms. But you do not know if the  zero is 0.50 ohms or 0.55ohms. When the resistor is added, you don't now if the reading of 0.6 is 0.66ohms or 0.060 ohms.
We need the value to be correct to 5%. This was done by reading the current through a globe (0.430A) and at the same time measuring the voltage across the resistor as 43mV.  
This resistor is called a SHUNT RESISTOR or simply a SHUNT. This is because it is "shunting" or "taking away" or "diverting" or "steering away" the current from the recording device - the micro. This is the same type of resistor in a multimeter - when large currents are being measured.

The next part is to understand that a positive voltage is developed across the SHUNT.
The following diagram shows a 12v6 battery connected to the circuit with 1amp flowing to a LOAD. This causes a drop of 100mV across the SHUNT: ( V=IR = 1 x 0.1 = 0.1v = 100mV)
We have tilted the SHUNT slightly to show the voltage on the left-side is 0v and on the right-side it is 100mV higher.
This means a POSITIVE VOLTAGE is developed across it and this voltage is detected by the micro to perform the energy calculation. 


The voltage drop across the SHUNT

 

HOW THE A/D WORKS
The PIC12F679 has an Analogue-to-digital Converter.
This consists of a set of instructions inside the chip that detects a voltage on pin 7 and divides it into approximately 1,000 parts.  (210 = 1024 parts).
We are not concerned with how it does this or the number of cycles it takes, as the program looks to see when the conversion is complete and continues.
However we need to know how to use it to our advantage.
The A/D converter consists of a ladder of resistors and the program taps off the lowest resistor and uses the voltage to charge a capacitor and works out how long it takes (or variations on this principle).
if the top of the ladder is connected to 5v, the minimum detection is 5,000/1,000 = 5mV.
We have already stated that a current flow of 10mA produces a voltage of 1mV across the 0.1 ohm resistor.
This means the minimum current-detection is 50mA.
To improve the resolution we can connect the top of the ladder to a lower voltage and thus detect a smaller voltage for each increment .
The top of the ladder is connected to pin 6 (by setting bit 6 of ADCON0). If we provide a constant-voltage of 0.9v on this pin via a diode and two voltage-dividing resistors,  we can divide 1v by 1,000 to get 1mV divisions.
 
 
 


INSTRUCTIONS FOR USE
Remove the spade terminals from the battery you want to monitor and fit the leads from the project. Connect the spade terminals to the project.
The project monitors the current taken from the battery and when the button is pressed, the display shows the AMP-HOURS.

WHAT ARE AMP-HOURS?
AMP HOURS  is simply the multiplication of the current in amps and the number of hours - the current is delivered.
If 1 amp flows for 1 hour the answer is 1AHr. 
If 2 amps flow for 3 hours, the answer is 6AHr.
If 1 amp flows for 15 minutes, the answer is 0.25AHr.
The answer is NOT amp/Hr. It is: AMPS  x HOURS.

Do not get mixed up with AMP-HOURS and the MAXIMUM CURRENT a battery can deliver. They are both completely different.
A  12v rechargeable battery with a capacity of 1.2A-Hr may be able to deliver 100amps but this will only be for a very short period of time.
In fact it cannot deliver 100 amps for less than a minute as this is the full capacity of the battery. The battery will be dead before this time as it cannot deliver its full capacity at a high current.
The way to work out the time for high current demand is to write down the capacity as: 1.2 x 60 minutes.
If you increase the current to 12 amps, the time will be 6 minutes.
For 24 amps it will be 3 minutes and 100 amps it will be 3/4minute. This is just a simple way to obtain the "life of the battery."  The actual life will be considerably less as a battery can only deliver the full capacity when a low current is delivered. When a high current is delivered, the capacity of a battery is much less than the stated value.
There is no such value as amp/Hr. Or should we say, there is no such term as amp/Hr when talking about battery capacity. A battery may deliver 6amp/Hr,  but we simply say it will deliver 6 amp and if it will deliver 6amp for 1 hour, we say it will deliver:  "6amp for 1 hour."   It is a bit like saying: "I will give you $100 per hour!"   How much will you get?  $1,000?   $100,000? or $1M??  It all depends on how long you stay for your $100 each hour.
Thus 6amp/Hr does not mean anything. It does not have a time-duration.   How big is the battery?  How long will it deliver the 6 amp?  Thus we say a battery has a capacity of  6AHr or 24AHr etc.  From these values we know the battery will deliver 6 amp for 1 hour or 12 amp for 30 minutes etc.



CONSTRUCTION
You can build the circuit on any type of PC board and we have used a small piece of designer board.
The kit of components comes with all the parts you need to get the project working, including a pre-programmed chip and the designer board.
To modify the program you will need a PICkit-2 programmer and this comes with 2 CD's containing all the software needed for In-Circuit Programming.
You will also need a lead (comes with PICkit-2) to connect the programmer to your lap top via the USB port and an adapter we call 6pin to 5 pin Adapter to connect the PICkit-2 to your project.
 



Here are the files you will need:
LED_FX.asm
LED_FX-asm.txt
LED_FX.hex

 
	
;*******************************
;;Battery.asm
;  11-3-2010 
;*******************************

	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
	errorlevel	-302	; Don't complain about BANK 1 Registers during assembly

		
				
;****************************************************************
;*EEPROM     				*
;****************************************************************
								
	org	2100h			
					
							
	END


GOING FURTHER
We have not produced all the possible codes and you can add more by simply creating a new sub-routine. This can be stored as code 1 and can be used as soon as the chip is turned on.
Or you can add it to the table and make sure you end with retlw 00 to send the micro back to Main. You will understand what we mean when you start programming.
We have provided all the hardware and software for you to do this.
Now it's now up to you.

 

Battery Monitor
Parts List

Cost: au
$15.00 plus postage
Kits are available

3   -  82R (820) SM resistors
3  -  47k  (473) SM resistors

1  -  100n SM capacitor
1  -  100u electrolytic

1  -  SPDT mini slide switch

1  -  8 pin IC socket 
1  -  LM78L05 voltage regulator
1  -  PIC12F629 chip (with Combo routine)
3  -  super bright white LEDs
3  -  mini tactile switches
1  -  9v battery snap
20cm very fine solder 
1  -  PC Board (with 7segment display using 14 LEDs)

 24/11/2010