Silicon ChipUsing Comparators To Detect & Measure - February 1989 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Lightning: more dangerous than you think
  4. Feature: Lightning & Electronic Appliances by Leo Simpson
  5. Vintage Radio: Restoring plastic & bakelite cabinets by John Hill
  6. Project: Transistor Beta Tester by Malcolm Young
  7. Feature: Using Comparators To Detect & Measure by Jan Axelson
  8. Project: Minstrel 2-30 Loudspeaker System by Leo Simpson
  9. Feature: Amateur Radio by Garry Cratt, VK2YBX
  10. Project: LED Flasher For Model Railways by Malcolm Young
  11. Serviceman's Log: A Sharp in Pye clothing by The Original TV Serviceman
  12. Subscriptions
  13. Feature: The Way I See It by Neville Williams
  14. Feature: The Evolution Of Electric Railways by Bryan Maher
  15. Back Issues
  16. Market Centre
  17. Advertising Index
  18. Outer Back Cover

This is only a preview of the February 1989 issue of Silicon Chip.

You can view 41 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.

Articles in this series:
  • Amateur Radio (February 1989)
  • Amateur Radio (February 1989)
  • Amateur Radio (March 1989)
  • Amateur Radio (March 1989)
Articles in this series:
  • The Way I See It (November 1987)
  • The Way I See It (November 1987)
  • The Way I See It (December 1987)
  • The Way I See It (December 1987)
  • The Way I See It (January 1988)
  • The Way I See It (January 1988)
  • The Way I See It (February 1988)
  • The Way I See It (February 1988)
  • The Way I See It (March 1988)
  • The Way I See It (March 1988)
  • The Way I See It (April 1988)
  • The Way I See It (April 1988)
  • The Way I See It (May 1988)
  • The Way I See It (May 1988)
  • The Way I See It (June 1988)
  • The Way I See It (June 1988)
  • The Way I See it (July 1988)
  • The Way I See it (July 1988)
  • The Way I See It (August 1988)
  • The Way I See It (August 1988)
  • The Way I See It (September 1988)
  • The Way I See It (September 1988)
  • The Way I See It (October 1988)
  • The Way I See It (October 1988)
  • The Way I See It (November 1988)
  • The Way I See It (November 1988)
  • The Way I See It (December 1988)
  • The Way I See It (December 1988)
  • The Way I See It (January 1989)
  • The Way I See It (January 1989)
  • The Way I See It (February 1989)
  • The Way I See It (February 1989)
  • The Way I See It (March 1989)
  • The Way I See It (March 1989)
  • The Way I See It (April 1989)
  • The Way I See It (April 1989)
  • The Way I See It (May 1989)
  • The Way I See It (May 1989)
  • The Way I See It (June 1989)
  • The Way I See It (June 1989)
  • The Way I See It (July 1989)
  • The Way I See It (July 1989)
  • The Way I See It (August 1989)
  • The Way I See It (August 1989)
  • The Way I See It (September 1989)
  • The Way I See It (September 1989)
  • The Way I See It (October 1989)
  • The Way I See It (October 1989)
  • The Way I See It (November 1989)
  • The Way I See It (November 1989)
  • The Way I See It (December 1989)
  • The Way I See It (December 1989)
Articles in this series:
  • The Evolution of Electric Railways (November 1987)
  • The Evolution of Electric Railways (November 1987)
  • The Evolution of Electric Railways (December 1987)
  • The Evolution of Electric Railways (December 1987)
  • The Evolution of Electric Railways (January 1988)
  • The Evolution of Electric Railways (January 1988)
  • The Evolution of Electric Railways (February 1988)
  • The Evolution of Electric Railways (February 1988)
  • The Evolution of Electric Railways (March 1988)
  • The Evolution of Electric Railways (March 1988)
  • The Evolution of Electric Railways (April 1988)
  • The Evolution of Electric Railways (April 1988)
  • The Evolution of Electric Railways (May 1988)
  • The Evolution of Electric Railways (May 1988)
  • The Evolution of Electric Railways (June 1988)
  • The Evolution of Electric Railways (June 1988)
  • The Evolution of Electric Railways (July 1988)
  • The Evolution of Electric Railways (July 1988)
  • The Evolution of Electric Railways (August 1988)
  • The Evolution of Electric Railways (August 1988)
  • The Evolution of Electric Railways (September 1988)
  • The Evolution of Electric Railways (September 1988)
  • The Evolution of Electric Railways (October 1988)
  • The Evolution of Electric Railways (October 1988)
  • The Evolution of Electric Railways (November 1988)
  • The Evolution of Electric Railways (November 1988)
  • The Evolution of Electric Railways (December 1988)
  • The Evolution of Electric Railways (December 1988)
  • The Evolution of Electric Railways (January 1989)
  • The Evolution of Electric Railways (January 1989)
  • The Evolution Of Electric Railways (February 1989)
  • The Evolution Of Electric Railways (February 1989)
  • The Evolution of Electric Railways (March 1989)
  • The Evolution of Electric Railways (March 1989)
  • The Evolution of Electric Railways (April 1989)
  • The Evolution of Electric Railways (April 1989)
  • The Evolution of Electric Railways (May 1989)
  • The Evolution of Electric Railways (May 1989)
  • The Evolution of Electric Railways (June 1989)
  • The Evolution of Electric Railways (June 1989)
  • The Evolution of Electric Railways (July 1989)
  • The Evolution of Electric Railways (July 1989)
  • The Evolution of Electric Railways (August 1989)
  • The Evolution of Electric Railways (August 1989)
  • The Evolution of Electric Railways (September 1989)
  • The Evolution of Electric Railways (September 1989)
  • The Evolution of Electric Railways (October 1989)
  • The Evolution of Electric Railways (October 1989)
  • The Evolution of Electric Railways (November 1989)
  • The Evolution of Electric Railways (November 1989)
  • The Evolution Of Electric Railways (December 1989)
  • The Evolution Of Electric Railways (December 1989)
  • The Evolution of Electric Railways (January 1990)
  • The Evolution of Electric Railways (January 1990)
  • The Evolution of Electric Railways (February 1990)
  • The Evolution of Electric Railways (February 1990)
  • The Evolution of Electric Railways (March 1990)
  • The Evolution of Electric Railways (March 1990)
Using Comparators to Detect and Measure OUTPUT 3 14 OUTPUT 4 13 INPUT GNO 2 3- LM339 1 3 OUTPUT OUTPUT 2 1 V+ 5 INPUT INPUT INPUT INPUT 1- 1+ 2- 2+ Fig.1: the LM339 contains four independent comparators and can operate from single or dual voltage power supplies. Discover how to use op amps to monitor real-world conditions. By JAN AXELSON Comparators are among the easiest op amp circuits to use. Unlike other op amps, whose outputs vary linearly in response to some input, the outputs of comparators switch between just two voltage levels, depending on the relative voltages at their inputs. A comparator is really quite similar to a toggle switch. When the toggle, or lever, is raised slowly (in a linear fashion), the switch will suddenly snap to the on position. There's no in-between state! Likewise, as the toggle is lowered, the inner switch mechanism will suddenly flip to the off position. The comparison stops here though, because comparator circuits are much more flexible than ordinary toggle switches. Comparators are ideal for voltage monitoring in test or alarm circuits. Any condition, such as temperature or light, that can be sensed as a voltage can be monitored with a comparator. Besides using comparators in simple voltage-detecting circuits, you can use a pair of comparators to detect whether an input falls within a range of voltages; or you can use a series of comparators to control a bargraph display, for a good-looking and more precise indication of signal levels. The circuits that follow are typical examples of comparators in action. They can be used to guide you in choosing and using comparators to fit your own circuit needs. What's special about comparators? Although some op amps are specifically designated comparators, in many cases a general-purpose op amp can also serve the same purpose. The main limitation is that op amps often include phase and frequency compensation for better closed-loop stability. Since comparator circuits operate open-loop (without negative feedback), they don't need this compensation and respond faster without it. 28 SILICON CHIP Most of the examples in this article use the low-cost and readily available LM339 IC, which contains four independent comparators on one chip. Fig.1 shows the LM339 chip's pinouts. The chip can be powered from a single supply ranging from 2-36 volts DC or from dual supplies from ± 1 to ± 18 volts DC). Supply current requirements are less than one milliampere (lmA) which is low enough to allow battery-powered operation. Comparator basics Fig.2 shows a basic comparator circuit using the LM339. The voltage to be sensed (Vinl is connected to the non-inverting ( +} input (pin 5), while the reference, or trip point, voltage (V rerl is applied to the inverting ( - } input (pin 4). The comparator's operation is straightforward: when Vin is greater than Vref, V 0ut (at pin 2) goes high. Conversely, when Vin is less than Vref, V 0ut goes low. ....-------+9V Rl 1k Fig.2: in this basic comparator circuit, Vout goes high when Vin is greater than Vref· The reference voltage (Vref) determines the comparator's toggle point. Fig.3 illustrates the comparator's response (Voutl as Vin is varied with respect to V ref· For inverting operation (ie, Vout high when Vin is less than Vref), all we have to do is swap Vref and Vin at the comparator's pin connections in Fig.2. The reference is now connected to the + input while Vin TIME (a) + VOLTS Voull:::====------------~====-..TIME (b) Fig.3: this diagram shows the relationship between the input and output voltages for the comparator represented in Fig.2. The upper graph (A) shows the inputs to the comparator's + and - inputs while the lower graph (B) shows the circuit's output response. R2 390{! +9V--+-------~Niltr--. Rl 10k 2 (a) 8 .,. Rl 390{! +9v--.....-~~--, (b) (c) Fig.4: here are three ways of using a light-emitting diode (LED) to indicate the electrical output state of a comparator. pull-up resistor Rl, and the collector current through Ql lights the LED. When Vin is less than V ref, pin 2 is low and Ql is cut off, turning the LED off. Resistor RZ limits the current through the LED. The circuit in Fig.4b is similar to Fig.4a but this time the comparator controls a PNP transistor. When pin 2 goes low, Ql turns on and lights the LED, giving the opposite effect of the NPN circuit in Fig.4a. Fig.4c shows yet another option for connecting a LED. Typical current-sink capability of the LM339 is 16 milliamperes. This is enough current to light a highefficiency LED directly, without using a driver transistor. The circuits in Fig.4 are shown using one of the four identical comparators in the LM339. In these and the circuits that follow , the inputs to unused comparators on the chip should be tied to ground. The power supply rails should be connected at pins 3 (positive) and 12 (ground) as shown in Fig.2. Achieving snap action The circuits shown so far all have limitations. If Yin has noise riding on it, the output may chatter high and low as Vin approaches V ref· A slowly changing input may also caus'e the output to oscillate as Vin nears the trip voltage. Adding a little positive feedback can take care of both of those problems. Fig.5 shows a temperature-monitoring circuit with positive feedback via resistor R6. The trip voltage is set with potentiometer R4 . The sensed voltage is taken from a voltage divider containing a thermistor (temperature-dependent resistor) and resistor RZ. As the temperature of thermistor Rl increases, its resistance decreases because it has a negative temperature coefficient. The·resulting drop in the network's resistance increases the current through RZ, raising the voltage at pin 4 of the LM339. Here's how the positive feedback works. When the output at pin 2 is high, a small part of the output voltage feeds back through R6 to pin 5. This raises the voltage at pin 5 so that it is slightly higher than the level set by R4. When rising temperatures subsequently cause pin 4 to go higher than pin 5, pin 2 goes low, buzzer BZl is energised, and the voltage at pin 5 drops , this time to a level slightly lower than that previously set by R4. The buzzer thus remains on until the temperature falls enough so that pin 4 is less than pin 5 aga in. r-----------.----..--+9V Rl THERMISTOR PIEZO BUZZER 10k AT 25 ° C goes to the - input. V 0 ut will now be high when Vin is less than V ref and will switch low when Vin exceeds Vref· A light emitting diode (LED) provides a simple indicator of a comparator's output state. The circuits in Fig.4 show several ways of interfacing a LED to a comparator's output. In Fig.4a, when Vin is greater than Vref, pin 2 goes high, transistor Ql turns on through .,. R6 1M Fig.5: in this circuit, a piezoelectric buzzer sounds at and above a temperature selected by potentiometer R4. Positive feedback through R6 ensures that the buzzer snaps on decisively at the trip voltage. FEBRUARY1989 29 ..-----------+-------+9V Because the turn-on voltage is higher than the turn-off voltage, the buzzer snaps on decisively at the desired temperature and remains on until the temperature drops. How much feedback? The feedback resistor (R6 in Fig.5) is usually chosen to be much larger than the input resistor (R5). Its precise value isn't critical but the smaller it is, the greater will be the difference between the turn-on and turn-off trip voltages. Although you can calculate the effects of the feedback mathematically, for basic alarm circuits like this it's often just as easy to set the trip point by experimentation. You simply bring Rl to the desired alarm temperature and adjust R4 so that the buzzer just turns on. As shown, the difference between the trip points in Fig.5 is around 400 millivolts. Positive feedback is also useful in relay-control circuits. Fig.6 shows a light-sensing circuit that controls a relay. The light sensor, R2, is a cadmium-sulphide light dependent resistor; its resistance decreases as the light level increases. As the light level goes up, pin 4 is progressively pulled lower by the decreasing resistance of the light dependent resistor. When its voltage is less than the voltage on pin 5, pin 2 goes high and turns on Ql, activating relay RLYl. Resistor R6 makes sure that RLYl turns on and stays on until the light level has fallen by a preset amount (as determined by the value of feedback resistor R6). .,.. Fig.7: this single-ended comparator circuit can be used to measure voltages that would otherwise exceed the comparator's input voltage rating. single-ended configuration, Vref is proportional (but not equal) to the trip voltage of Vin· If R2 is made much larger than R3, the voltage at pin 5 will remain well within the differential input rating, even with very large input voltages. For example, in Fig.7, if Vref is set at - lV, the trip voltage at Vin is + lOOV! One important limitation of the single-ended configuration is that Vref must be of the opposite polarity from the trip voltage. In the circuit shown in Fig. 7, Vref is always negative, so the trip voltage will always be positive. Germanium diode Dl protects the comparator by limiting negative voltage inputs to - 0.3V. Creating a window What if you want to determine if a voltage falls between an upper and a lower limit? A window detector is the answer and the LM339, with its multiple comparators and open-collector outputs, is ideal for that use. In Fig.8, the thermistor/resistor voltage divider of R4 and R5 connects to the - input of one comparator and the + input of another. The trip points for the comparators are taken from another voltage divider made up of Rl, R2 and R3. Because the outputs of the LM339 have open (uncommitted) collectors, they can be connected together as shown, and a low output on either one will pull their combined outputs low. When Vin falls between Vref-high and Vref-low, the outputs of both comparators go high and turn on LED Monitoring large voltages An important characteristic of comparator devices is their differential input voltage rating. This is the maximum voltage difference allowed between the + and - inputs of the device for correct operation. Many comparators, including the LM339, can handle input differences nearly as large as the difference between their positive and negative supply pins. If you need to monitor voltages larger than the input rating allows, a voltage divider can be used to derive a proportion of the total voltage. Alternatively, a singleend.e d comparator like the one, shown in Fig.7 can be used. Here, Vin and Vref connect through resistors R2 and R3 respectively to the + input of the comparator, while the - input is grounded through Rl. In the r----.----f-----..----+-~+9V R4 NTC THERMISTOR 10k AT 25 ' C R6 10k r--------------+----+------+9V 01 R7 10k 1N914 .____ I RLY1 Vin C i::::: R2 CdS PHOTO-RESISTOR R5 .,. .,. 10k R6 20k Fig.6: light dependent resistor R2 is used here to sense the light level. When the light rises above a preset level, as se_t by potentiometer R4, the output of the comparator switches high and turns on transistor Ql and the relay. 30 LM339 ~ SILICON CHIP .,. Fig.8: this window detector circuit lets the experimenter know when the detected temperature is within a pre-selected range. Resistors Rl, R2 and R3 set the comparator trip points and thus determine the upper and lower limits. +9v_..._......_ _ _ _ _ _ _ _ _ __ 1. But if Vin is greater than V ref-high or less than Vref-low, the output goes low and LED 1 is off. The LED is on only when the temperature is within the window set by resistor network Rl, RZ and R3. Fig.9 is similar but different - it's an out-of-window detector. In this circuit, the output of the bottom comparator goes high when the temperature is too high, lighting LED 2 [red). Similarly, the output of the top comparator goes high and lights LED 1 [green) when the temperature is too low. When the temperature falls within the window, both comparator outputs are low and the light-emitting diodes are off. REGULATED VOLTAGE SOURCE R3 1.2V 1.2k R4 Sk Bargraph display The final example [Fig.10} is a light meter with bargraph output. The circuit design has been made easier by using an LM3915 bargraph driver IC which contains a series of 10 comparators. The - input of each comparator connects to the buffered input voltage and the + inputs connect along a 10-resistor voltage divider network. This divider network biases each of the non-inverting outputs to a different level. The top of the resistor string [pin 6) is connected to a regulated voltage which can be varied by potentiometer R4. This means that the output of the top comparator only switches low when the voltage from the buffer amplifier exceeds the voltage on pin 6. The previous LEDs in the series are turned on in 3dB steps in response to a rising input signal on pin 5. This pin connects via a ZOkO resistor to ther buffer amplifier. To use the LM3915, you need only add a sensing circuit and connect the comparator outputs to a bargraph display or a succession of 10 light-emitting diodes. In Fig.10, the input at pin 5 of ICl is taken from a voltage divider made up of Rl [a cadmium-sulphide photo-resistor) and RZ. Each comparator inside ICl compares the buffered input voltage to its reference and turns its LED on or off, as appropriate. The R7 390H +9V--+----.----+----YN,.---. R1 20k R4 10k R2 10k IC1 LM3915 +9V R1 CdS PHOTORESISTOR .,. Fig.10: the LM3915 IC contains a series of 10 comparators and can be used to drive a bargraph display. In this circuit, the number of LEDs lit in the display varies with the light level sensed by photoresistor Rl. number of LEDs that light thus varies with the light level at Rl. Resistor R3 sets the current in each of the light emitting diodes at 10 milliamperes (lOmA), while potentiometer R4 varies the full scale [ie, all LEDs on) input voltage between 1.2V and 7V. Leaving pin 9 of ICl unconnected will change the display from a bargraph to a single-dot display. In that mode, only one LED is lit at a time [which saves on battery power). The position of the LED indicates the signal level and thus the light intensity. Now it's your turn R3 20k RS HTC THERMISTOR ' 10k AT 25°C Fig.9: an out-of-window comparator detector circuit. When the temperature is too high, the output of the bottom comparator goes high and lights LED 2 (red). Conversely, when the temperature is too low, the output of the top comparator goes high and lights LED 1 (green). Comparators are circuit building blocks that are both easy to use and adaptable to many circuit situations. By carefully studying the circuits presented in this article, you should be able to adapt them to your own specialised requirements. le This article first appeared in Hands -On Electronics, USA (August 1988); reprinted with permission. FEBRUARY1989 31