A wide variety of sensors are used in digital controlsystems and interfacing them requires a good understanding of linearamplifier design and signal conditioning techniques. Connection to anMCU is simplified if the sensor itself contains built-in signalconditioning, such that the output is linear, reasonably large,conveniently scaled and pre-calibrated.
The LM35temperature sensoris a good example, givingan output of 10 mV/degree Centigrade, starting at 0 degrees Centigrade = 0 mV, but it needs anADC input. Increasingly, sensors are incorporating all the necessarysignal processing and serial data outputs, so that interface design issimplified or eliminated. For example, Microchipsupplies a range oftemperature sensors with I2Coutput.
The sensor is an essential device that responds to some environmentalvariable and converts it into electrical output. This signal may thenneed to be conditioned (filtered, amplified, attenuated, converted) toallow the MCU to receive the input in a usable form. Digital sensorsmay provide a direct input at TTL levels, while some analogue inputsmight need a high-performance amplifier or complex digital processing.
The simplest form of digital sensor is a switch. A manually operatedpush button or toggle switch may only need a pull-up resistor, orpossibly debouncing via a parallel capacitor, hardware latch orsoftware process.
A micro-switchcanbe attached to a mechanical systemso that it detects the position of, say, the guard on a machine tool.The machine controller can then be programmed not to start until theguard is closed. The micro-switch may often have an extended operatinglever to make it more sensitive.
One disadvantage of the switch or relay contact isthat physical wear causes unreliable operation. This problem can beovercome by using a switch which has no moving parts, or is speciallydesigned for reliability.
A reed switch isenclosed in avacuum andoperated by the proximity of a magnet to the sprung contacts, which aregold-plated to reduce corrosion effects. The vacuum prevents burning atthe contacts due to high-voltage discharge as they open or bounce withan inductive load.
Opto-electrical devices have no moving parts, and aretherefore inherently more reliable. An LED and phototransistor areconnected in separate circuits, with the transistor operating as alight-activated switch. The opto-isolator includes both in a singlepackage, providing electrical isolation between control and loadcircuits, which may operate at high voltage. The signal to noise ratiomay also be improved, and the digital signal thus cleaned up.
The same devices are used in an opto-detector wherethe light beam is interrupted by a moving object, grating or perforatedwheel; this arrangement can be used to monitor position, speed oracceleration. Light transmission or reflection may be used, dependingon measurement. The reflective type can be used as a simple proximitysensor, while position detection often uses a transmissive system.
The inkjet printer provides a good example of aposition system. A plastic strip with a fine grating is used to provideposition feedback for the print head. The simple periodic grating canbe made more precise by grading the light transmission sinusoidallyover a cycle, allowing calculation of fractions of a cycle(interpolation).
Axis position inmachine tools can be controlled downto about 1 micrometer by this means. If a pair of gratings is used,offset by90 degrees Centigrade, the direction of travel can be detected by the phaserelationship. To establish absolute position, a reference position isneeded from which relative motion can be calculated.
For example, a robot arm may need to be started froma known home position. Alternatively, a Gray code can beused on theoptodisk; each sector has a unique combination of light and dark bands,so that the absolute position of the stationary shaft can be detectedby a set of sensors, one for each band.
The pattern is a modified binary code which onlychanges 1 bit at a time, to prevent incorrect data being sampled on thesector boundaries as shown in Figure10.1 below.
|Figure10.1 Incremental encoder: (a) linear encoder; (b) sinusoidal output;(c) Gray code optodisk (10 bit)|
Some sensors have a built-in data processing so thatan MCU compatible signal is produced; for example, the measuredvariable may be converted into a periodic TTL signal.
This can be fed into a digital input, and thefrequency determined in software by using a timer/counter to measurethe number of pulses in unit time, or the period. Analogue to digitalconverter chips are available which convert the measured voltage intofrequency, or transmit the binary form of the measurement in a standardserial format, such as I2C.
Analoguesensors produce a variable output, which may be voltage, resistance orcurrent. In microcontroller systems, they are usually converted into avoltage in a range suitable for an input comparator (high/lowdetection) or analogue to digital conversion.
Suitable signal conditioning may be needed usingamplifiers, filters and so on, to produce a clean signal, controllingnoise, drift, interference and so on, with the required output range.
Sensors have certain characteristics which should be specified in thedata sheet: Sensitivity, Offset, Range, Linearity, Error, Accuracy,Resolution, Stability, Reference level, Transfer function andInterdependence. The meaning of some of these is illustrated in Figure10.2, below
|Figure10.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 itsinput; that is, it has high sensitivity. The output could be feddirectly into the analogue input of the MCU.
The line also goes through the origin, meaning nooffset adjustment is required – a linear pot would give this result. Ifthe sensor has low sensitivity ( y = m2x), an amplifier may be neededto 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 lowestoutput has a large positive constant added (y = m3x + c).
This has to be subtracted in the amplifier interfaceto bring the output back into the required range, where maximumresolution can be obtained. The same can be achieved in software, butthis is likely to result in a loss of resolution.
Temperature sensors tend to behave in this way, astheir characteristic often has its origin at absolute zero(-273 degrees Centigrade). The sensor may have offset and negative sensitivity, suchas the silicon diode temperature characteristic ( y = -m4x + c2). Inthis case, an inverting amplifier with offset is needed.
Linearity.The ideal characteristic is a perfect straight line, so that the outputis exactly proportional to the input. This linearity then has to bemaintained through the signal conditioning and conversion processes.
Metal temperature sensors tend to deviate fromlinearity at higher temperatures, as their melting point is approached,which limits the useful range.
The deviation from linearity is usually expressed asa maximum percentage error over the specified range, but care must betaken to establish whether this is a constant over the range, or aproportion of the output level. These two cases are illustrated by thedotted 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 toknow apair of reference values to place the characteristic. In a temperaturesensing resistor (TSR), this may be given as the reference resistanceat 25 degrees Centigrade (e.g. 1 kohm).
The sensitivity may then be quoted as theresistance 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 ofthe 1 kohm sensor will be 1.37 kohm.
Transfer Function. Linear sensors are easier to interface forabsolutemeasurement purposes, but some that are non-linear may have otheradvantages. The thermistor, for example, has a negative exponentialcharacteristic, but it has high sensitivity, so is often used to detectwhether a temperature is outside an acceptable range. If the sensor isto be used for measurement, the transfer function must be knownprecisely in order to design the interface to produce the correctoutput.
Error.Many factors may contribute to sensor error: limitations in linearity,accuracy, resolution, stability and so on. Accuracy is evaluated bycomparison with a standard.
A temperature of 25 degrees Centigrade is only meaningful ifCelsius is an agreed scale, in this case based on the freezing andboiling points of water. Resolution is the degree of precision in themeasurement: 25.00 degrees Centigrade(+/-0.005) is a more accurate measurement that25 degrees Centigrade (+/-0.5).
However, this precision must be justified by theoverall precision of the measurement system. Poor stability may appearas drift, a change in the sensor output over time. This may be causedby short-term heating effects when the circuit is first switched on, orthe sensor performance may deteriorate over the long term, and themeasurement become inaccurate.
Recalibration of accurate measurement systems isoften required at specified intervals, by comparing the output with onethat is known to be correct. Interdependence in the sensor may also besignificant; for example, the output of a humidity sensor may changewith temperature, so this incidental variable must be controlled sothat the required output is not affected.
Next, in Part 2: Asurvey of sensor types.
Usedwith the permission of the publisher, Newnes/Elsevier, this series ofthree articles is based on copyrighted material from “InterfacingPIC Microcontrollers: Embedded Design by Interactive Simulation,“by Martin Bates. The book can bepurchased on line.
Martin Bates is a lecturer intechnology at the Hastings College of Arts and Technology, UnitedKingdom