[an error occurred while processing this directive]
Temperature sensors
by Garnet Bailey gbailey@telusplanet.net
An integral part of home automation systems centers around temperature sensing. Whether measuring outside temperatures, inside air temperatures, appliance temperatures or any other temperature related item, it is necessary to convert these real world analog parameters into a digital form the software can operate on. Once the home automation system is equipped with an analog to digital converter of some type, sensing devices are required to translate the temperatures.
While there are many devices on the market for accomplishing this, two
semiconductor products which are readily available are commonly utilized. These two
devices, while appearing physically similar, are actually quite different. One device, the
LM334 is a current source that possesses a linear dependence on temperature in it's
operating characteristics. This dependence is calibrated (and is directly related) to
temperature, making it simple to perform a conversion of the digital information to
useable temperature information.The second device, the LM335 is designed as a temperature
sensor with a similar dependence on temperature.
Either device is capable of yielding temperature measurements in either the Fahrenheit or Celsius measurement system by means of a conversion formula. This means that the selection of which device to use is more an issue of availability and accuracy than which measurement units are desired. Each device is available in a myriad of operating temperature extremes and accuracy tolerances.
Connections
for the two devices are subtly different since the devices are of a fundamentally
different design. The LM334, as mentioned, is a current source. As such the current level
required in the device must be "programmed" and a load impedance must be
supplied to develop an output voltage which can be measured. This is accomplished as shown
in the LM334 figure.
The
LM335 on the other hand functions as a zener diode and must be reverse biased in order to
generate a temperature dependent output voltage. These require no load impedance, but do
require a current limiting source impedance to place the device in the proper operating
mode. This is accomplished as shown in the LM335 figure. Note that the third lead of the
LM334 is not used. It can be used to fine tune the output voltage with respect to
temperature, but a similar effect can be made with a simple offset in software as will be
seen. In highly noisy environments, it may be necessary to filter the analog output of the
device. This can be done by adding a .01 micro-farad capacitor from the A/D input to
ground.
In both cases, the resulting output voltage can be directly fed to the analog to digital converter for measurement. Also, the power supply voltage used to supply the devices must be equal to or less than the maximum allowable input voltage for the analog to digital measurement system to avoid damage. Usually this supply voltage is 5 volts and the preceding diagrams assume this voltage. For other voltages, the biasing resistors must be adjusted to ensure the devices are functioning in the proper operating range. It is useful to note here that the operating currents used for the devices should be kept at the lower end of the allowable limits to reduce any possibility of self heating. This self heating effect will degrade the accuracy of any measurements.
The analog to digital conversion which is performed on the input voltage will yield a digital number which depends on two variables. First, the size (number of bits) of the converter will dictate how large the resulting digital number will be. Typical converters can be 8 bits, 10 bits or 12 bits, and will yield maximum "counts" of 255, 1023 or 4095 respectively. This means that for an input voltage of 0 volts, any of the converters will yield a "count" of 0. But for an input voltage equal to the maximum allowable for the converter, the values of 255, 1023 or 4095 will be returned. Any voltage in between these limits will be represented by the converter as a fraction of the maximum number in the same proportion as the input voltage is to it's maximum. So for an input voltage of 20% of maximum, the "count" returned will be 20% of the maximum count.
The maximum allowable count and maximum allowable voltage are very important parameters in the use of the analog to digital converters. The maximum allowable count can be calculated easily from the number of bits available for the unit being used by using the formula:
and the total number of counts or steps available is:
since the value of 0 is a
valid count or step.
The maximum input voltage range must be taken from the manufacturers specifications.
It is worth noting here that Applied Digital's later model Redac units were changed from a 5 volt maximum converter to a 4.096V converter. This means that a formula derived for use with an earlier unit will be incorrect if used on a later model. This change though, does simplify the temperature calculation task as will be seen.
The converter allows us to translate the analog voltages into meaningful digital information. But in order for the digital information to be truly meaningful for temperatures, we must also understand the relationship between temperature and input voltage. For this, we must look at the devices themselves. When configured and biased properly, both devices have an output voltage which is directly proportional to absolute temperature. This relationship is 10mv per degree Kelvin, meaning that at a temperature of absolute 0, the output voltage will be 0, at a temperature of absolute 0 plus 1 degree ( which is 1 degree Kelvin), the output voltage will be 10mv (.010 volts), etc.
Since this relationship is a linear one, we can easily use it to calculate any given output temperature. Taking the voltage and dividing it by .010 will give us the temperature. But not many of us are used to reading temperature in degrees Kelvin. So some further mathematics are required to turn that number into something more useful.
To turn the Kelvin reading into Celsius is simply a matter of subtracting 273 from the above calculation, since 273 degrees Kelvin is the freezing point of water, or 0 degrees Celsius. So, if the input voltage is 2.73 volts, the temperature of the sensor is 0 degrees Celsius. For output in Celsius, that is all there is to it. But for readings in Fahrenheit, further math is needed. To convert Celsius into Fahrenheit, we must take the Celsius reading, multiply it by 9/5 and then add 32.0.
For example, take a voltage reading of 3.930 volts. This voltage represents:
degrees
Kelvin.
Now we convert to Celsius with:
degrees
Celsius.
Now converting to Fahrenheit:
degrees
Fahrenheit.
So taking all of the previous information into account, the process of measuring and converting the voltage into a useable temperature becomes somewhat arduous, especially for multiple sensors. Let us recap the sequence:
This process can be simplified once the maximum reading and maximum voltage constants are known. This is desirable, since rounding errors in the calculations can contribute significant errors, especially when floating point calculations are limited. For example, the - 273.0 calculation can be eliminated by subtracting the equivalent converter "count" immediately on reading the converter (2236 for a 12 bit, 5.0 volt converter). This reduces the magnitude of the numbers being operated on and helps reduce round off errors.
The calculation then, for a 12 bit converter and a 5 volt maximum input becomes:
C = (reading - 2236) x (500) / 4096
It should also be noted here that to compensate for any offset calibration errors the device exhibits, one can merely adjust the constant that is subtracted from the input reading (2236 in this example).
The difficulty with this formula is that for temperatures over 16 degrees Celsius, ECS will not calculate the result properly using normal multiply and divide statements. This is caused by the fact that the ECS items are 16 bit numbers and as such cannot exceed 65,535. One possible solution is to use the A*B/C operation, which uses higher precision math routines. While this is solves the overflow problem, it is slower, consuming more time and resources. Another solution is to simplify the formula with 5 / 41 instead of 500 / 4096.
The only remaining problem is that ECS cannot directly handle negative numbers. This makes it difficult to display temperatures below 0 degrees in either measurement system. To solve this, one can maintain a separate item for a positive / negative indicator and adjust the above formulas to ensure negative numbers do not occur. There is, however, an alternative method which can be used in ECS for versions later than 3.3. This method utilizes custom item type definitions to display negative and positive numbers. Either method adds one more complexity to the above calculations by requiring that some offset be removed to maintain positive numbers without overflowing the 35,535 limit.
A relatively new feature of ECS is the ability to define custom item types. This ability allows us to define an item and assign any state name we wish to any of the state values for the item. Thus, we can assign any string of text to a given state value in any order we wish, and furthermore, use (or not use) any of the states we desire. So we could, for example, create a custom item of the type "Temperature" and arbitrarily give the state 45 a name of "0'C". We would then define the state 44 as "-1'C" and the state 46 as "+1'C". And then the state 43 as "-2'C" and the state 47 as "+2'C". And so on until we get to some reasonable range of values we will not exceed, like state 0 as "-45'C" and state 90 as "+45'C". Now when we display the item of the type "Temperature" on the Group screen we see the state name including a "+" or "-" symbol, the temperature reading and the units designator "'C". The catch however, is that 0 degrees is no longer a state of 0. It is instead a state of 45. This is easily accommodated in the previous formulas by adding 45 to the result, but one must be careful in any subsequent calculations involving temperature to account for the offset.
Taking all of the preceding into account, the following example illustrates temperature measurement and handling using a custom item type to handle positive and negative temperatures. Two separate temperatures are measured here, one for "Main Floor" which uses a late model Redac with a 12 bit converter and 4.096 volt maximum input. This first temperature also demonstrates the use of an averaging technique to counter act the effect of any noise present on the converter input. Note that the reading is divided by 10. This is a direct result of the 4.096 volt maximum range of the Redac.
The second temperature for "Deep freezer" uses an older model Redac with a 12 bit converter and 5.00 volt maximum input. No averaging is done on this measurement. Also note the use of Multiply 9, Divide 73 which is a closer approximation of 500 / 4096 than is 5/41.
In both examples the constant being subtracted from the actual sensor reading has been adjusted to calibrate the readings against a known thermometer.
Temperature reading and calculation example event.
| Ln# | Cnd/Act | Item/Comment | Operator | State/Item |
| 1 | . | ** Main Floor temperature (averaged) ** | . | |
| 2 | Do | Num_X variable | Set | Temp sensor-MainFlr |
| 3 | Do | Num_X variable | Subtract | 2280 |
| 4 | Do | Num_X variable | Divide | 10 |
| 5 | Do | Num_temp mnflr avg | Set | Num_X variable |
| 6 | Do | Temp_Main Floor | Set | Num_temp mnflr avg |
| 7 | . | ** Deep freezer temperature ** | . | |
| 8 | Do | Num_X variable | Set | Temp sensor-Freezer |
| 9 | Do | Num_X variable | Subtract | 1849 |
| 10 | Do | Num_X variable | Multiply | 9 |
| 11 | Do | Num_X variable | Divide | 73 |
| 12 | Do | Temp_Freezer | Set | Num_X variable |
Related item definitions.
| Item | Type | Acc | . |
| Temp sensor-MainFlr | Analog-Input-C | User/Maint | . |
| Initial State | Backup | Station # | Input # |
| 2400 | No | 1 | 4 |
| Item | Type | Acc | . |
| Num_X variable | Number | Owner/Maint | . |
| Initial State | Backup | . | . |
| 0 | No | . | . |
| Item | Type | Acc | . |
| Num_temp mnflr avg | Average | Owner/Maint | . |
| Initial State | Backup | Count | . |
| 45 | No | 100 | . |
| Item | Type | Acc | . |
| Temp_Main Floor | Temperature | User/Maint | . |
| Initial State | Backup | . | . |
| (None) | No | . | . |
| Item | Type | Acc | . |
| Temp sensor-Freezer | Analog-Input-C | User/Maint | . |
| Initial State | Backup | Station # | Input # |
| 2073 | No | 0 | 6 |
| Item | Type | Acc | . |
| Temp_Freezer | Temperature | User/Maint | . |
| Initial State | Backup | . | . |
| -20 'C | No | . | . |
Custom item definition from the ECS file ITPCST.DEF
| |TYPE: Temperature | (cont'd from previous column) | (cont'd from previous column) |
| | -45 'C 0 | | -14 'C 31 | | +17 'C 62 |
| | -44 'C 1 | | -13 'C 32 | | +18 'C 63 |
| | -43 'C 2 | | -12 'C 33 | | +19 'C 64 |
| | -42 'C 3 | | -11 'C 34 | | +20 'C 65 |
| | -41 'C 4 | | -10 'C 35 | | +21 'C 66 |
| | -40 'C 5 | | - 9 'C 36 | | +22 'C 67 |
| | -39 'C 6 | | - 8 'C 37 | | +23 'C 68 |
| | -38 'C 7 | | - 7 'C 38 | | +24 'C 69 |
| | -37 'C 8 | | - 6 'C 39 | | +25 'C 70 |
| | -36 'C 9 | | - 5 'C 40 | | +26 'C 71 |
| | -35 'C 10 | | - 4 'C 41 | | +27 'C 72 |
| | -34 'C 11 | | - 3 'C 42 | | +28 'C 73 |
| | -33 'C 12 | | - 2 'C 43 | | +29 'C 74 |
| | -32 'C 13 | | - 1 'C 44 | | +30 'C 75 |
| | -31 'C 14 | | 0 'C 45 | | +31 'C 76 |
| | -30 'C 15 | | + 1 'C 46 | | +32 'C 77 |
| | -29 'C 16 | | + 2 'C 47 | | +33 'C 78 |
| | -28 'C 17 | | + 3 'C 48 | | +34 'C 79 |
| | -27 'C 18 | | + 4 'C 49 | | +35 'C 80 |
| | -26 'C 19 | | + 5 'C 50 | | +36 'C 81 |
| | -25 'C 20 | | + 6 'C 51 | | +37 'C 82 |
| | -24 'C 21 | | + 7 'C 52 | | +38 'C 83 |
| | -23 'C 22 | | + 8 'C 53 | | +39 'C 84 |
| | -22 'C 23 | | + 9 'C 54 | | +40 'C 85 |
| | -21 'C 24 | | +10 'C 55 | | +41 'C 86 |
| | -20 'C 25 | | +11 'C 56 | | +42 'C 87 |
| | -19 'C 26 | | +12 'C 57 | | +43 'C 88 |
| | -18 'C 27 | | +13 'C 58 | | +44 'C 89 |
| | -17 'C 28 | | +14 'C 59 | | +45 'C 90 |
| | -16 'C 29 | | +15 'C 60 | | Disabled 100 |
| | -15 'C 30 | | +16 'C 61 | |
| (continued next column) | (continued next column) |
Subscribe | Submit Products | Submit Company | Submit News | Advertise
Articles | News | Products | Industry | Resources
Other LJB eMagazines
Robotics Tomorrow ------ Alternative Energy Mag
© 1996 - 2011, Home Toys Inc. - All Rights Reserved
Powered by LJB Management Inc.