This screen shot shows an LM 34 temperature sensor measuring the temperature of a
heater cycling between 100 and 200 degrees being controlled on P8 (blue digital
line). The PBASIC2 source code is below. Note the correlation
between the configurations in the source code and controls available in the
plot. The plot is fully controllable from the stamp!
'Configure Plot
Pause 500
'Allow buffer to clear
DEBUG "!RSET",CR
'Reset plot to clear data
DEBUG "!TITL HEATER CONTROL SAMPLE",CR 'Caption form
DEBUG "!PNTS 2000",CR
'2000 sample data points
DEBUG "!TMAX 300",CR
'Max 300 seconds
DEBUG "!SPAN 50,300",CR
'50-300 degrees
DEBUG "!AMUL .1",CR
'Multiply data by .1
DEBUG "!DELD",CR
'Delete Data File
DEBUG "!SAVD ON",CR
'Save Data
DEBUG "!TSMP ON",CR
'Time Stamp On
DEBUG "!CLMM",CR
'Clear Min/Max
DEBUG "!CLRM",CR
'Clear Messages
DEBUG "!PLOT ON",CR
'Start Plotting
DEBUG "!RSET",CR
'Reset plot to time 0
ADcs con 12
' A/D enable (low true)
ADdat con 14
' A/D data line
ADclk con 15
' A/D clock Line
adres var byte
' A/D Results
Temp var word
' Temperature
Loop:
Pause 200
'200msec pause
Gosub ReadAD
'Go read Temp
Temp = adres*500/25
'Scale for 0 - 5000 (0-500 degrees)
DEBUG DEC Temp,CR
'Send Temp to plot
DEBUG ibin Out8,CR
'Send Bit 8 to Plot
IF (Temp > 2000) and (Out8 = 1) Then HeaterOff
'> 200F? De-energize
If (Temp < 1000) and (Out8 = 0) Then HeaterOn
'< 100F? Energize
Goto Loop
HeaterOn:
DEBUG "!USRS Heater ON!",CR
'Status Message
DEBUG "Heater turned on",CR
'Log Message
HIGH 8 'Energize
Goto Loop
HeaterOff:
DEBUG "!USRS HEATER OFF!",CR
'Status message
DEBUG "Heater turned off",CR
'Log Message
LOW 8
'De-energize
Goto Loop
ReadAD:
'Read A/D
low 10
LOW ADcs
' Enable ADC
SHIFTIN ADdat,ADclk,msbpost,[ADres\9]
' Shift in the data
HIGH ADcs
' Disable ADC
Return