Picaxe keezer controller code help

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

jppostKW

Well-Known Member
Joined
Jan 27, 2009
Messages
1,802
Reaction score
12
Location
Englewood CO
I am building a temp controller for the new version of my keezer with a prelim thread here https://www.homebrewtalk.com/f51/keezer-build-prelim-156315/
I am planning on building a picaxe 08m based thermostat that will turn the comp on and off at a programed temp using a ssr and a Dallas 1wire dsb1280 i have been working on the code today. this is what i have so far it runs in the simulator but i dont know if i have any glaring problems or whether i can clean it up at all?

Code:
symbol counter = b1
    Symbol TempC_100 = W3
    Symbol DevNum = W6
    Symbol Temp_8 = B9

    Symbol HighTrip = 66	'(42.8F)	' 6 + 60 - adjust as necessary
    Symbol LowTrip = 64       '(39.2F)	' 4 + 60

	low 0		'set unused pin

	high 2	'(status LED on)
	pause 600
	low 2
  
Top:
	high 2			' read is in progress (power/activity light)
      ReadTemp 1, Temp_8		' read the high 8 bits 
	low 2
    
    Temp_8 = Temp_8 + 60	' to avoid negative numbers
    If Temp_8 >= HighTrip Then OperateRelay
	if Temp_8 < LowTrip then continue
	
continue:
    If Temp_8 < LowTrip Then ReleaseRelay
    ' else
    Goto SequenceDone

OperateRelay:
    High 4
    Goto SequenceDone

ReleaseRelay:
    Low 4
    Goto SequenceDone

SequenceDone:
    Pause 500	
    GoTo Top
 
thanks Yuri i took out a couple lines I really didnt need. Like to see the LED sequence of where in the temp range the keezer is sitting I kept the LED flash at start up to verify operation.
 
Here's my disclaimer - I don't have a PICAXE, I've never programmed one, I don't have a simulator, and I've never written in this particular version of BASIC. However, I think I have enough of a grasp of it in order to help. Reading the datasheet was at least slightly interesting. Anyway, try this out:

Code:
' constants
	symbol HIGHTRIP = 66	' (42.8F)	' 6 + 60 - adjust as necessary
	symbol LOWTRIP = 64 	' (39.2F)	' 4 + 60
	symbol LED = 2		' led pin
	symbol RELAY = 4	' relay pin
	symbol TEMP = 1		' DSXXXX sensor pin

' variables
	'symbol counter = b1	' unused
	'symbol TempC_100 = W3	' unused
	'symbol DevNum = W6	' unused
	symbol valTemp = B9	' variable for sensor output

' set up pins and flash the status LED once
setup:
	low 0		'set unused pin (Yuri's not sure why...)
	high LED	'status LED on
	pause 600
	low LED
	
' begin main subroutine 
main:
	high LED		' read is in progress (power/activity light)
	readtemp TEMP, valTemp	' read the high 8 bits 
	low LED

	' respond to the temperature
	valTemp = valTemp + 60	' avoid negative numbers
	
	if valTemp >= HIGHTRIP then
		gosub latch
	elseif valTemp < LOWTRIP then
		gosub release
	else	
		' indicate if above LOWTRIP but below HIGHTRIP
		gosub flash
	endif

	pause 500	
	goto main
end

' flash led
flash:
	for b0 = 1 to 2
		pause 200
		high LED
		pause 200
		low LED
	next b0
return

' latch relay
latch:
	high RELAY
return

' release relay
release:
	low RELAY
return
 
You don't really need those subroutines to set the relay pin state, but I thought it might be easier to understand if I left them there since you used a lot of goto statements. Also, the subroutines might make your code easier to decipher if you decide to add more functionality at some point.

Here's what it looks like without the subroutines (and without the LED flash since you said you removed it):

Code:
' constants
	symbol HIGHTRIP = 66	' (42.8F)	' 6 + 60 - adjust as necessary
	symbol LOWTRIP = 64 	' (39.2F)	' 4 + 60
	symbol LED = 2		' led pin
	symbol RELAY = 4	' relay pin
	symbol TEMP = 1		' DSXXXX sensor pin

' variables
	'symbol counter = b1	'unused
	'symbol TempC_100 = W3	'unused
	'symbol DevNum = W6	'unused
	symbol valTemp = B9	'variable for sensor output

' set up pins and flash the status LED once
setup:
	low 0		'set unused pin (Yuri's not sure why...)
	high LED	'status LED on
	pause 600
	low LED
	
' begin main subroutine 
main:
	high LED		' read is in progress (power/activity light)
	readtemp TEMP, valTemp	' read the high 8 bits 
	low LED

	' respond to the temperature
	valTemp = valTemp + 60	' avoid negative numbers
	
	if valTemp >= HIGHTRIP then
		high RELAY
	elseif valTemp < LOWTRIP then
		low RELAY
	endif	

	pause 500	
	goto main
