Auffie’s Random Thoughts

Tuesday, June 30, 2009

Watchdog for asterisk: implementation (Part IV)

Part IV: Revising the circuit to use a transistor to drive the relay

Well, it turns out that I needed to revise the circuit since I'll be using an unregulated power supply---a simple class 2 transformer (like the ones used for charging cell phones or powering computer peripherals). I have one with adjustable voltage (3V, 4.5V, 6V, 7.5V, 9V, and 12V). At nominal 4.5V, the measured open-circuit output is actually about 7.5V, and that is sufficient for my relay (Radio Shack Catalog #275-005) , which is rated at 7V to 9V.

But there were a couple of problems with unregulated supply. Since the voltage will vary with the amount of load, it could affect the accuracy and reliability of the operations of the two ICs on the circuit. Since the LM567 is rated at 9V maximum, I decided to use an LM7805 5V linear regulator. But this gives rise to another problem. Although the output of the 555 timer can drive 200mA, its output voltage is about 1.3V below its Vcc, in this case 5V. Secondly, driving an inductive load (relay) is tricky. The circuit in Part III is actually not quite right, because even with the protective diode, the negative voltage of -0.6V (the kickback voltage of the relay clamped by the diode) on the output of the 555 can actually cause it to malfunction. The application note for the NE555 (Philips AN170) (p.7, Figure 8) recommends that a series diode be connected between its output and the inductive load, but that means another drop of 0.6V, which is far from sufficient for driving the the relay.

The solution is to use an NPN transistor (Q2), with the output of the 555 driving the base (via a resistor [R6] to get the necessary base current). The current to drive the relay will be supplied from the unregulated output of the transformer. The modified circuit is shown below. Note that since Vcc is now 5V, I reduced the value of R5 so that D2 will not be too dim.

Labels:

Monday, June 15, 2009

Watchdog for asterisk: implementation (Part III)

Part III: Watchdog Timer (Missing Pulse Detector)

The following circuit implements a watchdog timer, sometimes also called a missing pulse detector.


The circuit expects pulses (active low) at intervals less than its timing constant, given approximately by (see LM555 datasheet):

T = 1.1 * R4 * C8

When a pulse is present at the input to this circuit (which is the output from the tone decoder), capacitor C8 is discharged because Q1 is turned on. It will again be charged starting from 0V, while the output (pin OUT of the 555 timer) remains high. Thus, it takes time T for the capacitor to be charged to the triggering threshold voltage for the output to go low. If the next pulse comes long before this amount of time elapses, then we start the timing cycle again without changing the output.

For the values chosen (1MegOhm and 47uF), T is about 52 seconds. Thus, the host computer needs to send a tone blip to the decoder no more than every 50 seconds or so. I plan to make that 10 seconds, with pulses of slightly varying frequencies (from the low-cutoff frequency to the high-cutoff frequency of the tone decoder), so that we can accommodate some shifts in the center frequency due to temperature variations.

D3 is a flyback diode that absorbs the voltage surge when the relay is turned off; this is necessary to protect the 555 IC. The output of the relay is used to connect or disconnect a plain telephone from the phone line. SW1 is connected to the handle of the telephone, so that when it is picked up, the relay will lose its current in that event as well. Note that the relay is connected as normally closed, so that when we lose power to the relay by whatever reason (power outage, host computer crash, or handset picked up), we get the plain telephone online.

The video below demonstrates the watchdog timer in action. For the purpose of this demonstration, I have replaced R4 with a 100kOhm resistor, so that the time constant T is now about 5 seconds. Eight tone blips of 0.25s in width in 2s intervals are generated from the host computer. The tone decoder nicely lights the orange LED accordingly, and the timer turns on the green LED and make it stay on as long as the blips come in frequently enough. About 5 seconds after the last pulse, the timer turns off the green LED and, in the final circuit, the relay as well, putting the telephone online.

Labels:

Watchdog for asterisk: implementation (Part II)

Part II: Calibrating the Tone Decoder for Specified Frequency

The tone decoder schematic is given below (Vout is connected to the input of the timing circuit, to be described in Part III):


(Thanks to Linear Tech for providing a nice free simulator LTSpice, which I used to produce the above drawing. The IC is actually an LM567 equivalent, though the schematic has Linear Tech's logo on it.)

I have constructed this circuit on a breadboard for testing. The 10k potentiometer (R1) on the test board is from the kit that I purchased from NightFire. It has only one turn, so it is probably not suitable for production as it might be less precise. I have also bought a couple of multiturn trimpots from Fry's Electronics, which I will use in the final circuit. The following video show the calibration of the tone decoder. (The right half of the board is the timing circuit, which we will ignore for now.) As I turned the trimpot slowly while the test tone is being played from the host computer, the orange LED eventually lights up when the frequency is matched.



Related posts:
Part I
Part III

Labels:

Watchdog for asterisk: implementation (Part I)

Part I: Generating a tone from host computer for an "alive signal" for the watchdog

First, it is obvious that a mini-stereo plug is needed to get the signal out of the sound card. I managed to find an old headset from my junk pile, and carefully cut out the mini-stereo plug and the cord for the earphone part. Stripping the wires is a little tricky, as the inner wire is very thin.

Next, I need to generate a tone. I picked 18kHz, which is almost inaudible, though the LM567 part can easily handle a wide range of frequencies. I also need to adjust the amplitude of the tone so that it is sufficient to be detected by the LM567. The datasheet for LM567 says that the minimum detectable input voltage is about 20-25 mVrms, but in one of its example circuits (a touch-tone decoder) an input voltage level of 100-200 mVrms is indicated. So a minimum of 100mVrms should be safe.

I used Audacity, which provides a nifty tone generator, to produce 30 seconds of 18kHz sound:


The next dialog box allows one to specify the frequency, amplitude, and duration:


Since I don't have an oscilloscope, I had to rely on my very primitive multimeter, which can measure AC voltage to only an precision of 0.1V. After experimenting with a few values of amplitude and measuring the corresponding voltage, I decided on an amplitude of 0.4. During this measurement, the volume setting in the Windows (Vista) mixer is set to its full value 100. This is because, when the circuit is deployed, the signal on the sound card in my Linux box will be produced via an ALSA program directly reading from a PCM WAV file, without final gain adjustment. Of course, I may need to readjust the amplitude since the output signal level on the Linux box may be different from my Windows box.

Labels: