Basic Timer Revisited

novolts

Senior Member
Hi Guys
I tried to edit my previous thread however I could not post the edited thread ,so apologies for starting a new thread

Re my previous post of 20-05-16 I read up on time as advised by westaust55
I altered the code to include a 10 second timer I chose 10 seconds as a starting point
I intend to increase the timer to switch off after 45 minutes even if the temperature is not reached
I would appreciate the comments of forum members on the code
thanks
novolts

#Picaxe 14M2

Symbol BoilerOn = PINC.2
Symbol temperature = b1
Symbol tempWanted = b2

Symbol POT_MIN = 55
Symbol POT_MAX = 65
readtemp C.4, temperature

start:

if BoilerOn=0 then
goto start
else
goto main
endif

main:

time =0

do

ReadTemp C.4, temperature

ReadAdc C.0, tempWanted

tempWanted = POT_MAX - POT_MIN * tempWanted / 255 + POT_MIN

If tempWanted >= temperature Then
High B.5
End If

If temperature>=tempWanted Then
Low B.5
goto start
Endif
loop until time>=10:Low B.5
goto start
 

BESQUEUT

Senior Member
Please, use "copy for forum" :
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]

[color=Blue]Symbol [/color][color=Black]BoilerOn [/color][color=DarkCyan]= [/color][color=Purple]PINC.2[/color]
[color=Blue]Symbol [/color][color=Black]temperature [/color][color=DarkCyan]= [/color][color=Purple]b1[/color]
[color=Blue]Symbol [/color][color=Black]tempWanted [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]

[color=Blue]Symbol [/color][color=Black]POT_MIN [/color][color=DarkCyan]= [/color][color=Navy]55[/color]
[color=Blue]Symbol [/color][color=Black]POT_MAX [/color][color=DarkCyan]= [/color][color=Navy]65[/color]
[color=Blue]readtemp C.4[/color][color=Black], temperature

start:[/color]
[color=Blue]if [/color][color=Black]BoilerOn[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]then 
      goto [/color][color=Black]start[/color]
[color=Blue]else 
      goto [/color][color=Black]main[/color]
[color=Blue]endif[/color]

[color=Black]main:[/color]

[color=Purple]time [/color][color=DarkCyan]=[/color][color=Navy]0[/color]

[color=Blue]do
      ReadTemp C.4[/color][color=Black], temperature
      [/color][color=Blue]ReadAdc C.0[/color][color=Black], tempWanted

      tempWanted [/color][color=DarkCyan]= [/color][color=Black]POT_MAX [/color][color=DarkCyan]- [/color][color=Black]POT_MIN [/color][color=DarkCyan]* [/color][color=Black]tempWanted [/color][color=DarkCyan]/ [/color][color=Navy]255 [/color][color=DarkCyan]+ [/color][color=Black]POT_MIN

      [/color][color=Blue]If [/color][color=Black]tempWanted [/color][color=DarkCyan]>= [/color][color=Black]temperature [/color][color=Blue]Then 
            High B.5
      End If

      If [/color][color=Black]temperature[/color][color=DarkCyan]>=[/color][color=Black]tempWanted [/color][color=Blue]Then
            Low B.5
            goto [/color][color=Black]start
      [/color][color=Blue]Endif
loop until [/color][color=Purple]time[/color][color=DarkCyan]>=[/color][color=Navy]10[/color]
[color=Blue]Low B.5
goto [/color][color=Black]start[/color]
 

hippy

Ex-Staff (retired)
A Finite State machine is probably the best way to code a control system like this. Then it becomes easier to add new states. Currently I would guess you have a heating phase which only ends when up to temperature, which could be in an FSM ...

Code:
case START_HEATING:
  High HEATER
  state = HEATING

Case HEATING:
  If temperature > 90 Then
    state = HOT_ENOUGH
  End If

Case HOT_ENOUGH:
That would be easy enough to add a 45 minute timeout to ...

Code:
Case START_HEATING:
  High HEATER
  [b]elapsedMinutes = 0[/b]
  state = HEATING

Case HEATING:
  If temperature > 90 [b]or elapsedMinutes > 45[/b] Then
    state = HOT_ENOUGH
  End If

Case HOT_ENOUGH:
 

BESQUEUT

Senior Member
Please, remove all GOTO commands...
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]

[color=Blue]Symbol [/color][color=Black]BoilerOn [/color][color=DarkCyan]= [/color][color=Purple]PINC.2[/color]
[color=Blue]Symbol [/color][color=Black]temperature [/color][color=DarkCyan]= [/color][color=Purple]b1[/color]
[color=Blue]Symbol [/color][color=Black]tempWanted [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]

[color=Blue]Symbol [/color][color=Black]POT_MIN [/color][color=DarkCyan]= [/color][color=Navy]55[/color]
[color=Blue]Symbol [/color][color=Black]POT_MAX [/color][color=DarkCyan]= [/color][color=Navy]65[/color]
[color=Blue]readtemp C.4[/color][color=Black], temperature[/color]

