AN1517
AN1517
AN1517
R6
GAIN = 1 +
R5
where R6 = R3 and R4 = R5
Comparator Stage
R7
10.0 kΩ
VTH
Amplifier Stage
R4 R11
R6
100 Ω 4.75 kΩ
20 kΩ
R1
12.1 kΩ CN1
U1 R5
100 Ω U1 R10 Vout
R3 24.3 kΩ
GND
20 kΩ + +5 V
+ +
U1 V4
Roff LM324D Q1
MMBT3904LT1
RH
RTH 121 kΩ
10 kΩ
3 4
X1
MPX2100DP
2
1
Pressure Sensor
Figure 1. Pressure Switch Schematic
AN1517
Sensors
2 Freescale Semiconductor
difference between logic states and will avoid having a LM311 USED IN A COMPARATOR CIRCUIT
microcontroller read the switch level as being in an
The LM311 chip is designed specifically for use as a
indeterminate state.
comparator and thus has short delay times, high slew rate,
• In order to be compatible with CMOS circuitry and to avoid and an open collector output. A pull-up resistor at the output is
microcontroller timing delay errors, the comparator must all that is needed to obtain a rail-to-rail output. Additionally, the
switch sufficiently fast. LM311 is a reverse logic circuit; that is, for an input lower than
• By using two comparators, a window comparator may be the reference voltage, the output is high. Likewise, when the
implemented. The window comparator may be used to input voltage is higher than the reference voltage, the output
monitor when the applied pressure is within a set range. is low. Figure 2 shows a schematic of the LM311 stage with
By adjusting the input thresholds, the window width can be threshold setting resistor divider, hysteresis resistor, and the
customized for a given application. As with the single open-collector pull-up resistor. Table 2 shows the
threshold design, positive feedback can be used to comparator's performance. Based on its performance, this
provide hysteresis for both switching points. The window circuit can be used in many types of applications, including
comparator and the other comparator circuits will be interface to microprocessors.
explained in the following section. The amount of hysteresis can be calculated by the following
equations:
EXAMPLE COMPARATOR CIRCUITS R2
V REF = ---------------------- V CC
Several comparator circuits were built and evaluated. R1 + R2
Comparator stages using the LM311 comparator, LM358 Op-
Amp (with and without an output transistor stage), and LM339 neglecting the effect of RH
were examined. Each comparator was evaluated on output
R1R2 + R2R H
voltage levels (dynamic range), transition speed, and the VREFH = ---------------------------------------------------------------- V CC
relative component count required for the complete pressure R1R2 + R1R H + R2R H
switch design. This comparison is tabulated in Table 2.
R2R H
VREFL = ---------------------------------------------------------------- V CC
VCC R1R2 + R1R H + R2R H
RH
R2
AN1517
Sensors
Freescale Semiconductor 3
VREF (including RH in the circuit), recompute R1 taking into extends from rail to rail and has a sufficiently high switching
account that VREF depends on R1, R2, and RH. It turns out that speed. The LM358 will perform well in applications where the
when the normal state is below VREF, RH is in parallel with R1: switching speed and logic-state levels are not critical (LED
output, etc.). The design of the LM358 comparator is
R2 accomplished by using the same equations and procedure
V REF = ------------------------------------- V CC
R1 || R H + R2 presented for the LM311. This circuit is also reverse logic.
VCC
Normal State
U1 RPU
R1 Vout
LM358
Vin RB Q1
VREFH MMBT3904LT1
Hysteresis
VREF (VREFLW)
RH
Figure 3. Setting the Reference Voltages
R2
LM358 OP AMP USED IN A COMPARATOR CIRCUIT
Figure 4 shows the schematic for the LM358 op amp
comparator stage, and Table 2 shows its performance. Since
the LM358 is an operational amplifier, it does not have the fast Figure 5. LM358 with a Transistor Output Stage
slew-rate of a comparator IC nor the open collector output. Comparator Circuit Schematic
Comparing the LM358 and the LM311 (Table 2), the LM311 is
better for logic/switching applications since its output nearly
AN1517
Sensors
4 Freescale Semiconductor
Like the other two circuits, this comparator circuit can be combination of R2 and R3 (named R23 for identification) to
designed with the same equations and procedure. The values obtain the desired value for VREFUW, neglecting the effect of
for RB and RPU are chosen to give a 5:1 ratio in Q1's collector RHU:
current to its base current, in order to insure that Q1 is well- R23
saturated (VOUT can pull down very close to ground when Q1 V REFUW = ------------------------- V CC
R1 + R23
is on). Once the 5:1 ratio is chosen, the actual resistance
values determine the desired switching speed for turning Q1 The amount of hysteresis can be calculated by the following
on and off. Also, RPU limits the collector current to be within equation:
the maximum specification for the given transistor (see
example values in Figure 1). Unlike the other two circuits, this R23R HU
V REFUW = -------------------------------------------------------------------------------- V CC
circuit is positive logic due to the additional inversion created R1R23 + R1R HU + R23R HU
at the output transistor stage.
Notice the upper window reference voltage, VREFUW, is
LM339 USED IN A WINDOW
now equal to its VREFL value, since at this moment, the input
COMPARATOR CIRCUIT voltage is above the normal state.
Using two voltage references to detect when the input is
within a certain range is another possibility for the pressure HYSTERESIS = V REFUW – V REFL
switch design. The window comparator's schematic is shown
in Figure 6. The LM339 is a quad comparator IC (it has open where VREFL is chosen to give the desired amount of
collector outputs), and its performance will be similar to that of hysteresis for the application.
the LM311. The initial calculation for VREFUW will be slightly in error due
to neglecting the effect of RHU. To establish a precise value for
VCC
VREFUW (including RHU in the circuit), recompute R1 taking
into account that VREFUW depends on R2 and R3 and the
parallel combination of R1 and RHU. This more precise value
1 1 is calculated with the following equation:
R1 RPU
2 U1 2 R23
V REFUW = --------------------------------------------- V CC
LM339 R1 || R HU + R23
4
2
5 for the lower window threshold choose the value for VREFLW.
VREFUW
2 1
R3
1 RHU VOUT SetV REFLW = -------------------------------------------------------- V CC
R1 || R HU + R2 + R3
R2
2
U1
6 where R2 + R3 = R23 from above calculation.
VREFLW 1
2 1 7
To calculate the hysteresis resistor:
R5
The input to the lower comparator is one half VIN (since
2 1
R4 =R5) when in the normal state. When VREFLW is above
1 1 RHL
R4 one half of VIN (i.e., the input voltage has fallen below the
R3
2 2 window), RHL parallels R4, thus loading down VIN. The
resulting input to the comparator can be referred to as VINL (a
lower input voltage). To summarize, when the input is within
Figure 6. LM339 Window Comparator Circuit Schematic the window, the output is high and only R4 is connected to
Obtaining the correct amount of hysteresis and the input ground from the comparator's positive terminal. This
reference voltages is slightly different than with the other establishes one half of VIN to be compared with VREFLW.
circuits. The following equations are used to calculate the When the input voltage is below VREFLW, the output is low, and
hysteresis and reference voltages. Referring to Figure 3, RHL is effectively in parallel with R4. By voltage division, less
VREFUW is the upper window reference voltage and VREFLW is of the input voltage at VIN is required to make the noninverting
the lower window reference voltage. Remember that input exceed VRELW.
reference voltage and threshold voltage are interchangeable Therefore, the following equations are established:
terms.
For the upper window threshold:
Choose the value for VREFUW and R1 (e.g., 10 kΩ). Then,
by voltage division, calculate the total resistance of the
AN1517
Sensors
Freescale Semiconductor 5
HYSTERESIS = V REFLW – V INL If hysteresis is desired, refer to the LM311 Used in a
Comparator section to determine RH.
Choose R4 = R5 to simplify the design. 2. To test this design, connect a +5 volt supply between pins
3 and 4 of the connector CN1.
R4R5 ( V REFLW – V INL – V CC )
R HL = ---------------------------------------------------------------------------------------V CC 3. Connect a volt meter to pins 1 and 4 of CN1 to measure
( R4 + R5 ) ( V INL – V REFLW ) the output voltage and amplified sensor voltage,
respectively.
NOTE:
As explained above, because the input voltage is divided in 4. Connect an additional volt meter to the VTH probe point to
half by R4 and R5, all calculations are done relative to the one verify the threshold voltage.
half value of Vin. Therefore, for a hysteresis of 200 mV 5. Turn on the supply voltage.
(relative to Vin), the above equations must use one half this
6. With no pressure applied, check to see that Voff is correct
hysteresis value (100 mV). Also, if a VREFLW value of 2.0 V is
by measuring the voltage at the output of the gain stage
desired (relative to Vin), then 1.0 V for its value should be used
(the volt meter connected to Pin 4 of CN1). If desired, Voff
in the above equations. The value for VINL should be scaled
can be fine tuned by using a potentiometer for Roff.
by one half also.
The window comparator design can also be designed using 7. Check to see that the volt meter monitoring VTH displays
operational amplifiers and the same equations as for the the desired voltage for the output to change states. Use a
LM339 comparator circuit. For the best performance, potentiometer for RTH to fine tune VTH, if desired.
however, a transistor output stage should be included in the 8. Apply pressure to the sensor. Monitor the sensor's output
design. via the volt meter connected to pin 4 of CN1. The output
will switch from low to high when this pressure sensor
TEST/CALIBRATION PROCEDURE voltage reaches or exceeds the threshold voltage.
1. Before testing the circuit, the user-defined values for RTH, 9. If hysteresis is used, with the output high (pressure
RH and Roff should be calculated for the desired sensor voltage greater than the threshold voltage), check
application. to see if VTH has dropped by the amount of hysteresis
The sensor offset voltage is set by desired.
A potentiometer can be used for RH to fine tune the amount of
V OFF
V OFF = -------------------------------V CC hysteresis.
R1 + R OFF
CONCLUSION
Then, the amplified sensor voltage corresponding to a The pressure switch design uses a comparator to create a
given pressure is calculated by: logic level output by comparing the pressure sensor output
VSENSOR = 201 × 0.0002 × APPLIED PRESSURE + VOFF, voltage and a user-defined reference voltage. The flexibility of
this minimal component, high performance design makes it
where 201 is the gain, 0.0002 is in units of V/kPa and compatible with many different applications. The design
APPLIED PRESSURE is in kPa. presented here uses an op amp with a transistor output stage,
The threshold voltage, VTH, at which the output changes yielding excellent logic-level outputs and output transition
state is calculated by determining Vsensor at the pressure that speeds for many applications. Finally, several other
causes this change of state: comparison stage designs, including a window comparator,
are evaluated and compared for overall performance.
RTH
VTH = VSENSOR (@ pressure threshold) = VCC
R7 + RTH
AN1517
Sensors
6 Freescale Semiconductor
NOTES
AN1517
Sensors
Freescale Semiconductor 7
How to Reach Us:
Home Page:
www.freescale.com
Web Support:
http://www.freescale.com/support
USA/Europe or Locations Not Listed:
Freescale Semiconductor, Inc.
Technical Information Center, EL516
2100 East Elliot Road
Tempe, Arizona 85284
+1-800-521-6274 or +1-480-768-2130
www.freescale.com/support
AN1517
Rev. 4
11/2006