Silicon ChipBattery-Pack Cell Balancer For Optimum Charging - March 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Future electronic developments in cars
  4. Feature: A Look At Quantum Computers by Dr David Maddison
  5. Project: Ultrasonic Garage Parking Assistant by Geoff Graham
  6. Project: 1-Wire Digital Temperature Sensor For The Raspberry Pi by Greg Swain & Nicholas Vinen
  7. Project: Delta Throttle Timer For Cars by John Clarke
  8. Product Showcase
  9. Serviceman's Log: Sorting my quake-damaged workshop by Dave Thompson
  10. Project: Solar MPPT Charger & Lighting Controller, Pt.2 by John Clarke
  11. Project: Battery-Pack Cell Balancer For Optimum Charging by Nicholas Vinen
  12. Feature: Save Money By Replacing Batteries In Emergency Lights by Ross Tester
  13. Vintage Radio: HMV 1939 model 209 5-valve radio by Associate Professor Graham Parslow
  14. Subscriptions
  15. PartShop
  16. Market Centre
  17. Advertising Index
  18. Notes & Errata: Loudspeaker Protector / High-Visibility 6-Digit LED GPS Clock / QuickBrake

This is only a preview of the March 2016 issue of Silicon Chip.

You can view 36 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Ultrasonic Garage Parking Assistant":
  • Micromite LCD BackPack PCB [2.8-inch version) [07102122] (AUD $5.00)
  • PIC32MX170F256B-50I/SP programmed for the Micromite-based Ultrasonic Garage Parking Assistant [ParkingAssistFull.hex] (Programmed Microcontroller, AUD $15.00)
  • MCP1700 3.3V LDO (TO-92) (Component, AUD $2.00)
  • CP2102-based USB/TTL serial converter with 5-pin header and 30cm jumper cable (Component, AUD $5.00)
  • Micromite Parking Assistant sensor & lid (Component, AUD $7.50)
  • Matte/Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Clear UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $4.00)
  • Firmware (HEX) file and BASIC source code for the Micromite-based Ultrasonic Garage Parking Assistant (Software, Free)
  • Micromite LCD BackPack PCB patterns (PDF download) [07102121/2] (Free)
  • Micromite LCD BackPack/Ultrasonic sensor lid cutting diagrams (download) (Panel Artwork, Free)
Items relevant to "1-Wire Digital Temperature Sensor For The Raspberry Pi":
  • Script for Raspberry Pi 1-Wire Temperature Sensor (Software, Free)
