The on/off switch for these lights became the most complex part. Remember the goals. The lights will be placed in a boy scout equipment trailer. They need to work for two nights every month. The battery may only get charged for two hours each month (an hour of travel time each direction). The users of the finished product vary between eleven year old boys and forty year old boys.
Figure 1 is the schematic for the whole operation. The boost regulator on the right was covered in the previous blog. The "Trailer Battery" is a "12V" lead-acid battery that is charged when the trailer is hooked up to the truck. The 7.5Ω 15W resistor (physically huge) will keep the charging current to about 1.3A even if the trailer battery falls to 10V and the truck electrical system is running at 20V. A 3A fuse is placed in the electrical path if that isn't sufficient. The diode keeps the trailer battery from feeding the truck if the trailer battery gets over charged somehow.
A mechanical relay has the advantage of low resistance when on and effectively infinite resistance when off. Pushing the button will turn on the relay. The relay will then stay on as long as power is provided. It takes a 5V SHUTDOWN signal to the base of Q1 to pull down the coil voltage and depower the entire circuit. Note the two resistors (R1 of 430Ω and R2 of 150Ω) are 1W while the rest of the resistors are 1/4W; enough current could flow through those two resistors if the battery were to float high that I thought heftier components would be a good idea.
I need to know when the button is pressed so I know when to turn off. The coil voltage is higher when the button is pressed than when the relay is operating self-latched. I can't directly use this voltage because all reasonably priced comparators that can operate from a 10-20V power supply have a common mode input range that only extends up to the power supply minus 2V. One side or the other of the comparator needs to be 2V below its power supply to get reliable operation. Thus the funky resistor network. Figure 2 shows just the resistor network with the resistor values as I decided them.
The basic idea of this funky network is that when the switch is open VPOS>VNEG and both are more than 2V below VPOW, and when the switch is closed, VNEG=VPOW, VPOS<VNEG, and VPOS<VPOW-2.
The relevant circuit equations are (hey, we had to have some equations in here somewhere!)- A single button to turn the lights on and off. You can't push the wrong button if there is only one.
- No power consumed when the lights are off. None.
- Lights turn off automatically after 30 minutes to conserve power.
- Before the lights turn off automatically, they blink to warn and give time to turn them back on.
- Pressing the button before the automatic off turns the lights off with the same warning blink.
- Pressing the button during the blinking turns the lights on for another 30 minutes.
Figure 1. Schematic for the whole she-bang. An 600dpi version can be downloaded. |
A mechanical relay has the advantage of low resistance when on and effectively infinite resistance when off. Pushing the button will turn on the relay. The relay will then stay on as long as power is provided. It takes a 5V SHUTDOWN signal to the base of Q1 to pull down the coil voltage and depower the entire circuit. Note the two resistors (R1 of 430Ω and R2 of 150Ω) are 1W while the rest of the resistors are 1/4W; enough current could flow through those two resistors if the battery were to float high that I thought heftier components would be a good idea.
I need to know when the button is pressed so I know when to turn off. The coil voltage is higher when the button is pressed than when the relay is operating self-latched. I can't directly use this voltage because all reasonably priced comparators that can operate from a 10-20V power supply have a common mode input range that only extends up to the power supply minus 2V. One side or the other of the comparator needs to be 2V below its power supply to get reliable operation. Thus the funky resistor network. Figure 2 shows just the resistor network with the resistor values as I decided them.
Figure 2. Funky resistor network. |
When the switch is open:
I2 = VPOW/(R2+(R2+RC)||(R3+R4))
VA = VPOW-I2R2
VNEG = VA*(RC/(RC+R1)
VPOS = VA*(R3/(R3+R4)
Check that even with VPOW=10V VPOS>VNEG and VPOS and VNEG < VPOW-2
When the switch is closed:
VNEG = VPOW
I3 = VPOW/(R2||R1+R4+R3)
VPOS = I3R3
Check that even with VPOW=10V VPOS<VNEG and VPOS < VPOW-2
I played with these in a spread sheet to find likely values then wrote a PERL script that varied all of the resistors by +/-1% or +/-5% to make sure it worked across corners.
The 7805 powers the microcontroller. It has a significant reservoir capacitor so the microcontroller will remain powered a bit longer than the rest of the circuit. This allows the microcontroller to turn off the main power supply. The 7805 can handle a back-power condition like this of up to 7V, so 5V is safe.
I have not yet programmed the microcontroller; that will be next month's post. In the mean time, I am using a 74HCT74 dual D-Flip-Flop to control the SHUTDOWN signal as shown in figure 3. The button presses toggle the power on and off. This accomplishes nothing more than a push-on/push-off switch could accomplish. The microcontroller is needed for the 30 second time delay and blinking the lights in warning.
The LIGHT signal is level-shifted up to the battery voltage and used to control a pnp high-side switch. The current flowing to the boost regulator is less than 250mA, so a small bipolar can be used. Another mechanical relay might have made sense here, I decided to go with the cheaper solution.
Figure 4 is everything put together, though it using the flip-flop instead of the microcontroller. The boost regulator is soldered onto a protoboard to keep the parasitics down, but the rest of the circuit can be operated on a bread board. I am laying out a custom PCB, it will be the post after next. Since the circuit works when done somewhat sloppily on a bread board, I feel confident I can make it work on a two layer PCB.
Figure 4. Prototype implementation, Boost supply on proto-board, everything else on breadboard. |
There you go. These things always seem simple once they are working. Next month a simple assembly language program to control this circuit.
Bruce