end

This version is just over half the size of the previous (in terms of microcontroller memory space).
 
it runs thru the simulator! put your b9 above 66 and pin four goes high this will work much better. I was debugging my original and it kept unlatching the relay when it went to the goto main until it did the readtemp command. Oh yeah and the reason you set pin 0 to low is that it is used as part of the programming circuit which must hooked up at all times it keeps it from floating and resetting from what i understand.

I am just learning the programming but it seems like a capable little chip.

Thanks Yuri!
 
I am following this thread with interest as while I am no expert, the picaxe chips seem very versatile and cheap, plus all the programming stuff and user manuals are on the internet and free!! For those who don't know, picaxe chips can control motors and soft start them, they can run stepper motors for fine positional control, they can run lighting, run cooling systems, heating elements, you can rig them up to do data logging, put their info up onto simple displays etc etc. The programing is a bit of a steep learning curve, but these things are ofted used in schools as an intro to control technology, so it must be just me having trouble!!!

Is there any chance of adding more info to the right of the programming steps that fully explain what is going on for those of us who are not experienced programmers? The facility is there in the syntax, and it really really helps us dummies!

For any given brewery need, (motor control, heating, cooling, pumping, you name it!) once the programme has been written and checks out ok, almost anyone can use the circuit for it's intended purpose, or modify it for their own application. If we build up a library of several circuits on here they might become quite popular, and used worldwide, as some of us cannot get "love controllers" or whatever, but almost anyone with a soldering iron can make the simple and cheap picaxe circuit.
 
Here is as much code commenting as I could stand to type:

Code:
' constants
	' there is a 2 degree gap between setpoints to avoid unnecessary cycling of the relay as the setpoint is reached
	symbol HIGHTRIP = 66	' (42.8F)	' 6 + 60 - adjust as necessary
	symbol LOWTRIP = 64 	' (39.2F)	' 4 + 60
	symbol LED = 2		' led pin
	symbol RELAY = 4	' relay pin
	symbol TEMP = 1		' DSXXXX sensor pin

' variables
	symbol valTemp = B9	' variable for sensor output
				' uses memory space B9 on the PICAXE chip

' set up pins and flash the status LED once
setup:			' program label that could be used with a goto statement - unnecessary in this case
	low 0		' set pin 0 LOW per PICAXE protocol
	high LED	' status LED on (digital HIGH)
	pause 600	' wait 600 milliseconds
	low LED		' status LED off (digital LOW)
	
' begin main subroutine 
main:				' program label for main subroutine
	high LED		' read is in progress (turn LED on to indicate activity)
	readtemp TEMP, valTemp	' read the temp sensor value into the variable, valTemp 
	low LED			' read is complete (turn LED off)

	' respond to the temperature
	valTemp = valTemp + 60	' avoid negative numbers
	
	if valTemp >= HIGHTRIP then	' if the temp is higher than the setpoint, turn the relay on
		high RELAY		' set the relay pin to digital HIGH
	elseif valTemp < LOWTRIP then	' else if the temp is lower than the setpoint, turn the relay off
		low RELAY		' set the relay pin to digital LOW
	endif				' completes the if/then/elseif/then conditional block

	pause 500	' delay 500 milliseconds
	goto main	' create an infinite loop by going back to the label, main
end			' end statement - only necessary if subroutines follow (so it's extraneous here)
 
For comparison, this program is the barebones equivalent to the one above. It should provide the same functionality, but eliminates all symbolic pointers and the LED. Note that the lack of named variables and constants makes it much tougher to read.

Code:
	low 0		' per PICAXE protocol
' begin main subroutine 
main:			' program label for main subroutine
	readtemp 1, B9	' read the temp sensor into the memory space B9 

	' respond to the temperature
	B9 = B9 + 60	' avoid negative numbers
	
	if B9 >= 66 then	' if the temp is higher than the setpoint, turn the relay on
		high 4		' set the relay pin to digital HIGH
	elseif B9 < 64 then	' else if the temp is lower than the setpoint, turn the relay off
		low 4		' set the relay pin to digital LOW
	endif			' completes the if/then/elseif/then conditional block

	pause 500	' delay 500 milliseconds
	goto main	' create an infinite loop by going back to the label, main

Identical functionality, further obfuscated:

Code:
low 0
m:
readtemp 1, B9
B9 = B9 + 60	
if B9 >= 66 then
high 4
elseif B9 < 64 then
low 4
endif
pause 500
goto m
 
I've looked at a bunch of different microcontroller development boards and tools. I really like Arduino. After messing with PICAXE code, I like Arduino even more - the programming language is much more robust. PICAXE costs slightly less unless you opt for the expensive protoboard, and there are a few neat built-in functions that make rather complex operations very simple. So, PICAXE is a great choice for getting started in the physical computing world. I'll likely stick with Arduino for now.
 
Back
Top