mrburnette
Senior Member
Got an extra input pin available on that PIC? Need to do remote correction or setup away from your PC? Here is an idea that will enable you to program on your bench and then do final set-up elsewhere.
Consider, the following code for a PICAXE 08M2:
What we are doing in the above is immediately before the MAIN: program routine starts, the code looks to see if physical pin #4 is grounded... this could be a jumper or a switch, what ever suits. If C.3 is "high" or "open" nothing happens and the program continues running with the variable "SetPoint" equal to the previously stored EEPROM value.
Now let's look at the FineTune: routine that runs if physical pin #4 has been grounded:
The bench parameter for SetPoint worked out to be 5447 which is the value that was written into the EEPROM when the program was loaded into the PICAXE. Subroutines MeasTEmp:, CalcTemp:, and UpdateLCD_T: are all routines in the base program. Since our initial test was performed after all of the program variables were initialized, the MAIN: program is simply a collection of GoSub's and Return's. When Physical Pin #4 goes "high", the program restarts normally but with the new value of SetPoint and that value will be utilized until another calibration period.
The Write 1, WORD SetPoint and the immediate Read1, WORD SetPoint are redundant but just gives me a warm and fuzzy feeling.
This routine is very useful if you must replace a part, say a thermistor, in the field and do not have all of your programming environment with you. It may also be useful if you purchase parts from different vendors that are intended to be identical.
The entire digital thermometer (YADTP - Yet Another Digital Thermometer Project) is on Instructables if you wish to see the full code: http://www.instructables.com/id/PICAXE-Pitcher-Perfect-Thermometer/
- Ray
Consider, the following code for a PICAXE 08M2:
Code:
' Bytes 1 & 2 in EEPROM hold SetPoint factor (little endian)
Read 1, WORD SetPoint
'Enable C.3 pullup
Pullup %001000
Pause 500
IF PINC.3 = 0 Then FineTune
'
Now let's look at the FineTune: routine that runs if physical pin #4 has been grounded:
Code:
FineTune:
' The wiper of a 10K pot is connected to C.2 and the other ends are +5 & GND
' The wiper is adjusted until the correct temperature is displayed and the jumper
' GNDing PINC.3 is removed to lock-in and write the correction factor to EEPROM
'
serout MONITOR,BAUD,(">> Tune MODE << ")
serout MONITOR,BAUD,(#SetPoint)
ReadADC C.2, SetPoint
'
GoSub MeasTemp
GoSub CalcTemp
GoSub UpdateLCD_T
Pause 2000
IF PINC.3 = 0 Then FineTune
Write 1, WORD SetPoint ' Little endian
Read 1, WORD SetPoint
GoTo MAIN
The Write 1, WORD SetPoint and the immediate Read1, WORD SetPoint are redundant but just gives me a warm and fuzzy feeling.
This routine is very useful if you must replace a part, say a thermistor, in the field and do not have all of your programming environment with you. It may also be useful if you purchase parts from different vendors that are intended to be identical.
The entire digital thermometer (YADTP - Yet Another Digital Thermometer Project) is on Instructables if you wish to see the full code: http://www.instructables.com/id/PICAXE-Pitcher-Perfect-Thermometer/
- Ray
Last edited: