Example: Temperature readout with limits with OBLCD
In this example we will do a complete sample application, a fermentation vessel temperature monitor with high and low limits.
The temperature sensor is a 10K thermistor probe connected to the MMi99 analog input c configured for temperature measurement (thermistor temperature measurement with SPLat is documented elsewhere). The thermistor drive voltage is generated by analog output i.
Using an Excel spreadsheet we have determined the following parameters:
Operating temperature range: 25°C – 45°C
Measurement resolution: approx 0.2°C
Optimum analog out count to thermistor driver voltage generator: 125 (=9.80V)
Equation for thermistor linearization:
T = -1.617807E-06x^3 + 1.275737E-03x^2 – 5.141065E-01x + 9.905215E+01
where x = raw analog input reading, T = temperature in °C and the ^ operator means “raised to the power of”
The optimum fermentation temperature is 35°C. Above 37°C we must display an over temperature warning and below 32°C we must display an under temperature warning. We will do an update every 100mS, using timer 4.
Display layout plan:
0123456789012345
Vat temp: 33.3°C
Normal
Under temp!
OVER TEMP!!
Our program must:
- Initialize the thermistor circuit by setting analog output i
- Initialize the LCD
- Wait for a 100mS time tick
- Take an analog reading and Convert to °C
- Display temperature
- Evaluate temperature and show status
- Go to 3
Here’s the program
;Temperature monitor program with hi/lo limits
Temperature mEQU 0 ;4 bytes for temperature value
LoadX 125
AnOutI ;Init thermistor circuit
OBLCD_Type 2 ;Init LCD
; 0123456789012345
OBLCD_Text "Temperature" ;"splash" screen
OBLCD_SetCur 1,0
OBLCD_Text "Monitor V1.0"
Pause 500 ;Delay 5s to let thermistor drive settle
MainLoop
Test 4
GoIfT MainLoop ;Wait for time tick
SetTimer 4,10 ;Restart the timer
GoSub ReadTemp ;Get and update temperature in memory
GoSub DispTemp ;Display temperature
GoSub Evaluate ;Check limits and display
GoTo MainLoop
;Subroutine to evaluate the temperature reading
;and display a message. Because the fCompareR instruction
;can yield a Result code in the R-register for indeterminate
;results, I've included a corresponding Branch address
;"OhDear". It does nothing.
Evaluate
OBLCD_SetCur 1,0 ;Get that done first
fRecallW Temperature
fLoadQ 37 ;Upper limit
fCompareR
BranchR
Target TempOK ; W=Q
Target TempHot ; W>Q
Target TestCold ; W<Q
Target OhDear ; ????
TestCold
fLoadQ 32 ;Low limit
fCompareR
BranchR
Target TempOK ; W=Q
Target TempOK ; W>Q
Target TempCold ; W<Q
Target OhDear ; ????
TempCold
;0123456789012345
OBLCD_Text " Under temp! "
Return
TempHot
;0123456789012345
OBLCD_Text " OVER TEMP!! "
Return
TempOK
;0123456789012345
OBLCD_Text " Normal "
OhDear
Return
;Subroutine to display temperature
DispTemp
OBLCD_SetCur 0,0
OBLCD_Text "Vat temp: "
fRecallW Temperature
OBLCD_fDispW 4,1
OBLCD_Text 223,"C" ;223 = degree sign
Return
;Subroutine to take one thermistor reading and convert to °C
;in floating point memory location Temperature.
ReadTemp
AnInC ;Read thermistor
Float
fStore Temperature
fLoadQ -1.617807E-06 ;<< X^3 coefficient
fMul
fLoadQ +1.275737E-03 ;<< X^2 coefficient
fAdd
fRecallQ Temperature
fMul
fLoadQ -5.141065E-01 ;<< X^1 coefficient
fAdd
fRecallQ Temperature
fMul
fLoadQ +9.905215E+01 ;<< X^0 coefficient
fAdd
fStore Temperature
Return