Add field-adjustable coefficients to your project

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:
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
'
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:

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 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
 
Last edited:

geezer88

Senior Member
Nice idea. I built a fuel flow meter for an airplane that uses a similar technique for the calibration routine. Instead of a potentiometer, I use a rotary knob encoder with a push switch built in. With a long push on the switch, the device goes into cal mode. Then use the knob to adjust. One easy to use control for both flight and ground operations.
tom
 

mrburnette

Senior Member
...I use a rotary knob encoder with a push switch built in. With a long push on the switch, the device goes into cal mode. Then use the knob to adjust. ...
tom
Yes, a great idea. The choice of encoder or pot (or even touch up/down on PICAXEs so enabled) will likely be based upon what is desired to achieve... increment, decrement or in my case, the substitution of a pot that would represent the thermistor thus allowing calibration with a known temperature reading.
 

mrburnette

Senior Member
Hi,

There is a section here specifically for code snippets in the completed projects area.
I know. I was more interested in broadcasting an idea with an example rather than publishing a code snipplet. A fine-line, for certain. Moderators: feel free to move if wished.

In my way of working, I read the Main section often, but ignore some of the other sections until I need something and then will use "search" and depending upon how well I use the tool, I secure results or the empty-set. So, my seeing something like this in the Main Forum section would just plant a seed and I would move on until the regressed thought was needed. Others, however, may always read the 'What's New' section in entirety.

- Ray
 
Last edited:
Top