;Linearisation Algorithm for Thermistor sensors. ;Language: Venom-SC ;Author: Karl Lam 15/02/2007 ;Copyright Micro-Robotics Ltd 2007. ; Checked for Venom 2 compatibility (Anahata, 2010-07-29) ;Find the temperature of a Thermistor Sensor that is used in a simple ;potential divider circuit, with a bias resistor in the top leg and ;the sensor in the bottom leg. ;The divider is energised by the reference voltage of the ADC, which can ;simply be the supply voltage since the reading is ratiometric. ;The divided voltage is fed directly to the ADC input. ;There may be lead resistance in the thermistor leads that needs taking ;into account, but 10 Ohms of lead res will only make ~20mK temp inacuracy at 25C. ;Linearisation is done using Log formula, with constants used here that meet ; data for a Betatherm 10K Ohm nom. thermistor. ;The bias resistor is 10K 0.1%, and the ADC is 12-bit. ;Contact M-R for constants for other devices. #Define BIAS_RES 10000.0 #Define LA_VALUE (-3.7183);Thermistor constant #Define B_VALUE 3854.67 ;Thermistor constant #Define ZERO_C 273.15 ;0C in Kelvin #Define ADC_MAX 4096 ;ADC max reading - 12-bit here. To temperature(adc) Local res If adc = 0 adc := 1 ;prevent math error. res := BIAS_RES * (ADC_MAX / (ADC_MAX - adc) - 1.0) ;Find the resistance of the sensor. Return B_VALUE / (Log (res) - LA_VALUE) - ZERO_C ;Find Degrees C from resistance. End