1. Trang chủ
  2. » Công Nghệ Thông Tin

Interfacing PIC Microcontrollers 26 doc

10 203 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 315,65 KB

Nội dung

Amplifier 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 frequency. However, too high a value will slow down the response time, so this needs to be considered if transient behaviour is a significant consideration. Interfacing PIC Microcontrollers 236 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 236 Calibration A 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. Sensor Interfacing 237 Figure 10.3 Gain and offset adjustment Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 237 Therefore, 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. Interfacing PIC Microcontrollers 238 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 238 The 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 Sensor Interfacing 239 Input Range Display (Max 8 Chars) Temperature Ϫ25°C to ϩ75°C Temp:XX (7) Light Dark, dusk, dull, cloud, sun XXXXX (5) Pressure 850–1100 millibar mbar:XXXX (8) Humidity 0–100% Relative humidity RH:XXX% (7) Precision 8-bits Ͻ1% @ mid range Storage 10 days @ 12 samples/h 11520 bytes User Run, recall data Essential interface Display/set date and time Desirable Host Data download to database and Desirable interface spreadsheet 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 – 100% RH Attenuation = 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 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 239 amplifier 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). Interfacing PIC Microcontrollers 240 (a) (b) LM35C +5v Vo = -250mV to +750mV 0V 18k Figure 10.5 Temperature sensor interface: (a) sensor connections; (b) interface simulation Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 240 The 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). 2.000 x (443 ϩ 247 Ϫ 693 Ϫ 0) ϭϪ 6 mV @ Ϫ 25°C 2.000 x (1443 ϩ 247–693–0) ϭϪ 6 mV @ ϩ 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 current 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, Sensor Interfacing 241 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 241 light). 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 Interfacing PIC Microcontrollers 242 (a) (b) (c) 10 -1 10 0 10 1 10 2 10 3 10 4 10 6 10 5 10 4 10 3 10 2 R (Ω) Dark Dusk Dull Cloud Sun +5V 4k7 LDR 10 2 Ω - 10 6 Ω Light (lux) Figure 10.6 Light sensor interface: (a) sensor connection; (b) LDR characteristic; (c) interface simulation Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 242 exposed 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 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 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: Input V inzero ϭ 0 mV V inmin ϭ 0.0725 ϫϪ140 ϭϪ10.15 mV (Ͻ140 not used) V inmax ϭ 0.0725 ϫ 100 ϭ 7.25 mV Output V outzero ϭ 1.50 V V outmin ϭ 1.50–1.40 ϭ 0.10 V V outmax ϭ 1.50 ϩ 1.00 ϭ 2.50 V If the standard instrumentation amplifier is used (Chapter 7), gain G ϭ 1 ϩ 2R 2 /R 1 , where R 1 and R 2 are the values in the input stage. ) R 2 /R 1 ϭ (GϪ1)/2 ϭ (138Ϫ1)/2 ϭ 68.5 If R 1 ϭ 1k, R 2 ϭ 68k ϩ 470R Sensor Interfacing 243 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 243 The 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 Interfacing PIC Microcontrollers 244 (a) (b) +5V Peizo- Resistive Bridge 5mV/PSI Figure 10.7 Pressure sensor interface: (a) sensor connections; (b) interface simulation Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 244 humidity 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 50 10 from the 8-bit binary input. Input range ϭ 3.9Ϫ0.8 ϭ 3.1 V Output range ϭ 2.50Ϫ0.50 ϭ 2.00 ) Required gain ϭ 2.00/3.1 ϭ 0.645 (attenuation) ; Use unity gain ϩ output attenuator Output max ϭ 3.9 ϫ 0.645 ϭ 2.516 Output min ϭ 0.8 ϫ 0.645 ϭ 0.516 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. Sensor Interfacing 245 Figure 10.8 Humidity sensor interface Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 245 . time, so this needs to be considered if transient behaviour is a significant consideration. Interfacing PIC Microcontrollers 236 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 236 Calibration A circuit. computer will allow the data to be downloaded for further analysis and long-term storage. Interfacing PIC Microcontrollers 238 Else_IPM-BATES_ch010.qxd 7/11/2006 2:55 PM Page 238 The ADC inputs. below the zero level while remaining positive with respect to supply 0 V (Figure 10.5). Interfacing PIC Microcontrollers 240 (a) (b) LM35C +5v Vo = -250mV to +750mV 0V 18k Figure 10.5 Temperature

Ngày đăng: 02/07/2014, 04:21

TỪ KHÓA LIÊN QUAN

w