Alternative to lookup table
Archiver
Posts: 46,084
Hi,
I'm develloping a fast and accurate thermometer with the BS2 to meaure the
temperature of (good) wine. The sensor is a miniture NTC as used in fever
thermometers.
The resistance and the slope of the nearly exponential curve of the sensor
are specified in in 5-degree intervals by the manufacturer. I.e. 100 kOhm
and 4.7 kOhm/degree at 20 degree C.
I develloped an aproximation by 4 straight lines over 5-degree intervals.
The intervals are: below 12.5C, between 12.5C and 17.5C, between 17.5C and
22.5C and above 22.5C. For a thermometer for wine this makes sense to me.
The result is a very fast responding (2 seconds for a full reading) and
fairly accurate (error ca. 0.2C absolute) measuring instrument.
If I had done this using LOOKUP, as I planned first, I would have ended up
with a table of about 200 elements for this acuracy and resolution. The
NO-GO for this table was when I realised that if small corrections would
have to be made in a later stage of calibrating the system I would have to
work over the entire table, or mess up my code.
The code and the formulas I used are listed below.
Next thing to do is write the code for a display and fix the decimal point
:-).
Klaus
'///////////////////////////////////////////////////////////////////////////
///
' Ts = Cx - RT/Cy Ts: Temperature of sensor * 10
' RT: output of RCTIME
' Cx = T_cal + R_cal/(dR/dT)_cal cal: 10,15,20,25 degree C
' Cy = K*(dR/dT)_cal (dR/dT): slope of curve
' K = 29,57 K: system constant for BS2 and cap = 0.47 uF
'{$STAMP BS2}
OUTPUT 15
Ts VAR WORD
RT VAR WORD
Main:
OUT15 = 1
HIGH 12
PAUSE 10
RCTIME 12, 1, RT
OUT15 = 0
Ts = 479 - (RT/107)
IF Ts>225 THEN Label1
Ts = 420 - (RT/139)
IF Ts>175 THEN Label1
Ts = 367 - (RT/177)
IF Ts>125 THEN Label1
Ts = 306 - (RT/231)
Label1:
DEBUG CLS, DEC Ts, " RT= ", DEC RT
PAUSE 440
GOTO Main
I'm develloping a fast and accurate thermometer with the BS2 to meaure the
temperature of (good) wine. The sensor is a miniture NTC as used in fever
thermometers.
The resistance and the slope of the nearly exponential curve of the sensor
are specified in in 5-degree intervals by the manufacturer. I.e. 100 kOhm
and 4.7 kOhm/degree at 20 degree C.
I develloped an aproximation by 4 straight lines over 5-degree intervals.
The intervals are: below 12.5C, between 12.5C and 17.5C, between 17.5C and
22.5C and above 22.5C. For a thermometer for wine this makes sense to me.
The result is a very fast responding (2 seconds for a full reading) and
fairly accurate (error ca. 0.2C absolute) measuring instrument.
If I had done this using LOOKUP, as I planned first, I would have ended up
with a table of about 200 elements for this acuracy and resolution. The
NO-GO for this table was when I realised that if small corrections would
have to be made in a later stage of calibrating the system I would have to
work over the entire table, or mess up my code.
The code and the formulas I used are listed below.
Next thing to do is write the code for a display and fix the decimal point
:-).
Klaus
'///////////////////////////////////////////////////////////////////////////
///
' Ts = Cx - RT/Cy Ts: Temperature of sensor * 10
' RT: output of RCTIME
' Cx = T_cal + R_cal/(dR/dT)_cal cal: 10,15,20,25 degree C
' Cy = K*(dR/dT)_cal (dR/dT): slope of curve
' K = 29,57 K: system constant for BS2 and cap = 0.47 uF
'{$STAMP BS2}
OUTPUT 15
Ts VAR WORD
RT VAR WORD
Main:
OUT15 = 1
HIGH 12
PAUSE 10
RCTIME 12, 1, RT
OUT15 = 0
Ts = 479 - (RT/107)
IF Ts>225 THEN Label1
Ts = 420 - (RT/139)
IF Ts>175 THEN Label1
Ts = 367 - (RT/177)
IF Ts>125 THEN Label1
Ts = 306 - (RT/231)
Label1:
DEBUG CLS, DEC Ts, " RT= ", DEC RT
PAUSE 440
GOTO Main