Wednesday, June 29, 2011

All-analog automatic night light circuit

Some ten days ago I installed an all-linear automatic night light circuit to control the lights inside the living room. Circuit consists of three op amps--two used as voltage followers and a third as a comparator. As the schematic shows, all user adjustable controls are at the comparator--with one potentiometer to set the trip point and the other pot to adjust the width of hysteresis band.
The sensor circuit is located several meters away at a location where it can have a view of the outdoors without being blinded or fooled by indoor lights at night. The high impedance sensor and low pass filter must have a unity gain buffer (voltage follower) within millimeters/centimeters. You can't have it on the main control circuit board meters away. Trust me. I've tested this several years ago with and without a buffer and a (unshielded twisted pair) cable. The signal will be degraded and probably unusable without the follower. Notice the low pass filter includes a diode. It  performs a very important and essential function. See my other automatic night light circuits for the explanation.

A 3-wire cable connects the sensor circuit to the main control circuit. According to the MCP627x op amp datasheet:
Driving large capacitive loads can cause stability problems for voltage feedback op amps. As the load capacitance increases, the feedback loop’s phase margin decreases and the closed-loop bandwidth is reduced. This produces gain peaking in the frequency response, with overshoot and ringing in the step response. A unity-gain buffer (G = +1) is the most sensitive to capacitive loads, though all gains show the same general behavior. When driving large capacitive loads with these op amps (e.g., > 100 pF when G = +1), a small series resistor at the output improves the feedback loop’s phase margin (stability) by making the output load resistive at higher frequencies. (DS21810F, 2008, p.14)

Well, we're working with essentially a DC signal and I have no idea of how much capacitance there is in the cable, but I just added R3 to be sure. The hysteresis circuit (R5, R6, R7) needs a low impedance source, thus A2 is used as a voltage follower--else R3 will foul up the resistor values for the hysteresis. For a discussion of hysteresis in single-supply op amps read this. Equations are provided.

A push-pull configuration using complementary transistors drives the relay and LEDs. A 12-volt relay is the output amplifier (and high-voltage isolator) which switches the 220VAC load. The relay is some 10 ten meters from the control circuit. Its normally open contacts are connected in parallel with the light's wall switch--so this switch has to be off for the circuit to turn the load on/off automatically. Green and red indicator LEDs provide feedback when adjusting the pots.



The shortcoming of this circuit--and for that matter all ANL circuits--is that the ambient light level at which the load is turned off must be higher than the light level at which it's switched on. In other words, incorporating a  hysteresis--however small--forces the circuit to turn the load off at a brighter condition than for load switch-on.

But in some cases (probably a majority) we want the lights off at the crack of dawn--i.e., at a darker condition than when it was turned on. Someone may have already done so, but I haven't yet come up with a way of doing this using linear components/ICs. I don't even know where to begin! Using a microcontroller on the other hand seems obvious and the simplest way to implement it.

And that's what I've been doing these past two days. Because it's MCU-based the circuit itself is a no-brainer. The firmware's where the brain-racking is. I've already installed a temporary circuit in place of the above all-analog one and will be checking its performance till week's end.

Given that I'm using an MCU--and all the computing power it's got--I pared down the sensor subcircuit and eliminated the low pass filter. Filtering is now performed digitally using algorithms. Pots are gone as well. Trip point is set using a momentary contact push button. "Negative" hysteresis (as I'm calling it, at least for now) is relatively simple to implement in firmware. Testing over the next few days will actually be assessment of the robustness of the algorithms I'm using, tweaking the values used in the equations, and ferreting out bugs.

No comments:

Post a Comment