Raspberry Pi HATS compatible UPS – part IIb – status indication

The explanation of the trickle charger portion was a lot longer than I’d anticipated, and I hope it was clear. With that in mind, I’m going to dive straight into the development of the second main portion of the UPS board – the source and charge indication controller. As you can see in the schematic snapshot below, this consists of three main sections: power/reference (R1, R4, R14, IC1, C1, C2, C3), power source indicator (R10, R17, R11, R18, IC2A, R8, R5, LED2), and low battery indicator (R12, R19, R6, R20, R13, IC2B, R9, R7, LED3). An LM2903 dual comparator, IC2, forms the core of this part of the circuit.

indicator

Power supply and reference: if you’ve read about the trickle charger, this part should be fairly straightforward. This is again built around a TL431 shunt regulator, which is going to serve two purposes: to provide a stable and accurate voltage reference, and to provide a 3.3 V power supply which will allow interfacing with the Raspberry Pi. I chose a shunt supply so as to reuse the widely available and easily configured TL431 IC. It would have been possible to use a simple linear voltage regulator here but these often come in different packages and are usually more expensive. Additionally, a shunt regulator is inherently short circuit proof, which is important in testing as mistakes happen..! Without further ado, the values were calculated using the following procedure:

  1. Shunt regulators work by tapping off a portion of applied current to ground so as to keep the desired voltage, so we need a current source for the supply. In this instance, R1 is acting as a very simple (and very bad, but sufficient!) current source. To calculate its value we need to know the minimum input voltage, V_{in}, the output voltage V_{out}, and the shunt current I_{shunt}. Of these, the two voltages are known and the designer must chose the chose the shunt current. As can be seen from the schematic, the 3.3 V supply powers IC2, LED2 and LED3, and the outputs to the RPi (or whatever), BATT and LOW. As shown, the LEDs are powered at about 1.5 mA each (more on that below), and the comparator will take around 4 mA, and the voltage dividers and output will take some current too, so we need at least ~9 mA shunt current. However, for some tolerance, I’ve settled on I_{shunt} = 15 mA – this is a value that may be easily changed! Now, we are in a position to calculate R1. The voltage across R1 is V_{in} - V_{out}, with the minimum $V_{in}$ dependent on the battery chemistry; for our 6 V SLA battery that is around 5.9 V. So, R1 = \frac{V_{in}-V_{out}}{I_{shunt}} \rightarrow R1 = \frac{5.9 - 3.3}{0.015} = 173\ \Omega. Rounding this to a realistic resistor value gives R1 = 180\ \Omega.
  2. Now we need to program the TL431 (IC1) to give the desired 3.3 V output. This is set by resistor divider R4/R14. For the TL431, V_{out} = (\frac{R4}{R14} - 1)V_{ref}. From the datasheet, we know V_{ref} = 2.495 V, and as discussed in part IIa, R4 + R14 \approx 10\ k\Omega. We already used a 6.8 k\Omega resistor, so it makes sense to use that again for R14. Putting it all together after rearranging the output equation to solve for R4 give: R4 = (\frac{V_{out}}{V_{ref}} - 1)R14 \rightarrow R4 = (\frac{3.3}{2.495} - 1) \times 6800 = 2194\ \Omega, so rounding to a sensible value gives R4 = 2.2\ k\Omega.
  3. As a safety precaution, we should check the worst case power dissipation in R1 and IC1. The worst case for R1 is if the output is shorted to ground, in which case it will see the full V_{in} across it. Knowing the voltage and resistance, we can use P_\mathrm{R1} = \frac{V_{in}^2}{R1} \rightarrow P_\mathrm{R1} = \frac{6.8 \times 6.8}{180} = 257 mW, so we should use a 0.5 W part here. For IC1, the (unlikely – why?) worst case is all the current running through it, so we can calculate it as P_\mathrm{IC1} = I_{shunt}V_{out} \rightarrow P_\mathrm{IC1} = 0.015 \times 3.3 = 49.5 mW, which is within the power tolerance specified.