Articles in this series:
  • Raspberry Pi Temperature/Humidity/Pressure Monitor Pt.1 (January 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor Pt.1 (January 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2 (February 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2 (February 2016)
  • 1-Wire Digital Temperature Sensor For The Raspberry Pi (March 2016)
  • 1-Wire Digital Temperature Sensor For The Raspberry Pi (March 2016)
Items relevant to "Delta Throttle Timer For Cars":
  • QuickBrake/Delta Throttle Timer PCB [05102161] (AUD $12.50)
  • QuickBrake/Delta Throttle Timer PCB pattern (PDF download) [05102161] (Free)
Articles in this series:
  • Reduce Rear-End Collision Risk With The QuickBrake (January 2016)
  • Reduce Rear-End Collision Risk With The QuickBrake (January 2016)
  • Delta Throttle Timer For Cars (March 2016)
  • Delta Throttle Timer For Cars (March 2016)
Items relevant to "Solar MPPT Charger & Lighting Controller, Pt.2":
  • Solar MPPT Charger & Lighting Controller PCB [16101161] (AUD $15.00)
  • PIC16F88-E/P programmed for the Solar MPPT Charger & Lighting Controller [1610116A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (ASM and HEX) files for the Solar MPPT Charger & Lighting Controller [1610116A.HEX] (Software, Free)
  • Solar MPPT Charger & Lighting Controller PCB pattern (PDF download) [16101161] (Free)
Articles in this series:
  • Solar MPPT Charger & Lighting Controller, Pt.1 (February 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.1 (February 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.2 (March 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.2 (March 2016)
Items relevant to "Battery-Pack Cell Balancer For Optimum Charging":
  • Battery Pack Cell Balancer PCB [11111151] (AUD $6.00)
  • PIC16LF1709-I/SO programmed for the Battery Pack Cell Balancer [1111115A.HEX] (Programmed Microcontroller, AUD $10.00)
  • SMD Parts for the Battery Pack Cell Balancer (Component, AUD $50.00)
  • Firmware (HEX) file and C source code for the Battery Pack Cell Balancer [1111115A.HEX] (Software, Free)
  • Battery Pack Cell Balancer PCB pattern (PDF download) [11111151] (Free)

Purchase a printed copy of this issue for $10.00.

Battery Pack Cell Balancer Many multi-purpose chargers can handle lithium-ion, lithium-polymer or LiFePO4 batteries. But they may not balance the charge between individual cells and this can lead to incomplete charging and premature failure. This small device solves this by providing the balancing function separately. It can also be used with Nicad and NiMH packs for a longer life-span and is suitable for use with the MPPT Solar Lighting Charger/Controller published elsewhere in this issue. By Nicholas Vinen T RADITIONAL BATTERY chargers treat a battery as a device having two terminals, delivering current until the battery voltage reaches a certain level. The termination voltage is the fully-charged cell voltage multiplied by the number of cells and the assumption is that the when the battery reaches this voltage, each cell is fully charged. However, this relies on the cells being identical. Similarly, the battery is determined to be flat when the overall voltage reaches a level indicating that each cell is fully discharged. But if one cell starts out with a lesser charge or discharges faster for some reason, it could be over-discharged before this threshold is reached. This could damage the cell, leading to lower capacity and a shorter battery-pack life. It’s quite typical for a battery-pack to fail because the internal resistance of just one cell has gone high. The charge and discharge current must flow through all cells, so once one cell can no longer pass enough current, the whole battery is useless. Similarly, if Features & Specifications • • • • • • • • • • • • • • • Balances Li-ion, LiPo or LiFePO4 batteries with 2-8 cells Can also balance NiMH or Nicad packs with 4-8 cells Fully charged battery voltage of up to 33.6V (8 x 4.2V) Suitable for use with chargers up to 10A Will work with chargers >10A but not as effectively Cell balancing shunt current: ~200mA Very low quiescent current: <25µA Compact PCB can be mounted next to battery pack Works with virtually any non-balancing charger Plugs straight into typical battery balance connectors No external power required Automatically detects number of cells Detection of charging by cell voltage or via external signal Adjustable cell voltage balance start threshold via resistor LEDs indicate balance status 72  Silicon Chip one cell’s voltage is especially low (or perhaps even negative), the fully charged battery voltage may be insufficient even though the rest of the cells are healthy. So for the longest battery life you need to ensure that all cells are charged and discharged equally. Even with a brand new battery, cell capacity may vary slightly (by one ot two percent, say) but over time, this can worsen. This effect is greater with lithiumbased cells than other types, which is why it’s important to ensure they are properly balanced during charging. Consider a 4-cell LiPo battery with one cell that has 2% lower capacity than the others. All cells start out fully discharged at 3V, ie, the battery is at 12V. It is then charged to 16.8V, which we would expect to yield 4.2V per cell. However, since the lower capacity cell will charge faster, it may have reached 4.3V while the other cells are all at 4.166V. 4.3V + 4.166V x 3 = 16.8V, so the charger can’t tell the difference. This cell has now been over-charged and this could lower its capacity further, to say 3% below the rest. Despite its lower capacity, it has a higher charge state than the other cells, so after discharge the voltages may be equal again. But eventually its capacity could drop so much that it also starts discharging further than the other cells each cycle, accelerating the damage. The simple solution is to monitor siliconchip.com.au E S G + B 3.90V C D S G CHARGER (EXTERNAL) CHARGE PUMP 3.90V 4 +IN D S G INSTRUMENT. AMPLIFIER 3.92V D D 7 OUT 1 –IN 3.90V G S DISCHG.1 DISCHG.2 DISCHG.3 DISCHG.4 CELL SELECT ADC 3.92V MICROCONTROLLER PWM ON/OFF Fig.1: a simplified circuit showing the general principle of cell balancer operation. We’re showing four cells but our balancer will work with up to eight. Mosfets are connected across each cell, to divert some of the charge current if that cell’s voltage rises higher than the others. Analog switching, driven by a microcontroller, allows each cell to be connected across the inputs of an instrumentation amplifier, so the micro can measure that cell’s voltage. A charge pump is used to provide sufficient voltage for the instrumentation amplifier to operate, while a transistor allows its supply to be switched off when it isn’t being used. the voltage of each cell during charging and shunt current around those cells which have a higher voltage than the others. This reduces the charge delivered to lower capacity cells, so they all reach the correct charge termination voltage simultaneously. This not only prevents weak cells from being over-charged but also stops strong cells from being under-charged. Arguably, it’s a good idea to monitor and balance cell voltages during discharge too, however if balancing occurs during charging, this should hopefully keep the cells healthy and they will discharge at a more or less equal rate. Serious imbalances normally take multiple charge/discharge cycles to build up, so regular cell balancing during charging is thought to be sufficient. However, should you wish to balance a battery pack while it’s being discharged, our unit can do that too. It can be constantly active, drawing very little current until an imbalance is detected, at which point it “wakes up” and attempts to rectify it. Our cell balancer The concept of a cell balancer is quite simple. It periodically checks the voltage of all cells. If one cell has siliconchip.com.au a significantly higher voltage than the others, some of the charge current is shunted around it or if the battery is not currently being charged, it is discharged slightly. This reduces its voltage back in line with the others. This process is continuous so that as soon as any cell’s voltage starts rising above the others, it is brought back in line. Block diagram The basic principle is shown in the simplified circuit of Fig.1, drawn with a 4-cell battery. Blue arrows show the flow of current from the charger through the battery. The second cell has a higher voltage than the others, so the microcontroller enables the corresponding Mosfet to divert some of the charge current around it. There are some complications to this approach. Cell voltages will need to be measured accurately so that small imbalances can be detected before they become significant. Ideally, inter-cell error should be around 10mV or less. This will prevent unnecessary shunting/discharging of the cells due to measurement error. In the worst case, if there is a bias in the way the balancer measures cell voltages, it could actually imbalance an already balanced pack! Also, if the balancer is to be left connected to the battery pack (which, in fixed installations, it would be), it needs to have negligible drain when the battery is not being charged or balanced. Ideally, it should be able to detect when charging is occurring and switch off for the rest of the time. It also needs to be able to shunt a sufficiently large percentage of the charge current to be able to “keep up” with the rate at which cell imbalance can occur, without this resulting in excessive dissipation which could cause undesired heating of the balancer or the battery. It should also ideally suit a wide range of battery types, from two cells or more and including all the different chemistries that may require balancing. In order to accurately assess the difference in cell voltages, we’ve avoided using a voltage divider. If we had simply connected each cell to a micro’s ADC inputs with its own divider, it would be difficult to assure cell-to-cell accuracy. And if we used dividers after some sort of analog switching arrangement, they would have to be very accurate to keep the common mode rejection ratio (CMRR) high enough. Independent cell measurement Instead, we are using analog switches to connect one cell at a time to an instrumentation amplifier. This is effectively a differential op amp with a very high input impedance and a very high CMRR. These both contribute to providing very good differential voltage sensing accuracy. Its output is the voltage of the selected cell and this is then fed to the ADC input of a microcontroller. The micro we have chosen is a PIC16LF1709, running at 3.3V. This has a 10-bit ADC which is sufficient to sense cell voltages with a resolution of less than 5mV or even better with averaging. It’s also capable of an ultra-low-power sleep mode, to minimise current drain when balancing is not occurring. To this end, it has been teamed up with an ultra-low quiescent current regulator and it can switch power to the instrumentation amplifier off when it isn’t being used. Current is shunted around a cell during charging, or the cell is partially discharged, by switching on a Mosfet connected across the cell with a pair of current-limiting resistors. These March 2016  73 74  Silicon Chip siliconchip.com.au Fig.2: the complete Cell Balancer circuit. Cell voltages at CON1 are connected to instrumentation amplifier IC4 by highvoltage analog switches IC1 and IC2, then to microcontroller IC3’s AN11 analog input. IC3 can then switch on one of Mosfets Q5-Q11 which in turn activate Mosfets Q1a-Q3b or Q4 to shunt current around or discharge the cell with the highest voltage. The bottom-most cell is shunted directly by Mosfet Q12. IC3’s pin 11 output drives a charge pump to boost IC4’s supply so it can operate over the entire battery voltage range. siliconchip.com.au March 2016  75 Parts List 1 double-sided PCB, code 11111151, 69 x 35.5mm 1 3-way to 9-way pin header, 2.54mm pitch, straight or right angle to suit battery pack (CON1) 1 3-way pin header, 2.54mm pitch, with optional jumper shunt (CON2) 1 5-way pin header, 2.54mm pitch, straight or right angle (CON3, optional, for ICSP) 1 100mm length of heatshrink tubing, 50mm diameter (optional) 3216/1206 (LED1) 1 high-brightness green LED, SMD 3216/1206 (LED2) 3 DMP3085 dual 30V P-channel Mosfets, SOIC-8 (Q1-Q3) 1 DMP2215 20V P-channel Mosfet, SOT-23 (Q4) 9 BSS138 logic level N-channel Mosfets, SOT-23 (Q5-Q13) 1 BC856 PNP transistor, SOT-23 (Q14) 8 BAT54CFILM dual 40V Schottky diodes, SOT-23 (D1-D8) 1 BAT54SFILM dual 40V Schottky diode, SOT-23 (D9) Semiconductors 2 DG409DY quad high-voltage CMOS switches, SOIC-16 (IC1,IC2) 1 PIC16LF1709-I/SO 8-bit microcontroller programmed with 1111115A.hex, SOIC-20 (IC3) 1 AD8226BRZ single supply instrumentation amplifier, SOIC-8 (IC4) 1 RT9058-33GV 3.3V (36V in) 100mA low-dropout, low-IQ regulator, SOT-23 (REG1) 1 high-brightness red LED, SMD Capacitors (SMD 3216/1206, X5R/X7R) 8 1µF 50V 2 10nF 50V Mosfets are controlled by individual output pins on the microcontroller. Circuit description The full circuit of the cell balancer is shown in Fig.2. The battery balance connector is usually a 2.54mm-pitch JST type which plugs into CON1 with the negative-most terminal to pin 9, as shown. Between two and eight cells are connected and with fewer than eight cells, some pins will not connected. The terminals of CON1 are wired directly to the inputs of two dual 4-to1 multiplexer ICs, IC1 & IC2. These DG409s will tolerate up to 44V and have a maximum on-resistance of 100Ω. They are wired so that, depending on the state of their control input pins (A0, A1 and EN), one cell at a time can be connected to the inverting and non-inverting inputs of instrumentation amplifier IC4 (pins 1 & 4). For example, if A0 and A1 are low (0V) and the enable pin of IC1 is high, pin 1 of CON1 is connected to pin 4 of IC4 while pin 2 of CON1 is connected 76  Silicon Chip Resistors (SMD 3216/1206, 1%, ¼W) 1 3.3MΩ* 3 10kΩ 1 1MΩ 2 1kΩ 10 47kΩ 1 47Ω 1 22kΩ 9 10Ω 0.5W** 2 10kW ¼W through-hole resistor * change to set balance start voltage threshold ** 4.7Ω ½W preferred for use with NiMH/Nicad to pin 1 of IC4. Therefore, the voltage across the top-most cell of the battery (assuming it has eight) appears across IC4’s inputs. IC4 is configured for unity gain, with no resistor between pins 2 & 3. Thus, the difference between the voltage at either end of the selected cell appears at output pin 7. This is fed to analog input AN11 (pin 12) of the PIC16LF1709 microcontroller via a 10kΩ/22kΩ resistive divider, with a 10nF capacitor connected across the bottom leg to act as a noise filter. The divider ensures that even with a fully-charged lithium-ion or lithium polymer battery, with a cell voltage of up to say 4.3V, no more than 2.96V will be fed to IC3 and this is well below its 3.3V supply, which also acts as the ADC reference voltage. So basically, the micro can measure the voltage across each cell by controlling the state of its output pins 13/RB4 (to A0), 14/RC2 (to A1), 15/RC1 (to IC2 EN) and 16/RC0 (to IC1 EN). Because it uses the same circuitry in each case, errors should be consistent, making for accurate cell voltage comparisons. IC4 has a CMRR of at least 90dB with unity gain, so the error due to absolute cell voltage variation is tiny – with 30V between the bottom and top cell voltages, the resulting error will be less than 1mV. Besides noise, the other source of error is variation in the on-resistance between the analog switches in IC1 and IC2. However, since IC4 has an extremely high input impedance of around 400MΩ, this error will also be negligible; less than 10µV. Cell balancing During charging, microcontroller IC3 scans the cells about once per second, to determine if there is a significant difference in their voltages. If there is, it switches on one of Q1a-Q3b, Q4 or Q12 to shunt some current around it, reducing that cell’s charge rate. One of these Mosfets is connected across each cell, with a 10Ω series resistor at either end (the bottom cell is slightly different). Many of these resistors are shared, to cut down on the component count, meaning normally only one Mosfet will switch on at a time, to keep dissipation within component limits. The bottom-most cell is discharged by N-channel Mosfet Q12. Its gate is driven directly from output pin 10 (RB7) of micro IC3 and when that line goes high, it sinks current from the positive terminal of this cell through a pair of series-connected 10Ω resistors to ground. Assuming this is a fullycharged Li-Po cell at around 4.2V, the shunt current is 4.2V ÷ 20Ω = 210mA. If the battery is being charged at, say 5A, this means that 4.2% of the charge current will be shunted around this cell, so it will charge more slowly than the others and eventually the voltages will re-balance. If charging is not occurring then this cell will simply discharge at a rate of 210mA, until its voltage has been reduced to be in line with the other cells. The other seven cells (or however many are present) are discharged by one of P-channel Mosfets Q1-Q4. Six of these are part of DMP3085 dual Mosfets while the seventh is a single DMP2215 Mosfet. Each is normally held off by a 47kΩ resistor between its gate and source terminal, and switched on when the gate is pulled to ground by one of Q5-Q11, which are smallsignal N-channel Mosfets. Like Q12, these are driven directly from the outputs of micro IC3, from siliconchip.com.au pins 2-9. These are logic-level Mosfets and require less than 2V at the gate to sink more than 100mA. Q5-Q11, in combination with the gate pull-up resistors, effectively form level shifters to provide the different voltage levels to drive the gates of Q1-Q4. The DMP3085 Mosfets used have a maximum gate-source voltage of 30V, so Q2 and Q3 require no gate voltage limiting. Q4 does not require gate voltage limiting either as it’s connected across the second-from-bottom cell and so its source will never be more than 9V above ground. However, for Q1a and Q1b, two extra 47kΩ resistors are connected between the drains of Q5/Q6 and their gates to reduce the gate drive voltage to a maximum of -20V. The discharge Mosfets do not need to be switched quickly, so the relatively high-value 47kΩ resistors do not interfere with their function. Power supply REG1 is fed the full battery voltage via one of dual Schottky diodes D1-D4. A 47Ω filter/dropper resistor reduces dissipation in REG1, an SMD 3.3V lowdropout linear regulator, while also filtering out any hash from the charger or spikes from discharge pulses. The 3.3V rail supplies microcontroller IC3 and is also used as a reference voltage for its ADC, as stated earlier. The VBAT rail from the cathodes of D1-D4 also powers multiplexers IC1 and IC2 via series Schottky diodes D5 and D6. These diodes provide protection for IC1 and IC2 against over-voltage at their inputs, since their internal clamp diodes will automatically boost the supply if this happens (and D5/D6 would become reverse-biased). Normally this is not an issue but when a battery is initially plugged in, not all of its pins may make contact at the same time, so we’re protecting these ICs as per the suggested arrangement in the data sheet. The power supply for IC4 is somewhat more complex. To avoid draining the battery when it isn’t being charged or balanced, micro IC3 switches off IC4 using PNP transistor Q14. To switch Q14 on, IC3 drives its RB6 output high (pin 11), which charges N-channel Mosfet Q13’s gate via an RC filter. Q13 then sinks current from Q14’s base via a 10kΩ current-limiting resistor, turning it on and allowing current to flow to IC4’s supply pin via D7. siliconchip.com.au Fig.3: operation of the charge pump which supplies IC4. Initially, IC4’s supply (yellow) is below the battery voltage (green) due to the two Schottky diodes and one PNP transistor its supply current must pass through. Once the charge pump begins operation, it quickly climbs above the battery voltage, eventually settling about 4V higher after 8ms or so. The micro then quickly takes the measurement using its ADC before the supply voltage drops. But that isn’t the end of the story because while IC4 can handle input voltages down to its negative rail (ie, GND), the inputs must remain below its positive rail for correct operation. The voltage between the positive-most input and the positive supply rail must be at least 1V plus half the output voltage to remain in the common-mode operating range, which in our case means we need a “headroom” of around 3.1V (1V + 4.2V ÷ 2). The forward voltage of D1-D4 & D7 means that normally IC4’s supply will be around 0.6V below the positivemost battery terminal, so we need to boost its supply by 3.1V + 0.6V = at least 3.7V to correctly sense the top cell voltage. So, before measuring the voltage of the top-most cell, after RB6 is brought high and the 1µF capacitor at Q13’s gate is fully charged, IC3 pulses its RB6 output around 50 times before taking the first measurement, with a frequency of around 5kHz. This drives a charge pump which increases IC4’s supply voltage to about 4V above the battery voltage, allowing it to properly measure the voltage of the top cell(s). Fig.3 shows how the supply voltage to IC4 rises during this period, from a little below the 20V battery voltage in this example to around 24V. It works as follows: when RB6 goes low, 1µF capacitor C1 charges from the battery supply via Q14 and D8, to around 0.75V less than the battery (point “a”, Fig.2). When RB6 goes high again, point “a” increases by about 3.3V, to around 2.5V above the battery voltage. C2 is then charged to slightly less than this (at point “b”), via one half of dual series Schottky diode D9. When RB6 next goes low, C3 charges to around 2V above the battery voltage via the second half of D9 (point “c”). When RB6 goes high again, point “c” is boosted to around 4V above the battery voltage and current flows through the lower half of dual Schottky diode D7, forming IC4’s supply. This drops a little during RB6’s off-time but remains sufficiently high to complete several ADC conversions. By starting with Q13’s gate at 3.3V and keeping the duty cycle relatively high, Q13 is prevented from switching off before the charge pump has done its work, despite the fact that RB6 is being modulated. Balance current The 10Ω resistors have been chosen March 2016  77 Q14 47Ω IC4 1 µF 1 µF D8 ICSP1 µF D9 47k 1 µF10k D7 REG1 10nF 10nF22k 10k 1 µF 1 Q13 CON1 − IC2 9x 10 Ω ½W Cell Balancer RevC LED2 CON3 1 µF 1 µF 10k IC3 PIC16LF1709 Q4 DMP2215 1 LED1 K A 1 µF D5 Q3 Q6 2x 1k AD 8226 D4 1 Q2 Q5 1 DG409 D3 1 1 1M Q12 Q11 Q10 Q9 Q8 Q7 D2 BATTERY DG409 CON2 11111151 3.3M GND CELL1 D6 EN 9x 47k + IC1 1 D1 1 Q1 Fig.4: all SMD components are mounted on the top of the double-sided PCB. The pin headers can be straight or rightangle types and can be fitted on either side. Take care with the orientation of IC1-IC4, Q1-Q3, LED1 & LED2. The other components are either non-polarised or their orientation is fairly obvious. Note: photo shows prototype PCB assembly. to limit current to a safe level with lithium-based rechargeable cells. For NiMH/Nicad, since the cell voltage is substantially lower (less than half), ideally 4.7Ω 0.5W resistors should be substituted. The unit will still operate with 10Ω resistors but the shunt current will be below 100mA and this may be insufficient to keep the cells balanced, depending on the charge current. Note though that 4.7Ω is too low for use with Li-ion, LiPo and LiFePO4 batteries as they would dissipate nearly 1W each ((4.3V ÷ 2)2 ÷ 4.7Ω). Software operation The first thing that the software does, after setting up the input and output pins, is to determine the number of cells in the battery by measuring the voltage of each one and checking that it is above a minimum threshold. It expects to find a contiguous set of at least two cells starting from the bottom; otherwise, it flashes red LED1, waits a little while, then checks again. Once a valid battery has been detected, normal operation begins. When checking for the presence of a cell, the corresponding shunt/discharge Mosfet is switched on briefly to remove any stray charge that may be present, which could give a false reading. The main loop checks the voltage on pin 17 and goes into a sleep mode if it is below the 0.95V threshold (corresponding to a 4.085V trigger threshold with the values shown in Figs.1 & 3). After spending some time in low power sleep mode, the watchdog timer wakes the chip up and the pin 17 voltage is checked again. Assuming pin 17 is at least 0.95V, the software switches on power to IC4, waits for its bypass capacitor to charge, then initiates the charge pump to bring 78  Silicon Chip its supply voltage up. Once that’s complete it quickly scans the cells, from the highest to the lowest, measuring the voltages and storing them. It then makes a decision about whether to shunt/discharge any cells. If they’re all basically equal, it ceases balancing and goes back to the main loop. If balancing starts, the cell with the highest voltage is shunted/discharged. If there is a tie then they are handled in a round-robin fashion to balance the shunt current evenly. Each time, after a few seconds of shunting/discharging, the cell voltages are re-checked and a new decision is made. Balance initiation You can connect an external signal to pin 2 of CON2 to initiate balancing; for example, you could connect an output from your battery charger that goes high (to at least 4.5V) during charging. For a lower threshold, reduce the value of the 3.3MΩ resistor. For example, to suit a 3.3V signal, use a 1MΩ resistor, setting the threshold to 1.9V. Alternatively, you can short out pins 1 & 2 of CON2, eg, with a jumper shunt. Balancing then starts whenever the bottom-most cell of the pack exceeds 4.1V. This voltage was chosen so that when a Li-ion or Li-Po battery is approaching full charge, balancing will begin but will cease once the battery has been discharged below approximately 90% of full charge. This prevents unnecessary battery drain if the cells become imbalanced during discharge. There’s no inherent reason why cells can not be balanced during discharge; in fact, arguably this is a good idea. However, it will increase battery current drain slightly and may reduce shelf-life after charging. It may also trigger low-battery cut-out on the powered device earlier. However, this could be a good thing as it will prevent any single cell from being over-discharged. The balance initiation threshold can also be changed by selecting a different value for the 3.3MΩ resistor. Simply take the desired cut-off voltage, divide by 0.95, subtract one and pick the nearest resistor value in megohms. This will be necessary for different battery chemistries (eg, NiMH). Construction All components are fitted to one side of the PCB, with the possible exception of the headers, depending on your requirements. Use the PCB overlay diagram, Fig.4, as a guide for assembly. Start by fitting the ICs. The simplest method is to apply a little solder to one of the pads, then heat that solder while sliding the IC into place. Once you’ve done that, check carefully that pin 1 is orientated correctly, which is usually indicated by a divot or dot in the corner. Failing that, look for a bevelled edge on the IC package. Then check that all the pins are correctly centred over their pads. If not, reheat the initial solder joint and nudge the IC into place. You can then solder the remaining pins and, finally, refresh the initial solder joint. Follow with Mosfets Q1-Q3 which are in similar packages to IC4. Next, install all the components in SOT-23 packages which includes all the diodes, the remaining Mosfets and bipolar transistor Q14, as well as REG1. A similar method can be used, where one pin is tacked down before the other two are soldered and the initial joint refreshed. Be careful not to get any of these parts mixed up as they all look very similar. Follow with the resistors and capacitors using a similar technique. The resistors will have an abbreviated code printed on the top showing the siliconchip.com.au value, eg, 223 for 22kΩ (22 x 103). The capacitors will be unmarked although you will probably be able to pick them apart as the 1µF types should be physically larger. If you’re planning on using 4.7Ω resistors rather than 10Ω, keep that in mind. That just leaves two SMDs, both LEDs. You will need to determine which end is the cathode. This is often marked on the package with a green dot, however we’ve seen LEDs which mark the anode with a green dot too, so it’s safest to check. Generally, this can be done with a DMM set on diode test mode. Probe each end of the LED with the leads. If it lights up, the red lead is connected to the anode and the black to the cathode. If not, try flipping the LED around. Once you’ve worked out which end is the cathode (and also revealed the colour), solder it in place. Note that LED1 is red and LED2 is green and that the cathode (indicated with a K) goes towards the righthand edge of the PCB. Battery connector CON1 can be soldered to either side of the PCB and you can use a straight or right-angle header. We used a right-angle header on the top of the board to minimise the overall thickness of the unit. You may wish to use a header with fewer than nine pins, to suit your battery connector, as this will make it easier to plug in. However, you could just solder in a 9-pin header to suit any battery pack with 2-8 cells. CON3 can be omitted if your microcontroller is already programmed. We used a right-angle programming header, again to minimise thickness. For CON2, we used a straight header as we simply fitted a jumper shunt so that balancing would begin automatically once the battery reached a sufficient cell voltage. However, you could simply fit a wire link between “EN” and “CELL1” if desired. Alternatively, connect a pair of wires between GND and EN, with or without the pin header. Note that, while it would be possible to leave out some components if you do not need to handle batteries with more than six cells, we’ll leave it to individual constructors to figure out which ones can be omitted. Usage If IC3 has not already been programmed, download the hex file from the SILICON CHIP website (free for subsiliconchip.com.au scribers). Program the chip using a PICkit 3 or similar. You can use the PICkit 3 to power IC3 but be careful not to exceed its 3.6V maximum supply rating. Ideally, it’s a good idea to do some basic checks before connecting a battery. If you have a current-limited bench supply, set it to 12-24V at 10mA and connect it between pins 1 & 9 of CON1, with the negative terminal to pin 9. Once the on-board capacitors charge, the current drain should drop to just a few milliamps and the red LED should flash, indicating a battery is not detected. If you don’t have a bench supply, you can use any DC source with a series resistor of say 470Ω 0.5W for ~12V or 1kΩ 0.5W for ~24V. Assuming all is OK, connect the battery, taking care to orientate the plug correctly as the header is not polarised. In theory, the unit should survive a reversed supply connection, at least in the short term, but the 10Ω resistors could potentially overheat as the parasitic diodes in Mosfets Q1-Q4 will conduct. After a couple of seconds you should see the green LED flash once for each cell in the battery. If you have joined EN and CELL1 on CON2, depending on the battery voltage, the unit may then begin the balancing operation. Otherwise, it will go into sleep mode and both LEDs will remain off. If driving the EN pin externally, wire this up to your charger so that it will be driven high during charging. You can then switch on the charger and check that the red and green LEDs illuminate together briefly, to indicate that the unit has “woken up”. If the battery needs balancing, you will see further flashes. When balancing occurs, green LED2 will flash rapidly and then switch off. The number of flashes indicates which cell is being shunted/discharged. Once the cells have been balanced, green LED2 will be switched on for around one second, then switch off. Error indication If an error condition is detected (eg, an unexpected low cell voltage), red LED1 will flash rapidly. If the EN pin drops below 0.95V while balancing is still active, red LED1 will switch on for around one second and then the unit will go back into sleep mode until the SC EN pin voltage rises again. MISS THIS ONE? CLASSIC Published in Feb 2013 DAC Make just about any DVD or even CD player sound better by using this highperformance Digital to Analog Converter! It has three TOSLINK inputs, three SP/DIF inputs, USB audio inputs, SD card playback capability and a built-in headphone amplifier. THD is almost unmeasurable at 0.001% <at> 1kHz and S/N ratio is outstanding at 110dB. Most parts mount on a single PCB and the hard-to-get parts (PCB, front and rear panels, programmed micro, SMD parts and coloured RCA sockets) are available from the SILICON CHIP On-Line Shop. You’ll find the construction details at siliconchip.com.au/project/classic+dac PCBs, micro etc available from On-Line Shop Where do you get those HARD-TO-GET PARTS? Many of the components used in SILICON CHIP projects are cutting-edge technology and not worth your normal parts suppliers either sourcing or stocking in relatively low quantities. Where we can, the SILICON CHIP On-Line Shop stocks those hard-to-get parts, along with PCBs, programmed micros, panels and all the other bits and pieces to enable you to complete your SILICON CHIP project. SILICON CHIP On-Line SHOP www.siliconchip.com.au/shop March 2016  79