Practical PIC Projects

   

Automatic Charger Sharing
for
Motorcycle Battery Charger
(#280)

 



Description

This project came about because I have three motorbikes and being a bit of a fair weather biker they don't get used much over the winter months.  I have an OptiMate™ 4 charger that I connect to the bikes but this needs me to manually swap it from one bike to the next and between forgetting to do it and not remembering which bike it was last connected to it's all a bit unreliable.

So this project is a four-way automatic battery charger sharing controller.   The circuit is powered from the battery(s) of the connected motorbikes. Current consumption is about 40-50mA and since it draws its power from the battery under charge it doesn't discharge the batteries on the other bikes.

The circuit continually monitors which of the four connections are in use so it only connects the charger to outputs that are currently connected to a bike.  If a bike is disconnected part way through  charging the circuit immediately switches to the next connected output.

Status LEDs show which output is currently connected to the charger, which outputs are connected to a bike but not currently charging and a heartbeat LED to indicate the microcontroller is operating normally.

Please read the Caveat before using this project


Operation

This controller project has only been tested using an OptiMate™ 4 'smart' charger in standard mode (not CAN-bus).  It should work with other chargers, however, it hasn't been tested and I am unable to advise on this.

The controller connects each output to the charger for approximately 12 hours.  The controller cycles through all four outputs over a 48 hour period (4 x 12hrs) 

When switching from one bike to the next, all outputs are disconnected for about 30 seconds to allow the charger to see the disconnection and reset itself.

If no bike is detected on an output the controller simply skips that output and goes to the next one in the cycle.  If only one bike is connected, after 12 hours it is disconnected for 30 seconds and then reconnects for another 12 hours.
 

There are five LEDs on the control board.

The green heartbeat LED blinks continually, once per second to show the controller is operating.

Four orange LEDs indicate the status of each output/bike connection.

  • If the LED is off, no bike is detected and the channel is skipped.
     
  • If the LED is steady on, the charger is connected to the output.
     
  • If the LED blinks briefly every 2.5 seconds, a bike connection is detected on the output but the charger isn't currently connected to it.  This just gives visual confirmation that the controller knows the bike is connected.
     
  • If a battery is disconnected while charging, the controller waits 30 seconds before assuming the battery has disconnected.  The output LED stays on during this time.

Any of the outputs can be connected at any time.  They don't need to be connected sequentially.  The controller will skip outputs that aren't connected.  However, you should note that when you connect another bike it may be up to 48 hours (4 x 12 hours) before its output gets connected to the charger.

  

Important Notes:
  • The charger is designed to work with 12 volt electrics and charging currents not exceeding 3 amps.
     
  • Before using this controller, all the batteries should be in good condition and charge state, if necessary charge then directly from the charger. 
     
  • The charge share controller will help to maintain healthy batteries in a good state of charge.  If you have a battery that is heavily discharged or sulphated don't connect it to this controller. 
     
  • Don't use on bikes equipped with a CAN-bus or charger set to CAN-bus mode as switching from one battery to another can confuse the 'smart' charger.
     
  • When the charging is done through the controller the status indicators on the charger only show the condition of the battery currently being charged.   Therefore periodically you should connect the charger directly to each bike to ensure the batteries are all charging correctly.
     
  • When the control board output(s) are connected to one or more motorbikes, the controller starts to operate.  This occurs even if the battery charger isn't connected so you should make sure the controller isn't connected to the bike(s) if the charger is turned off or disconnected for any length of time.  Although the controller only uses about 50mA it will eventually run the bikes battery down if the charger isn't present for several days.

Connecting up

The physical wiring is shown in the diagram on the right. 

Red wiring is the positive connection, black wiring is negative or earth.  Pay attention to the wiring and make sure to get the polarity correct, especially if you are making up your own cables.

To keep the wiring diagram simple I haven't shown any fuses or intermediate connectors.

The OptimMate™ charger I use has accessory options that include a weatherproof, fused permanent connection lead like the one shown below.  This is fitted to each bike's battery and makes it easy to connect/disconnect the charger.

I bought some crimp connectors compatible with those used by the original charger and made up my own extension cables to connect the charger to the controller and controller to the bikes.  You can also buy a ready made 2.5m extension cable with the correct connector on for the OptiMate™ system.  If you use one of these cables you just cut the charger end off and connect the bare wires to the controller. (you'll find this stuff on eBay)

Safety Warning: Whatever charger system you have and however you connect to the bike battery it is important that you use an inline fuse.  This should be in the charging lead at the battery end of the cable since a fault in the wiring or on the control board could short the battery leading to serious damage or fire.



Schematic

Circuit Description

This section covers how the circuit works, but you don't need to understand it to build a working charger sharing controller, so feel free to skip it.

The circuit is controlled by IC2, a PIC16F628A microcontroller running firmware written in MikroC (firmware and compiler can be downloaded free)  

There are four single pole relays on the PCB that connect the input from the battery charger to each individual output.  The software controls the operation of the relays so that only one relay is active at any time.  When switching from one bike to the next all outputs are switched off for 30 seconds to allow the charger to 'see' the disconnection and reset itself.   Each output is active for approximately 8 hours and the controller cycles round the outputs sequentially so all four outputs will connect over a 32 hour period. The controller senses the presence of the bike battery on each output so unconnected outputs are skipped e.g. if only two bikes are connected each bike gets an 8 hour charge every 16 hours.  The timings are written into the controller software, if you want to change them you will need to edit and recompile the C source code.

The circuit is powered using the batteries on the connected motorbikes.  Diodes D1 to D4 feed power from each bikes battery to the circuit.  The diodes isolate the bikes batteries from each other and only the bike with the highest battery terminal voltage actually powers the circuit; this will normally be the battery currently charging.

The voltage at each of the four outputs is fed to the microcontroller sense inputs via a resistor network comprising 10K and 3K3 resistors.  This divides the input voltage by 4.03 so a voltage above approximately 8 volts at the output will feed 2 volts to the sense input of the microcontroller IC2. This is seen as a high logic level by the software and allows the controller to detect which outputs are actually connected to a bike.

The 12 volt supply from the bike battery feeds the relay coils and also to a 5 volt regulator IC1.  This regulator IC is an LP2950 micro-power precision Low Dropout regulator and provides regulated 5 volts to the microcontroller.  The relay coil voltage is a nominal 12V DC but is rated to 1.5x this which is 18 volts so they are okay working with typical battery terminal voltages of 12.5 to 14.8 volts.

Capacitor C3 provides decoupling of the input power. C2 does the same for the 5 volt output.  C4 is required by the voltage regulator IC1 to maintain a stable output.  Capacitor C3 is rated at 25 volts, don't use a lower voltage rated part here.

The five LEDs connect via 560 ohm resistors to the microcontroller.  This is quite a high value but it keeps the LED current around 5mA which helps keep the overall current consumption of the circuit low.

The ground connection of the battery charger and all the bikes are connected together on the PCB.  The positive output from the charger is fed to the common pole of all four relays.  The output of each relay feeds one bike.  When the corresponding relay is turned on, the positive output from the battery charger is connected to the bike and therefore allows the battery to be charged.

A  ULN2003A Darlington transistor array is used to switch the relays using four of the seven outputs.  Each output of the ULN2003A incorporates a diode to provide clamping of the relay coil flyback voltage.  The choice of this IC over discrete components was made to keep the PCB layout simpler and more compact.

Charging Current and Voltage

Quick digression here.  Although the relays are rated for 10 amp switching, the PCB traces are only good for about 3 amps. This is more than adequate for most motorbike chargers, in fact the charger I use only outputs 800mA.  If you heavily tin the PCB tracks with solder around the relays and terminal blocks you can increase this to maybe 6 amps.  The circuit is designed to work with 12 volt batteries only - it won't work with 6 or 24 volt automotive electrics.

Power Supply

The board requires a nominal 12 volt DC supply to operate.  With D1-D4 installed the board is powered from the batteries of the motorbikes attached to the outputs.  The battery with the highest voltage at its terminals will forward bias one of the diodes, causing it to conduct and power the controller.  The other diodes are then reverse biased and do not conduct.  Typically the bike under charge will have a higher battery terminal voltage than the others so the controller  doesn't drain the batteries of the non-charging  bikes.

If you don't want it to work this way you can use an external 12 volt DC power supply connected to the 'external power input' connector.  If you do this you MUST omit diodes D1-D4.  Also ensure the power supply output does not have a connection to the AC mains earth.

When using the external power input terminal the board is protected from a reverse polarity connection by diode D5.

Each relay requires about 35mA to operate, the 5 LEDs when all on add another 25mA and the rest of the circuit uses about 5mA.  The heartbeat LED flashes at 1Hz, and the channel connection LEDs for 100mS every 2.5 seconds, only the active channel LED is on constantly and since only one relay is active at any time the average current consumption is typically under 50mA.

Building for less than four channels

If you don't need four channels you can omit the LEDs, resistors, relay and diode for an unused channel.  Even if a channel output isn't used you should fit the 3K3 resistor (R7 through R10) to ensure the channel sense input is held low and the software treats it as unused.

External Crystal

The PCB is laid out to allow the use of an external crystal for the microcontroller's clock oscillator using XT1/C5/C6.  I chose not to use an external clock and instead use the internal RC oscillator.  While this doesn't give such accurate time delays, for the intended application 10 minutes error in 12 hours isn't significant.  If you want to use a crystal it needs to be 4Mhz, the load capacitors should be 15pF and you will need to change the configuration word when programming the PIC to use external XT crystal on RA6/RA7 for the clock source.


I've designed a single sided PCB for this project, however it's a very simple circuit with minimal components so there is no reason why you couldn't build it on stripboard.  Just remember that the bike battery can deliver a lot of current so any wiring faults could cause serious damage. Test with a current limited power supply and always use a fused lead to connect to the bike battery.


Component List

You can buy all the parts needed to build this project from most component suppliers world wide. In the UK you can get everything from Rapid Online and I've included a parts list with their part numbers below.

 

All Rapid parts/descriptions correct at 10 February 2013.  You should check part# and descriptions are correct when ordering in case I've made a mistake transferring them onto this page.

Component Description Part #
R1-5   PACK 100 560R 0.25W CF RESISTOR   (Order 1 pack only) 62-0364
R6,R11-R14 PACK 100 10K 0.25W CF RESISTOR  (Order 1 pack only) 62-0394
R7-R10 PACK 100 3K3 0.25W CF RESISTOR  (Order 1 pack only) 62-0382
C2 100N 2.5MM X7R Dielect Ceramic Capacitor 11-3442
C3 100uF 25 v low imp Electrolytic capacitor 11-2922
C4 47uF 10v 5mm Micromin Electro Capacitor 11-1502
IC1* LP2950CZ-5 micropower regulator 82-0680
IC2** PIC12F628A-I/P 73-3340
IC3 ULN2003A 82-0618
D1-D5 1N4148 75V 200mA signal diode 47-3309
LED1-4 Kingbright L-53LYD 5mm Low Current Yellow Diffused LED 2mcd 55-0856
LED5 Kingbright L-53LGD 5mm Low Current Green Diffused LED 2mcd 55-0852
     
socket for IC2 18 Pin 0.3in Turned Pin Socket 22-1723
socket for IC3 16 Pin 0.3in Turned Pin Socket 22-1722
     
K1-K4 Finder 12V Relay (Miniature) SPDT 10A 36.11 60-4192
Terminal block
Qty 6
2 Way 16A Black Interlocking Terminal Block (order 3) 21-0440

Parts List Notes

All the resistors are supplied in packs of 100

* If you can't get hold of the LP2950 you can substitute a 78L05 5-volt regulator

** PIC16F628A will need to be programmed with the HEX file available to download at the bottom of this web page.

C1 is not used.
C5/C6/XT1 are optional components and not used in this design
 


Construction photos:

A brief photographic guide to PCB assembly and testing.  Please read through before starting assembly as there are some important things to note.

Copper side of PCB after etching and drilling

 

Fit the diodes taking note of the orientation.  The cathode is marked with a black band. This should be placed towards the respective arrows in the photo above.



On the copper side of the PCB is a solder jumper.  Bridge this with a big blob of solder as shown in the photo.  This is very important, the circuit won't work without it.

The above photo shows all the resistors fitted, capacitor C2 (blue part), the LEDs and sockets for the two ICs.



This photo shows IC1 and Capacitor C3.  IC1 should be fitted with the flat face towards the arrow.  C3 also needs to be fitted the correct way round.  The negative terminal needs to be fitted nearest the hole shown by the arrow.  You can identify the negative lead as it will be shorter than the other and this should be fitted so it is in the hole nearest the arrow.

General view of the board showing the 5mm screw terminals in place.

Also capacitor C4 needs to be fitted the correct way round.  One lead will be shorter than the other and this should be fitted so it is in the hole nearest the arrow.



The four relays have now been fitted to the board and component assembly is now complete.

Before proceeding, inspect the copper side of the PCB and make sure all the solder joints are good.  There are no solder bridges, wire off-cuts etc. shorting across track and also that all component leads have been neatly trimmed.

At this point you should check the 5 volt supply is present.  Connect a 12V DC supply to the screw terminals shown in the photo.

Next using a multimeter measure the voltage at pins 5 and 14 of IC2 socket. It should measure 4.9 to 5.1 volts. 



Once you have checked the 5 volt supply is correct, disconnect the board from the 12 volt supply.  Next, fit IC2 (PIC16F628A) and IC3 (ULN2003A) into the respective sockets.

When you fit the two IC's they must be inserted the correct way round. Each IC has an indent at the left end as seen in the photo above.  Make sure you fit them the same way as shown.  

Now the board is assembled it can be tested.  This should be done using a 12 volt DC power supply.  Best not to use a motorbike battery for this since it will deliver enough current to cause series damage if there is a fault.

Connect the 12 volt supply to the 'ext power' screw terminal as shown above.  The heartbeat LED should start to blink.

You can also test the battery sensing control by connecting a wire from the positive 12 volts supply (red lead above) to the positive output screw terminal of each output.  When you do this the corresponding LED should start blinking; after 30 seconds the relay should click-in and the LED will turn on.



Connected up to the motorbikes (Triumph Tiger 800 and Yamaha Fazer 8)  The Daytona is out of view. 

I haven't fitted the control board into a case yet but you really should do so before using it otherwise there is a risk of shorting the underside of the control board to metal work on the bike.


Did I mention fuses?  Well I'll say it again, Use Fuses at the battery end of the connecting cables.  The cables available for the OptiMate
  chargers that connect permanently to the battery already have an in-line fuse.  If you're making up your own cable connections to the battery, please fit an inline fuse.  The electric current a bike battery can supply will easily cause a fire if a wiring fault develops.


Firmware

The firmware is for use with a PIC16F628A microcontroller.

The HEX file is ready to program straight into the PIC.  The 'C' source code was written using MicroC PRO 6.4.0  You can download the free version of the C compiler from the MikroElektronika website

Not got a programmer?  Buy a pre-programmed PIC from the On-line store

Description Filename Download link
Source code for 16F628A chargeshareV11.c download
HEX file ready to program into the PIC
for use with
16F628A
chargeshareV11.HEX
Version 1.1 08/09/2014
Checksum 0xE92F
download

PIC Configuration word is set correctly in the HEX file but should your programmer need them they are listed at the top of the C source code.  Config word value ix 0x217C

If you need a PIC Programmer I strongly recommend the Microchip PICKit 2, this is available from suppliers world wide or direct from Microchip.  It's reasonably cheap to buy and reliable. 

 



Contact us: