Much of this work was done by Tenee Watkins as a part of her Senior Design Project.
' Program PLOT1.BAS ' ' Illustrates the use of the Selmaware Plotting Software ' ' Measures temperature each 1.0 sec and sends result to COM Port for plotting. ' ' Temperature is measured using an nominal 10K NTC thermistor in a voltage divider ' arrangement. ' ' +5 VDC ' | ' 10K ' |------------------- BX24 Term 13 ' | ' 10K NTC ' | ' GRD ' ' Sets up plotting software for new plot with a vertical span in the range of 60 to 100 ' and a maximum time of 10 minutes (600 secs). Shifts plot to the left by 25 percent when ' plot is at maximum. ' ' High and Low trip points of 75.0 and 73.0 are defined. (Note that these could be adjusted using ' potentiometers on the A/D inputs). Normally the "Heater" (Red LED) is off. When the temperature ' falls below the low trip point, the heater is turned on and when the temperature goes above the ' high trip point, the heater is turned off. ' ' Note that the Selaware software plots the temperature and high and low trip points and the state ' of the heater. ' ' ' Copyright, Tene Watkins, Peter Anderson, Baltimore, MD, Oct, '01 Const GreenLED as Byte = 26 Const RedLED as Byte = 25 Const A_THERMISTOR as Single = 0.000623 ' Thermistor two-point model used to calculate Temperature Const B_THERMISTOR as single = 0.000297 Sub Main() Dim TF as Single, THigh as Single, TLow as Single Dim NextTime as Single, CurrentTime as Single Dim HeaterOn as Byte Dim RollOverFlag as Boolean ' used for periodic timing Call Delay(0.2) Call PutPin(GreenLED, 1) ' Turn off Green LED. Green LED not used. ' Configure Selmaware Software Debug.Print "!NEWP" ' New Plot Debug.Print "!SPAN 60,100" ' Analog range 60-100 Debug.Print "!TMAX 600" ' 10 minute's worth of data Debug.Print "!PNTS 5000" Debug.Print "!FAMT 25" Debug.Print "!FLSH ON" Debug.Print "!SAMT 25" Debug.Print "!SHFT ON" Debug.Print "!PLOT ON" 'Enable plotting THigh = 75.0 TLow = 73.0 HeaterOn = 0 Call PutPin(RedLED, 1) ' Turn off Red LED Call PutTime(0, 0, 0.0) ' 0 hrs, 0 mins, 0.0 secs CurrentTime = Timer() Do TF = MeasTemp() If (TF > THigh) Then HeaterOn = 0 Call PutPin(RedLED, 1) ' Turn off Red LED ElseIf (TF < TLow) Then HeaterOn = 1 Call PutPin(RedLED, 0) ' Heater is Red LED End If ' TF, THigh and TLow Debug.Print CStr(CInt(TF)) ; "," ; CStr(CInt(THigh)); ","; CStr(CInt(TLow)) ' State of the heater Debug.Print "%"; CStr(HeaterOn) ' Now time for the remainder of one sec using the onboard timer NextTime = CurrentTime + 1.0 ' every 1 seconds If (NextTime > 86400.0) then ' there was a rollover from one day to the next NextTime = NextTime - 86400.0 RollOverFlag = TRUE Else RollOverFlag = FALSE End If If (RollOverFlag = FALSE) then Do CurrentTime = Timer() Loop Until (CurrentTime >= NextTime) Else ' there was a rollover Do CurrentTime = Timer() Loop Until (CurrentTime <= NextTime) ' wait for the timer to ' roll over Do ' and then count up to NextTime CurrentTime = Timer() Loop Until (CurrentTime >= NextTime) End if CurrentTime = NextTime Loop End Sub Function MeasTemp() as Single Dim ADVal as Integer Dim Rtherm as Single, TK as Single, TC as Single, TF as Single ADVal = GetADC(13) ' A/D conversion Rtherm = 10000.0/((1024.0/CSng(ADVal))-1.0) ' Calculate thermistor R TK = 1.0/(A_THERMISTOR + B_THERMISTOR *log(Rtherm)) ' T_Kelvin TC = TK-273.15 ' T_Celcius TF = (TC * 1.8) + 32.0 ' T_Fahr MeasTemp = TF End Function