;Linearisation Algorithm for PT100 sensors.
;Language: Venom-SC
;Author: Karl Lam 14/02/2007
;Copyright Micro-Robotics Ltd 2007.

;This is a function that will 'calibrate' the non-linear PT100
;resistance/temperature curve. Different data tables, based on different
;national/international standards, can be built. Please contact us for
;details.


;Find temperature of PT100 Sensor given resistance value 'Res'.
;Uses Array below. No range checking done.
TO Temp(Res)
  LOCAL Ind,ResOver10
  LOCAL T1,T2
  ResOver10 := Res / 10.00;Useful intermediate result.
  Ind := ResOver10 AS INT ;Find an index into the array
  T1 := PT100_data.(Ind) ;Find the Temperature at the lower Res boundary
  T2 := PT100_data.(Ind+1);Find the Temperature at the upper Res boundary
  RETURN T1 + (T2 - T1) * (ResOver10 - Ind);Interpolate temperature.
END

;Linearisation data for PT100 sensor between -200C and +266C.
;Temperature vs. Resistance at 10 Ohm intervals, between '10' and 200 Ohms.
;Using linear interpolation, the maximum interpolation error is
; < +0.053C over the whole range
; < +0.031C above -60C.
;Contact M-R if you need data for more accuracy, or higher/ lower temperatures.
;Source Data: IEC751:
; Rt = R0[1+At+Bt^2+Ct^3(t-100)]
; A 3.9083E-03
; B -5.7750E-07
; C -4.1830E-12; [C is 0.000 for T >= 0.000 Deg C].
; R0 100.000 Ohms
; Not valid for temperatures below -200C.

Array PT100_data(1.0,21)
  -1000.00, ;0 ;Dummy value
  -219.537, ;10 ;This is below the specified range of PT100, included to extend to -200C.
  -196.574, ;20
  -173.158, ;30
  -149.335, ;40
  -125.144, ;50
  -100.631, ;60
  -75.827 , ;70
  -50.770 , ;80
  -25.488 , ;90
  0.0000 , ;100
  25.684 , ;110
  51.564 , ;120
  77.650 , ;130
  103.943 , ;140
  130.446 , ;150
  157.169 , ;160
  184.115 , ;170
  211.289 , ;180
  238.698 , ;190
  266.348 , ;200
END