Supply source indication: the LM2903 is an open collector dual comparator. What this means is that it acts like a switch inside, which is closed when the -ve input is at a higher level than +ve input. When the open collector output is on (closed), it acts like a wire to ground, so that node is at 0 V when it’s on. This also turns on LED2, which now has a path to ground When it’s off (open), R8 pulls up the voltage to 3.3 V, and LED2 turns off as there’s no voltage difference across it. In this case, we just need to divide both the external supply voltage and the battery voltage by an equal amount as we just need to know which is bigger. The constraint is that the inputs to the comparator must be less than the power supply voltage, which is 3.3 V. The maximum specified input voltage is 15 V, so simply divide by 5 to get a signal within range. So:

  1. For a simple voltage divider, V_{out} = \frac{V_{in}R17}{R10 + R17}. Now, the values for R1o and R17 on the schematic probably look familiar as 3.6\ k\Omega and 910\ \Omega respectively. I can’t remember which order I designed this whole things in, but I suspect I started here..! For the sake of argument, let’s say that we’ve already used a 3.6\ k\Omega resistor somewhere else (R10). Now, we can rearrange the voltage divider equation to find our unknown, which is R17: R17 = \frac{V_{out}R10}{V_{in}-V_{out}} \rightarrow R17 = \frac{3 \times 3600}{15-3} = 900\ \Omega. Rounding to a sensible value gives R17 = 910\ \Omega. As we need to divide both the external and battery power, that also gives R10 = R11 = 3.6\ k\Omega and R17 = R18 = 910\ \Omega.
  2. To calculate the value LED2’s current limiting resistor, we need to know the LED voltage and then specify a current through it. For V_\mathrm{LED} a sensible value is 2 V, which covers the high end of red and the bottom of green. Delve into the datasheet for a more precise value, but it’s not a particularly critical value. Now, to choose I_\mathrm{LED} – based on the 3.3 V power supply, we’ve given ourself a current budget of 10-15 mA and LEDs don’t need a large current to function. With this in mind, I chose I_\mathrm{LED} = 1.5 mA. Now, using Ohm’s law, R5 = \frac{V_\mathrm{in}-V_\mathrm{LED}}{I_\mathrm{LED}} \rightarrow \frac{3.3 - 2}{0.0015} = 867\ \Omega. This value is not critical to the function of the circuit, so let’s use the 910 \Omega resistors already in use.
  3. Finally, the pull-up resistor R8. This must be sufficiently small in value to drive any pins the circuit connects to, but not large enough not to drain too much power. The datasheet for the Raspberry Pi’s BCM2835 shows a 50 k\Omega pull-down resistor in the GPIO schematic, but it isn’t specified and could be in the range of 40-100 k\Omega. As long as we pick a value approximately 10\times less than the lowest value, it will drive it to a low enough value (imagine it forming a voltage divider with the GPIO’s pull down resistor). There are a lot of 3.6 k\Omega resistors in use already, so we can just re-use one of those without worry.

Battery condition indicator: Firstly, it’s worth bearing in mind this will be an approximate indication. The chemistry of batteries is dependent on a lot of factors, including temperature, current draw, and charge state. However, this will give a fairly good indication of the battery having, say, 40% charge remaining. When the Raspberry Pi receives this signal, it would be a good idea to start shutting things down in an orderly manner but that’s up to you. This part is a little more complicated, as the comparator here has hysteresis. The battery will be be discharging fairly slowly, so the voltage will also be dropping slowly. At the point at which the battery voltage is equal to the reference voltage, the comparator will be in an undetermined state as both inputs are equal and so it will bounce between on and off. This would be fine if we just had an LED to show that the battery was running low, but as we’re signalling to an external circuit we want a clean transition here.

  1. Note the commonality between the power source indicator and this part and we can re-use parts without having to calculate anything else. We still need to divide down the battery voltage, which we’ve already done using R10 and R17, so that’s just connected directly. The pull-up and and the LED are both identical, so R8 = R9, and R5 = R7.
  2. A full coverage of hysteresis is a beyond this page, and there’s a lot of text already so we’ll cheat a bit here. When you have time, I would encourage you to understand the principles behind this circuit (references are at the bottom of the page). We need to pick a low threshold, a high threshold. As we’re using the battery voltage roughly divided by 5, we need to determine the battery voltage where there is say 40% capacity remaining. For a 3-cell lead acid battery, this is roughly 6.15 V, so our low threshold is \frac{6.15}{5} = 1.228 V. The comparator will transition cleanly to 0 V when this is reached, and from the hysteresis, will not return to 5 V until the input is 1.278 V. The values were found using this handy comparator hysteresis calculator.

Well – there it is! Again, what appears to be quite a simple circuit has a lot of design choices to be taken care of with a reasonably high level of precision. Quite a lengthy article again, but hope it’s been informative! Comments, questions, and suggestions welcome as ever. The links to some articles on hysteresis are listed below.

Curing Comparator Instability with Hysteresis – Analog Devices; Adding Extra Hysteresis to Comparators – Maxim Integrated Products; Hysteresis – Wikipedia

Advertisements

2 thoughts on “Raspberry Pi HATS compatible UPS – part IIb – status indication

  1. Pingback: Raspberry Pi HATS compatible UPS – part IIc – power and miscellaneous parts | AWJ Logan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s