Issue
RTD-DI-16 temperature input range is -50C to 150C, some applications require a wider range.
Product Line
EcoStruxure Building Operation.
Environment
- Building Operation Automation Server
- Building Operation Automation Server Premium
- Building Operation I/O Module 16 Ch RTD
Cause
Script program sample and guidelines needed for implementing resistance to temperature table lookup and further temperature calculation using linear interpolation.
Resolution
We will present two solutions, the first solution is very simple to implement but at the expense of accuracy.
The second solution retains the 0.3C accuracy of the native RTD inputs.
For simplicity, both solutions implement a range of -50C to 250C using the RTD Resistance electrical type to convert resistance to temperature, the program can be easily modified to implement a wider range.
SOLUTION #1
This solution simply uses the conversion settings of the RTD-Resistive input to convert from Ohms to Degrees C.
Because the change in resistance is not exactly linear across the temperature range, the accuracy of the converted value varies across the range as much as +/- 4 degrees C
STEPS TO IMPLEMENT SOLUTION #1
- Under the RTD-DI-16 IO module, create RTD-2W-Resistive input.
- Change the units to degrees Celsius.
- Select the sensor class, in this example, we are using the pt100 sensor.
- Look up the resistance value in the table for -50C and 250C and set the upper/low-level reliability. (see attached R versus T table from Omega)
- Use values from step #4 to set the input's conversion electrical scale.
- Set the engineering scale top/bottom to 250 and -50 respectively.
STEPS TO IMPLEMENT SOLUTION #2
- Under the RTD-DI-16 IO module, create RTD-2W-Resistive input.
- Look up the resistance value in the table for -50C and 250C and set the upper/low-level reliability. (see attached R versus T table from Omega)
- In the Automation Server, create an Analog Value object. This object will receive the calculated temperature value from the Script program. Set the AV units to degrees C
- In the Automation Server create a Script program, this program will read the resistance from the input object, look up the corresponding temperature range in the table, and then using linear interpolation calculates the temperature to an accuracy of +/- 0.3C. To ensure the program when runs when necessary, configure the program's flow type for fall thru and trigger the program off of the RTD-2W-Resistive input.
- Bind the RTD-2W-Resistive input and the Analog Value in the Script program as Numeric Input and Numeric Output respectively.
Here is the code for the script program
'This program uses RTD temperature vs. resistance table combined with linear interpolation
'to implement RTD temperature input over the range -50C to 250C
'Program Flow Type is FallThru
'Program is triggered by the RTD resistance input.
'This program is provided as a sample for illustration purposes, it is not intended to be a complete solution
'SE PSS v1.0 101010111110
Numeric Input RTD_Raw 'the RTD Resistance input where the RTD sensor is connected
Numeric Output RTD_Temp 'Analog Value that receives the calculated temperature
Numeric RTD_R[31]'Resistance to
Numeric RTD_T[31]'temperature table for 100 Ohms based sensor
'NOTE: Since the resistance value changes in a nearly linear way over any 10 degree section
'of the table, we can use 10 degree increments of resistance/temperature values and apply linear
'interpolation to calculate readings in between those values, this method greatly reduces the size
'of the table in the program while maintaining very good accuracy.
'Accuracy is +/-0.3C for 100 Ohms based sensors and can be improved to +/-0.03C if 1000 Ohms based sensor used.
Numeric n, sLow, sHigh,sMid
Line INIT
'Due to limitations in Script we will use 2 arrays to implement the resistance to temperature table.
RTD_R[1]=80.31
RTD_R[2]=84.27
RTD_R[3]=88.22
RTD_R[4]=92.16
RTD_R[5]=96.09
RTD_R[6]=100
RTD_R[7]=103.9
RTD_R[8]=107.79
RTD_R[9]=111.67
RTD_R[10]=115.54
RTD_R[11]=119.4
RTD_R[12]=123.24
RTD_R[13]=127.08
RTD_R[14]=130.9
RTD_R[15]=134.71
RTD_R[16]=138.51
RTD_R[17]=142.29
RTD_R[18]=146.07
RTD_R[19]=149.83
RTD_R[20]=153.58
RTD_R[21]=157.33
RTD_R[22]=161.05
RTD_R[23]=164.77
RTD_R[24]=168.48
RTD_R[25]=172.17
RTD_R[26]=175.86
RTD_R[27]=179.53
RTD_R[28]=183.19
RTD_R[29]=186.84
RTD_R[30]=190.47
RTD_R[31]=194.1
'The temperature array could be easily omitted since once we have the first array index (n) we could easily calculate
'the corresponding temperature value, I have kept it for the purpose of simplicity.
RTD_T[1]=-50
RTD_T[2]=-40
RTD_T[3]=-30
RTD_T[4]=-20
RTD_T[5]=-10
RTD_T[6]=0
RTD_T[7]=10
RTD_T[8]=20
RTD_T[9]=30
RTD_T[10]=40
RTD_T[11]=50
RTD_T[12]=60
RTD_T[13]=70
RTD_T[14]=80
RTD_T[15]=90
RTD_T[16]=100
RTD_T[17]=110
RTD_T[18]=120
RTD_T[19]=130
RTD_T[20]=140
RTD_T[21]=150
RTD_T[22]=160
RTD_T[23]=170
RTD_T[24]=180
RTD_T[25]=190
RTD_T[26]=200
RTD_T[27]=210
RTD_T[28]=220
RTD_T[29]=230
RTD_T[30]=240
RTD_T[31]=250
n=0
sLow = 1
sHigh = MaxItem(RTD_R) 'Initialize to the size of the table
Line calculateTemp
'Bottom of range
If RTD_Raw <= RTD_R[1] then
RTD_Temp = -50.0
Stop
Endif
'Top of range
If RTD_Raw >= RTD_R[sHigh] then
RTD_Temp = 250.0
Stop
Endif
'Find the resistance input reading in the table using a binary search
'NOTE:
'In our case, what we are looking for is the lower value of the resistance range in the table that
'the input reading falls under.
'EXAMPLE if input value is 160.9 Ohms then it is in the range of RTD_R[21]=157.33 AND RTD_R[22]=161.05
'so the binary search will give us 21
While(1)
If sHigh < sLow then
n=sHigh 'the input value is not in the table but we now have RTD_R[n] of the range it is within
break
Endif
'calculate the mid point
sMid = Round(sLow + (sHigh - sLow) / 2)
if RTD_R[sMid] < RTD_Raw then sLow = sMid + 1 'if read value is larger then look again in upper half
if RTD_R[sMid] > RTD_Raw then sHigh = sMid - 1 'if read value is smaller then look again in lower half
if RTD_R[sMid] = RTD_Raw then
n = sMid 'we've located the input value in the table, this is actually the exception
Break
endIf
EndWhile
'Now, use linear interpolation to calculate the temperature
If n > 0 Then
RTD_Temp = (RTD_T[n+1]-RTD_T[n])*(RTD_Raw-RTD_R[n])/(RTD_R[n+1]-RTD_R[n])+RTD_T[n]
Endif
Stop
Line E
stop
NOTE:
The accuracy of the temperature reading can be further improved by the use of 1000 Ohms based sensors as well as the use of 3 wire sensors so that the resistance of the leading wires can be taken into account.
If 1000 Ohms based sensors are used then the resistance values in the table implemented in the Script program must be multiplied by 10