Amplifier DesignIn order to design the interface between a sensor and the MCU, we need to specify the performance of a linear amplifier which will translate the output of the sensor into
Trang 1Amplifier Design
In order to design the interface between a sensor and the MCU, we need to specify the performance of a linear amplifier which will translate the output of the sensor into a suitable input for the MCU, which is in the right range for the amplifier to handle and allows a convenient conversion factor to be used in the ADC For example, our standard temperature sensor with built-in signal con-ditioning produces an output of 10 mV per degree C, with an output range of
⫺55 to ⫹150°C Let us assume it is to be interfaced to a PIC MCU to meas-ure between 10 and 35°C
Gain
At 10°C, the input will be 10 ⫻ 10 ⫽ 100 mV At 35°C, it will be 35 ⫻ 10 ⫽
350 mV The gain is calculated as the required change in the output divided by the range of the input Now if we are using a single supply op-amp package, such as the LM324, the output range is strictly limited The output only goes down to about 50 mV and up to about 3.5 V So if we assume an output swing
of 2.5 V is available, the gain required ⫽ 2.5/(0.35–0.1) ⫽ 10
Offset
As in this case, sensors often have a positive offset, so the output range has to
be shifted down With a gain of 10, the output at the lowest temperature will
be 100 mV ⫻ 10 ⫽ 1.00 V, and at the highest 350 mV ⫻ 10 ⫽ 3.50 V This can
be shifted down by 1.00 V, so that the output range will be 0 –2.50 V This also allows us to use a reference voltage of 2.56 V, just above the required maxi-mum, which gives a convenient 8-bit conversion factor (10 mV/bit) Including
0 V in the output means that we will lose the lowest degree or two from the range If this is not acceptable, the offset can be adjusted to suit, so that the out-put ranges from 0.5 to 3.0 V In this case, the negative reference voltage for the ADC should be modified to 0.5 V, and the positive reference to 3.06 V If nec-essary, corrections can also be made in software
Frequency Response
Since we are measuring direct voltages, it is sensible to restrict the frequency response of the amplifier to low frequencies, as any instability in operation tends to produce high-frequency oscillation and incorrect DC readings A moderate value of capacitance across the feedback network will reduce the fre-quency response by reducing the feedback impedance at high frefre-quency However, too high a value will slow down the response time, so this needs to
be considered if transient behaviour is a significant consideration
Trang 2A circuit which meets these requirements is shown in Figure 10.3 It is based
on a non-inverting amplifier configuration, with the offset added as a positive voltage at the reference input The temperature sensor input is represented by three selected levels, corresponding to the minimum (100 mV), mid-range (225 mV) and maximum (350 mV) output voltage The gain is notionally 10, but is adjusted by the reference input resistance The offset input is notionally
100 mV, but is also adjustable
Calibration of the amplifier normally consists of adjusting the gain and the offset at the minimum and maximum output levels, assuming that it is linear
in between these values However, there is a problem with the single supply case – the minimum output is not reached because the amplifier cannot reach the supply rail voltage (0.000 V) In the simulation, the minimum reached is about 80 mV The output gives a resolution of 100 mV/°C, so readings from 10
to 11°C will be affected, leaving an operating range of 11–35°C This will be accepted If unacceptable, the operating range can be modified by adjusting the offset input voltage and recalibrating
Figure 10.3 Gain and offset adjustment
Trang 3Therefore, in this circuit, we will calibrate the amplifier by adjusting the offset to approximately the correct value at the mid-output level (1.280 V), and then adjusting the gain to give the right output at the maximum level (2.500) These steps are then repeated until the reading is correct at the mid and max values This is usually necessary because the gain and offset inter-act, that is, adjusting one affects the other In practice, multi-turn pre-set pots (typically 10 turns) are often used to give greater sensitivity or range to the adjustment
In this circuit, a relatively small offset voltage is required, and it is obtained
by taking the forward volt drop of a standard signal diode (about 0.7 V) and di-viding it down to around 100 mV A fine adjustment of this is then obtained by
‘squeezing’ the diode voltage via its current supply A diode current of about
10 mA is used, dissipating about 10 ⫻ 0.7 ⫽ 7 mW in the diode It is possible that self-heating in the diode could cause some temperature instability If nec-essary, a more stable reference circuit design should be used, or, at the very least, the circuit temperature should be allowed to reach a steady state before the calibration procedure is attempted
The accuracy of the sensor is quoted as ⫹/⫺0.5°C, and the interface needs
to match this The output changes by 100 mV/°C, so 0.5°C ⫽ 50 mV At mid-range, 22.5°C, the output is 1.28 V, and the allowed range is 1.23–1.33 V The accuracy of the amplifier should in fact be better than ⫹/⫺10 mV, and this is more than adequate The ADC will be working at 2.56 V/256 ⫽ 10 mV/bit, the same resolution
Weather Station
To illustrate sensor interfacing, a weather station measuring temperature, light, pressure and humidity will be designed These variables will be sampled at an interval of 5 minutes (12/hour) and data stored for a period of up to 10 days The specification is detailed in Table 10.4
The system will be based on a general purpose module using the PIC 16F877, an LCD and a serial memory, details of which will be provided in the next chapter It has a 12-button keypad, 16 ⫻ 2 line backlit display and a 16 kb serial memory (Figure 10.4) Each variable will occupy eight characters on screen in run mode If sampled at 8-bit resolution, one sample for each sensor
⫽ 1 byte of data Over 10 days, the system will store 10 ⫻ 24 ⫻ 12 ⫻ 4 ⫽
11520 bytes of data The user should be able to reset, run and read back data manually Optionally, an RS232 link to host computer will allow the data to be downloaded for further analysis and long-term storage
Trang 4The ADC inputs will be connected to this module via a 10-way ribbon cable, with the analogue interfaces built on a separate board A sensor was selected for each weather variable, primarily based on the range required, ease of inter-facing and low cost An analogue interface was then developed to provide the gain and offset required for each Signal filtering was not considered in detail, but the possibility of controlling high-frequency interference and noise always needs to borne in mind Typically, some low-pass filtering or decoupling may
be included in the interface as a pre-caution when conditioning DC signals This may be in the form of a simple first-order CR network in the input, and
an integrating capacitance connected across the feedback resistance in the
Table 10.4 Weather station specification
MCU
Temp Sensor -25 ° C to +75 ° C
Light Sensor
1 – 10 6 lux
Gain = 2
Pressure Sensor 850mb – 1100mb
Humidity Sensor
= 0.645
Gain = 1
Gain = 69
LCD
2 X 16
Keypad 3x4
EEPROM 16kb
10mV/ ° C
5 levels (0 - 2.5V)
-21.75mV to +14.5mV 0.145mV/mb
0.8V – 3.9V 0.31V/%
0 – 2.00V 20mV/ ° C
0 – 2.55V Offset = +250mV
0 – 2.55V 10mV/mb Offset = +1.50V
0 – 2.55V
Figure 10.4 Block diagram of weather station
Trang 5amplifier stage The maximum source resistance allowed at the PIC ADC input
is 10 k; a low-pass filter with a 1 k series resistance and 100 nF decoupling capacitor will give a cut-off frequency of around 2 kHz
Temperature Sensor Input
The default choice for this sensor is the LM35 type The performance is ade-quate for this application, and it is possible to connect it direct to the ADC input In this case, the LM35C is used which allows negative temperatures to
be measured To provide these as a positive voltage with single supply, the sen-sor negative supply is connected to ground via a diode to lift the zero degrees output to around 0.7 V This allows the actual output voltage to go below the zero level while remaining positive with respect to supply 0 V (Figure 10.5) (a)
(b)
LM35C
+5v
Vo = -250mV
to +750mV
0V 18k
Figure 10.5 Temperature sensor interface: (a) sensor connections; (b) interface simulation
Trang 6The interface uses a differential amplifier with two positive and two neg-ative inputs, based on the universal amplifier described previously The number of positive and negative inputs must always be equal to conform to this model A reference diode provides a negative input to balance the pos-itive offset on the sensor input The input from the sensor is simulated by a switch which provides the maximum and minimum voltage which would be seen at the input A further positive input provides the offset at the ampli-fier output to give 0.00–2.00V corresponding to the input range of 100°C The overall sensitivity is 20 mV/°C A further negative input of 0 V is needed to match the offset input The preset feedback resistance is adjusted for a gain of 2.00
The circuit provides the following arithmetic sums at each end of the range (⫺25°C and ⫹75°C)
The 6 mV at the output (3 mV at the input) is the offset of the amplifier, which is allowed for in the external offset adjust (250–3 ⫽ 247 mV) Notice that in the simulation there is a residual offset at 2.000 V output, but this is less than 5 mV, which is acceptable (⬍0.5% at full scale) The reference diode cur-rent may need to be adjusted in the real hardware by changing its 1k curcur-rent feed resistor to a value that gives the same current as that provided by the sen-sor to its offset diode
When converted with a 2.56 V reference, the temperature range will be rep-resented by binary numbers equivalent to 0–200, with 50 representing 0°C This scaling offset can be corrected in software, prior to display Remember that the single supply amplifier output will not go all the way to zero, so the actual range starts at about ⫺23°C In normal circumstances, this is accept-able, as this temperature is rarely experienced in temperate climates
Light Sensor Input
The light sensor input is designed around the standard NORP12 cadmium disulphide-LDR It has a spectral response which is similar to the human eye, and is sensitive to a wide range of values of light intensity and is relatively easy
to interface Its resistance is inversely proportional to light intensity, as shown
in Figure 10.6 (b)
The light level is divided into five decades, from ⬍1 lux (dark) to ⬎10000 lux (direct sun), so the output levels are similarly divided When the LDR is connected in series with a 4k7 resistor across the 5 V supply, a set of voltages
is obtained which vary from 2.5 V (high resistance, dark) to 0 V (low resistance,
Trang 7light) In the simulated interface, these values are represented by switched par-allel resistances, with the sensor voltage simply buffered by a unity gain ampli-fier (Figure 10.6 (c)) The software can then compare the input with any chosen set of limits, which correspond to the required light levels The actual reading will be stored for further analysis
Pressure Sensor Interface
Measurement of barometric pressure is not particularly straightforward, since pressure measurement in usually made relative to atmosphere (1 bar ⫽ 1000 mb) For example, it is straightforward to measure a low-pressure air supply for a pneumatic system operating at 5 bar One side of the gauge diaphragm is
(c)
10-1 100 101 102 103 104
106
105
104
103
102
Dark Dusk Dull Cloud Sun
+5V
4k7
LDR
102Ω - 106Ω
Light (lux)
Figure 10.6 Light sensor interface: (a) sensor connection; (b) LDR characteristic; (c) interface
simulation
Trang 8exposed to atmosphere, while the pressurised system is connected to the other side Small deviations from atmosphere caused by meteorological variation are more difficult to measure accurately
It is suggested here that one side of the gauge is connected to a closed tube rep-resenting 1 atmosphere, while the other is exposed to the varying meteorologi-cal pressure Careful meteorologi-calibration will be required, with temperature compensation for its effect on the fixed volume of air This temperature measurement is avail-able from sensor input described above
Low-cost pressure sensors use a strain gauge bridge made up of laser-trimmed piezo-resistive elements in a compact, robust package A pressure in the range of 850–1106 mbar is proposed (range ⫽ 256 mbar), allowing an 8-bit conversion at 1 8-bit per mbar Standard atmospheric pressure will then occur
at a reading of 150
The gauges investigated are rated in psi (pounds per square inch) 1 psi ⫽ 69 mbar, so the range required is 256/69 ⫽ 3.71 psi A gauge is available which measures up to 5 psi with a 10 V supply If the supply is ⫹5 and 0 V, the output will be ⫹/⫺2.5 psi, with a sensitivity of 5 mV/psi and offset of 2.5 V This is equivalent to 5/69 ⫽ 0.0725 mV/mbar The range will then be 256 ⫻ 0.0725mV
⫽ 18.56 mV The amplifier gain required is therefore 2.56 V/18.56 mV ⫽ 138 The output offset at 1000 mbar input will be 1.50 V The low end will be cur-tailed by the output of the single supply amp not quite being reaching zero, but
as this will be an extreme event, this is acceptable The input and output volt-ages are then as follows:
Output V outzero ⫽ 1.50 V
If the standard instrumentation amplifier is used (Chapter 7), gain G⫽ 1 ⫹
2R2/R1, where R1and R2are the values in the input stage
) R2/R1⫽ (G⫺1)/2 ⫽ (138⫺1)/2 ⫽ 68.5
If R1 ⫽ 1k, R2⫽ 68k ⫹ 470R
Trang 9The offset voltage (⫹1.50 V) will be input at the non-inverting reference input This can also include some adjustable element to compensate for the amplifier input offset Figure 10.7 (b) shows the circuit simulation operating with the maximum input
Humidity Sensor Interface
The humidity sensor selected has integrated signal conditioning so that an output between 0.8 and 3.9 V is produced, representing a change in relative
(a)
(b)
+5V
Peizo-Resistive Bridge
5mV/PSI
Figure 10.7 Pressure sensor interface: (a) sensor connections; (b) interface simulation
Trang 10humidity of 0–100% A simple buffered attenuator is used to shift the signal range for input to the ADC The output of 0 V from the single supply ampli-fier cannot be obtained, so the output is shifted up to the range 0.5–2.50 V, giving 20 mV/% This offset must be removed in software, by subtracting 5010 from the 8-bit binary input
) Required gain ⫽ 2.00/3.1 ⫽ 0.645 (attenuation)
; Use unity gain ⫹ output attenuator
The small residual offset is easier to eliminate in software, by adjusting the offset correction factor, and subtracting 52 instead of 50 This allows preferred values to be used in the attenuator, reducing component cost The input and output buffering of the attenuator network simply reduces any error due to loading effects However, the sensor is only specified about 4% accurate normally, so this may not be absolutely necessary The sensor can be supplied with individual calibration data if a more accu-rate output is needed Figure 10.8 shows the simulated interface operating at 100% humidity
Figure 10.8 Humidity sensor interface