[color=Blue]do
      loop until [/color][color=Black]BoilerOn[/color][color=DarkCyan]<>[/color][color=Navy]0

      [/color][color=Blue]ReadTemp C.4[/color][color=Black], temperature
      [/color][color=Blue]ReadAdc C.0[/color][color=Black], tempWanted

      tempWanted [/color][color=DarkCyan]= [/color][color=Black]POT_MAX [/color][color=DarkCyan]- [/color][color=Black]POT_MIN [/color][color=DarkCyan]* [/color][color=Black]tempWanted [/color][color=DarkCyan]/ [/color][color=Navy]255 [/color][color=DarkCyan]+ [/color][color=Black]POT_MIN

      [/color][color=Blue]If [/color][color=Black]tempWanted [/color][color=DarkCyan]>= [/color][color=Black]temperature [/color][color=Blue]Then 
            High B.5
            [/color][color=Purple]time [/color][color=DarkCyan]=[/color][color=Navy]0
            [/color][color=Blue]loop until [/color][color=Purple]time [/color][color=DarkCyan]>= [/color][color=Navy]10
      [/color][color=Blue]Endif
      Low B.5
loop[/color]
 

rossko57

Senior Member
Really you also need to define what you want to happen when the timer expires. You might have the Picaxe just do nothing forever, until turned off/on again. Or you might arrange it so that switching the BoilerOn switch makes it start another heating cycle. Or maybe there should be a delay before another cycle is allowed ... your choices!
 

BESQUEUT

Senior Member
I intend to increase the timer to switch off after 45 minutes even if the temperature is not reached
OK for that,... but, in that case :
How long will you wait before attempting a new heating phase ?

edit : same question as Rossko just asks...
 

lbenson

Senior Member
Not relevant to your specific question, but you could replace the code between "start:" and "main:" with

do while BoilerOn=0 loop

When BoilerOn no longer is equal to 0, execution falls through to "main:".
 

novolts

Senior Member
Hi Guys
Thanks for all the replies much appreciated
Besquet I pasted the code you kindly posted into P.E however it produced an error code "loop" ( the last line ) without "do"
I am working on the code just now and again thank you Besquet
The purpose of the circuit is to heat hot water between 55oC to 65oC and time out after 45 minutes for the summer only
My sister has an oil fired boiler and in the summer has a habit of setting the hot water switch on the controller to the manual setting and forgetting to switch it off
I want to construct a timer with a push button ,once pushed the timer will cut out on temperature or time
thanks
novolts
 

BESQUEUT

Senior Member
Besquet I pasted the code you kindly posted into P.E however it produced an error code "loop" ( the last line ) without "do"
OK : there where some do: missing...
Code:
[color=Navy]#Picaxe [/color][color=Black]14M2[/color]

[color=Blue]Symbol [/color][color=Purple]BoilerOn [/color][color=DarkCyan]= [/color][color=Purple]PINC.2[/color]
[color=Blue]Symbol [/color][color=Purple]temperature [/color][color=DarkCyan]= [/color][color=Purple]b1[/color]
[color=Blue]Symbol [/color][color=Purple]tempWanted [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]

[color=Blue]Symbol POT_MIN [/color][color=DarkCyan]= [/color][color=Navy]55[/color]
[color=Blue]Symbol POT_MAX [/color][color=DarkCyan]= [/color][color=Navy]65[/color]
[color=Blue]readtemp C.4[/color][color=Black], [/color][color=Purple]temperature[/color]

[color=Blue]do
      do[/color][color=Black]:[/color][color=Blue]loop until [/color][color=Purple]BoilerOn[/color][color=DarkCyan]<>[/color][color=Navy]0

      [/color][color=Blue]ReadTemp C.4[/color][color=Black], [/color][color=Purple]temperature
      [/color][color=Blue]ReadAdc C.0[/color][color=Black], [/color][color=Purple]tempWanted

      tempWanted [/color][color=DarkCyan]= [/color][color=Blue]POT_MAX [/color][color=DarkCyan]- [/color][color=Blue]POT_MIN [/color][color=DarkCyan]* [/color][color=Purple]tempWanted [/color][color=DarkCyan]/ [/color][color=Navy]255 [/color][color=DarkCyan]+ [/color][color=Blue]POT_MIN

      If [/color][color=Purple]tempWanted [/color][color=DarkCyan]>= [/color][color=Purple]temperature [/color][color=Blue]Then 
            High B.5
            [/color][color=Purple]time [/color][color=DarkCyan]=[/color][color=Navy]0
            [/color][color=Blue]do[/color][color=Black]:[/color][color=Blue]loop until [/color][color=Purple]time [/color][color=DarkCyan]>= [/color][color=Navy]10
      [/color][color=Blue]Endif
      Low B.5
loop[/color]
I am working on the code just now and again thank you Besquet
The purpose of the circuit is to heat hot water between 55oC to 65oC and time out after 45 minutes for the summer only
My sister has an oil fired boiler and in the summer has a habit of setting the hot water switch on the controller to the manual setting and forgetting to switch it off
I want to construct a timer with a push button ,once pushed the timer will cut out on temperature or time
thanks
novolts
You till need to answer questions #5 and/or #6
 
Top