A refresher tutorial on sensor design using microcontrollers: Part 1
A wide variety of sensors are used in digital control systems and interfacing them requires a good understanding of linear amplifier design and signal conditioning techniques. Connection to an MCU is simplified if the sensor itself contains built-in signal conditioning, such that the output is linear, reasonably large, conveniently scaled and pre-calibrated.
The LM35 temperature sensor is a good example, giving an output of 10 mV/degree Centigrade, starting at 0 degrees Centigrade = 0 mV, but it needs an ADC input. Increasingly, sensors are incorporating all the necessary signal processing and serial data outputs, so that interface design is simplified or eliminated. For example, Microchip supplies a range of temperature sensors with I2C output.The sensor is an essential device that responds to some environmental variable and converts it into electrical output. This signal may then need to be conditioned (filtered, amplified, attenuated, converted) to allow the MCU to receive the input in a usable form. Digital sensors may provide a direct input at TTL levels, while some analogue inputs might need a high-performance amplifier or complex digital processing.
The simplest form of digital sensor is a switch. A manually operated push button or toggle switch may only need a pull-up resistor, or possibly debouncing via a parallel capacitor, hardware latch or software process.
A micro-switch can be attached to a mechanical system so that it detects the position of, say, the guard on a machine tool. The machine controller can then be programmed not to start until the guard is closed. The micro-switch may often have an extended operating lever to make it more sensitive.
One disadvantage of the switch or relay contact is that physical wear causes unreliable operation. This problem can be overcome by using a switch which has no moving parts, or is specially designed for reliability.
A reed switch is enclosed in a vacuum and operated by the proximity of a magnet to the sprung contacts, which are gold-plated to reduce corrosion effects. The vacuum prevents burning at the contacts due to high-voltage discharge as they open or bounce with an inductive load.
Opto-electrical devices have no moving parts, and are therefore inherently more reliable. An LED and phototransistor are connected in separate circuits, with the transistor operating as a light-activated switch. The opto-isolator includes both in a single package, providing electrical isolation between control and load circuits, which may operate at high voltage. The signal to noise ratio may also be improved, and the digital signal thus cleaned up.
The same devices are used in an opto-detector where the light beam is interrupted by a moving object, grating or perforated wheel; this arrangement can be used to monitor position, speed or acceleration. Light transmission or reflection may be used, depending on measurement. The reflective type can be used as a simple proximity sensor, while position detection often uses a transmissive system.
The inkjet printer provides a good example of a
position system. A plastic strip with a fine grating is used to provide
position feedback for the print head. The simple periodic grating can
be made more precise by grading the light transmission sinusoidally
over a cycle, allowing calculation of fractions of a cycle
Axis position in
machine tools can be controlled down
to about 1 micrometer by this means. If a pair of gratings is used,
90 degrees Centigrade, the direction of travel can be detected by the phase
relationship. To establish absolute position, a reference position is
needed from which relative motion can be calculated.
For example, a robot arm may need to be started from a known home position. Alternatively, a Gray code can be used on the optodisk; each sector has a unique combination of light and dark bands, so that the absolute position of the stationary shaft can be detected by a set of sensors, one for each band.
The pattern is a modified binary code which only changes 1 bit at a time, to prevent incorrect data being sampled on the sector boundaries as shown in Figure 10.1 below.
|Figure 10.1 Incremental encoder: (a) linear encoder; (b) sinusoidal output; (c) Gray code optodisk (10 bit)|
Some sensors have a built-in data processing so that an MCU compatible signal is produced; for example, the measured variable may be converted into a periodic TTL signal.
This can be fed into a digital input, and the frequency determined in software by using a timer/counter to measure the number of pulses in unit time, or the period. Analogue to digital converter chips are available which convert the measured voltage into frequency, or transmit the binary form of the measurement in a standard serial format, such as I2C.
Analogue sensors produce a variable output, which may be voltage, resistance or current. In microcontroller systems, they are usually converted into a voltage in a range suitable for an input comparator (high/low detection) or analogue to digital conversion.
Suitable signal conditioning may be needed using amplifiers, filters and so on, to produce a clean signal, controlling noise, drift, interference and so on, with the required output range.
Sensors have certain characteristics which should be specified in the data sheet: Sensitivity, Offset, Range, Linearity, Error, Accuracy, Resolution, Stability, Reference level, Transfer function and Interdependence. The meaning of some of these is illustrated in Figure 10.2, below
|Figure 10.2. Sensor chacteristics|
Sensitivity. The ideal sensor characteristic is shown in the characteristic y = m1x. The sensor has a large change in its output for a small change in its input; that is, it has high sensitivity. The output could be fed directly into the analogue input of the MCU.
The line also goes through the origin, meaning no offset adjustment is required - a linear pot would give this result. If the sensor has low sensitivity ( y = m2x), an amplifier may be needed to bring the output up to the required level.
Offset. Unfortunately, many sensors have considerable offset in their output. This means, that over range for which they are useful, the lowest output has a large positive constant added (y = m3x + c).
This has to be subtracted in the amplifier interface to bring the output back into the required range, where maximum resolution can be obtained. The same can be achieved in software, but this is likely to result in a loss of resolution.
Temperature sensors tend to behave in this way, as their characteristic often has its origin at absolute zero (-273 degrees Centigrade). The sensor may have offset and negative sensitivity, such as the silicon diode temperature characteristic ( y = -m4x + c2). In this case, an inverting amplifier with offset is needed.
Linearity. The ideal characteristic is a perfect straight line, so that the output is exactly proportional to the input. This linearity then has to be maintained through the signal conditioning and conversion processes.
Metal temperature sensors tend to deviate from
linearity at higher temperatures, as their melting point is approached,
which limits the useful range.
The deviation from linearity is usually expressed as a maximum percentage error over the specified range, but care must be taken to establish whether this is a constant over the range, or a proportion of the output level. These two cases are illustrated by the dotted lines in Figure 10.2, above, indicating the possible error due to non-linearity and other factors.
Reference Level. If the sensitivity is specified, we still need to know a pair of reference values to place the characteristic. In a temperature sensing resistor (TSR), this may be given as the reference resistance at 25 degrees Centigrade (e.g. 1 kohm).
The sensitivity may then be quoted as the resistance ratio " the proportional change over 100 degree Centigrade. For a TSR, this is typically 1.37. This means that at 125 degree Centigrade, the resistance of the 1 kohm sensor will be 1.37 kohm.
Transfer Function. Linear sensors are easier to interface for absolute measurement purposes, but some that are non-linear may have other advantages. The thermistor, for example, has a negative exponential characteristic, but it has high sensitivity, so is often used to detect whether a temperature is outside an acceptable range. If the sensor is to be used for measurement, the transfer function must be known precisely in order to design the interface to produce the correct output.
Error. Many factors may contribute to sensor error: limitations in linearity, accuracy, resolution, stability and so on. Accuracy is evaluated by comparison with a standard.
A temperature of 25 degrees Centigrade is only meaningful if Celsius is an agreed scale, in this case based on the freezing and boiling points of water. Resolution is the degree of precision in the measurement: 25.00 degrees Centigrade(+/-0.005) is a more accurate measurement that 25 degrees Centigrade (+/-0.5).
However, this precision must be justified by the overall precision of the measurement system. Poor stability may appear as drift, a change in the sensor output over time. This may be caused by short-term heating effects when the circuit is first switched on, or the sensor performance may deteriorate over the long term, and the measurement become inaccurate.
Recalibration of accurate measurement systems is often required at specified intervals, by comparing the output with one that is known to be correct. Interdependence in the sensor may also be significant; for example, the output of a humidity sensor may change with temperature, so this incidental variable must be controlled so that the required output is not affected.
Next, in Part 2: A survey of sensor types.
Used with the permission of the publisher, Newnes/Elsevier, this series of three articles is based on copyrighted material from "Interfacing PIC Microcontrollers: Embedded Design by Interactive Simulation," by Martin Bates. The book can be purchased on line.Martin Bates is a lecturer in technology at the Hastings College of Arts and Technology, United Kingdom