how to include a basic timer

novolts

Senior Member
Hi Guys
with reference to the code below I would like to include a 45 minute timer (approx ) below so that the timer switches the boiler off after 45 mins
The boiler switches off when the temperature reaches 60oC
I have tried using for and next commands to create the timer but I cannot integrate it to the code below
any tips would be greatfully received
thank you
novolts

#picaxe 14m2
symbol PUSH_SW = pinC.1 ; switch boiler on
symbol TH_STAT = pinC.4 ; Strap on cylinder thermostat ( set at 60oC )

do

if PUSH_SW=1 then
high B.2 ;switch boiler on
end if

if TH_STAT=1 then
low B.2 ;switch boiler off when hot water temperature is 60oC
end if

loop
 

lbenson

Senior Member
For the M2 parts, "time" is a word variable which counts seconds, so you can set it to 0 when you turn the boiler on, and turn the boiler off when it is greater than 60*45 or 2700.

Use a flag (for instance, bit0) if you like so that you only look at the seconds counter when the boiler is on.

symbol bBoilerOn = bit0

...
Code:
if bBoilerOn = 1 and time > 2700 then
  bBoilerOn = 0
  low B.2
endif
 

novolts

Senior Member
Ibenson
I thank you for your reply
I cant seem to get your code to work I have cut and pasted it into my code but nothing seems to happen
its entirely down to me not having the intelligence to understand the code
kindest regards
novolts
 

lbenson

Senior Member
That was just a snippet--we'd have to see all of your code, as amended, to see exactly what you're trying to do.

Did you set "time = 0" and "bBoilerOn = 1" within your "if PUSH_SW=1 then" clause?
 
Last edited:

novolts

Senior Member
Hi Ibenson
Thank you for your time and help
below is the complete code including your snippet what I am trying to achieve is either the boiler is switched off after 45 minutes or switched off by the thermostat canceling the timer providing the thermostat reaches the temperature

#picaxe 14m2
symbol PUSH_SW = pinC.1 ; switch boiler on
symbol TH_STAT = pinC.4 ; Strap on cylinder thermostat ( set at 60oC )
symbol bBoilerOn = bit0

do

if PUSH_SW=1 then
high B.2 ;switch boiler on
time = 0
end if

if bBoilerOn = 1 and time >2700 then
bBoilerOn = 0
low B.2
end if



if TH_STAT=1 then
low B.2 ;switch boiler off when hot water temperature is 60oC
end if

loop
 

novolts

Senior Member
Hi Guys
I have come to the conclusion that its time I stopped fooling myself
I cant seem to get even the simplest codes to work
so I am giving up
its with sadness as I really do enjoy attempting to program the picaxe chips
but for me there has got to be an end result
but as most of you can see from my previous thread I go 3 steps forward and 10 backward
and no end result
without the immense help from you guys I would not have been able to go forward 3 steps
I thank each and everyone of you for all the help in the past
kindest regards to all
novolts
 

Polaris Jim

New Member
You don't want to give up! I'm no expert, but I usually find a way to make my code work. I've never used the "time" command yet, but have made timers with pauses within loops. Give that a try. Study the online manuals. You CAN do this!
 

neiltechspec

Senior Member
Don't give up !.

Code:
#picaxe 14m2
symbol PUSH_SW = pinC.1 ; switch boiler on
symbol TH_STAT = pinC.4 ; Strap on cylinder thermostat ( set at 60oC )

main:

	do

	if PUSH_SW=1 and TH_STAT=0 then
	 high B.2 	;switch boiler on
	 time = 0
	endif

	if time >= 2700 then
	 low B.2	;switch boiler off
	endif


	if TH_STAT=1 then
 	 low B.2 	;switch boiler off
	endif

	loop
Neil
 
Last edited:

novolts

Senior Member
Thank you IBenson ,Polaris Jim & neiltechspec the code works a treat neiltechspec it makes so much sense
I appreciate the time taken you guys have taken out of your own time to reply to my thread
May I also take the oppertunity to thank the person that sent myself a buddy request which I have accepted and very much appreciate but I hope not to pester
too much in the future
faith in human nature is a wonderful thing
kindest regards
novolts
 

novolts

Senior Member
Thank you IBenson ,Polaris Jim & neiltechspec the code works a treat neiltechspec it makes so much sense
I appreciate the time taken you guys have taken out of your own time to reply to my thread
May I also take the oppertunity to thank the person that sent myself a buddy request which I have accepted and very much appreciate but I hope not to pester
too much in the future
faith in human nature is a wonderful thing
kindest regards
novolts
 

grim_reaper

Senior Member
I can understand how frustrating it is learning a new language (I must have been through hundreds in my career so far - it's actually a relief to hear that some of them won't be making a comeback!). Reading this forum every day is what keeps my optimism going; you're quite right, faith in human nature is good. We're lucky to have so many experts in this field that are willing to help with all sorts of random problems - you don't get such good responses (or any usually!) on other forums.
Keep at it novolts! I'm entirely self-taught, so look at it this way; in 18 years you'll know as much as me!!
 

novolts

Senior Member
Thank you
grim_reaper but I am 56 so in 18 years time I will 74 so I will be lucky to be able to anything other than maybe sit in the rocking chair and watch films of my
favourite Glasgow football team but I do hope that picaxe and Rev Ed are around for the up and coming kids I just wish the education authorities in Scotland would encourage children to learn picaxe the fun kids could have would be tremendous and the buzz actually seeing the outcome of there own efforts well priceless
well I better get off the soapbox and start on the picaxe rocking chair
kind regards
novolts
 

Jeff Haas

Senior Member
Many of us started that way. I learned by examining examples like that and then going to the manuals and looking up every command to understand what was going on. Why is he using SYMBOL at the top? What is the do:loop structure? How did he set up the If:Then structure? Etc.

Over time you will grasp the programming concepts and be able to look at other examples here and expand what you can do. And the members of this forum are terrific! I've gotten a lot of help over the years.
 

premelec

Senior Member
@novolts - first change your name to HiVolts - it's hard to make any progress with 0 volts! I like the puzzle solving aspects of programming - when it finally works! [I'm 78 years old and forget a lot and have to refer to manuals to get stuff right]. However if it's really no fun and no progress good to go for a bike ride or take a walk etc... good luck with it and thanks for stopping by - you are welcome any time again...
 
Top