Repeating timer modifier

lamxe

Senior Member
Code:
'REUK.co.uk - The Renewable Energy Website.

'Picaxe Basic code for a repeating ON/OFF timer
'with the following ON and OFF timings:
'ON for 0 hours, 20 minutes, and 0 seconds.
'OFF for 4 hours, 0 minutes, and 0 seconds.

symbol relay = C.1

main:
  
   for b2 = 1 to 20
      gosub pauseONEminute
   next b2

   
   low relay
   
   
   for b2 = 1 to 4
      gosub pauseONEhour
   next b2

  
   goto main

pauseONEhour:
   'Pause for one hour.
   for b0 = 1 to 60 'minutes
      gosub pauseONEminute
   next b0
   return

pauseONEminute:
   'Pause for one minute.
   for b1 = 1 to 60 'seconds
      gosub pauseONEsecond
   next b1
   return

pauseONEsecond:
   'Pause for one second.
   '1000ms (milliseconds) is one second.
   pause 1000
   return
Dear All
I want to use this code ( from UK Picaxe) for driver relay ON 20 min every 4 hours But this program run 24/24, Now I want modifier the code for running 12/24 it mean:
0 to 12 o'clock program ON and 12 to 24 o'clock program pause (OFF) and repeat. So please help me to have a new code
Many thank you
Best regards
l;am

Mod Edit :added code tags
 
Last edited by a moderator:

inglewoodpete

Senior Member
I would not use a 1000mS delay to act as the basis of a long-term timer. Both M2 and X2 PICAXEs have inbuilt timers that can count seconds with reasonable accuracy (within 3 to 5 minutes a day when run at room temperatures). Just avoid using any "blocking" commands that could stall the background timer for more than a second. For M2s, refer to the system variable "Time" and commands "EnableTime" and "DisableTime". For X2s, there are more options and consequently it is a bit more complicated - start by reading up on command "SetTimer"

I once wrote a clock program using an 08M2, with an LDR to detect sunset and sunrise, resetting the timer every 24 hours. (One day is 1440 minutes, so manageable in a 16-bit register). It was surprisingly accurate, to within that 3 to 5 minutes that I referred to earlier. The clock has been in operation for over five years, utilised as a lighting controller for an outdoor artwork. If absolute time is required, midnight can be calculated as roughly halfway between dusk and dawn, offset by your location relative to your time zone reference longitude. Let's not debate daylight saving :).
 

hippy

Technical Support
Staff member
There are 240 minutes in 4 hours, so you could have your thing on for the first 20 minutes and off the rest of the time ...
Code:
Do
  For minutes = 1 To 240
    If minutes <= 20 Then
      Gosub SetOn
    Else
      Gosub SetOff
    End If
    Gosub WaitOneMinute
  Next
Loop
You can modify that for hours, and on between 00:00-11:59, off from 12:00-23:59 ...
Code:
Do
  For hours = 0 To 23
    If hours < 12 Then
      Gosub SetOn
    Else
      Gosub SetOff
    End If
    Gosub WaitOneHour
  Next
Loop
 

lamxe

Senior Member
I would not use a 1000mS delay to act as the basis of a long-term timer. Both M2 and X2 PICAXEs have inbuilt timers that can count seconds with reasonable accuracy (within 3 to 5 minutes a day when run at room temperatures). Just avoid using any "blocking" commands that could stall the background timer for more than a second. For M2s, refer to the system variable "Time" and commands "EnableTime" and "DisableTime". For X2s, there are more options and consequently it is a bit more complicated - start by reading up on command "SetTimer"

I once wrote a clock program using an 08M2, with an LDR to detect sunset and sunrise, resetting the timer every 24 hours. (One day is 1440 minutes, so manageable in a 16-bit register). It was surprisingly accurate, to within that 3 to 5 minutes that I referred to earlier. The clock has been in operation for over five years, utilised as a lighting controller for an outdoor artwork. If absolute time is required, midnight can be calculated as roughly halfway between dusk and dawn, offset by your location relative to your time zone reference longitude. Let's not debate daylight saving :).
Thanks so much for sharing your experience
 

lamxe

Senior Member
There are 240 minutes in 4 hours, so you could have your thing on for the first 20 minutes and off the rest of the time ...
Code:
Do
  For minutes = 1 To 240
    If minutes <= 20 Then
      Gosub SetOn
    Else
      Gosub SetOff
    End If
    Gosub WaitOneMinute
  Next
Loop
You can modify that for hours, and on between 00:00-11:59, off from 12:00-23:59 ...
Code:
Do
  For hours = 0 To 23
    If hours < 12 Then
      Gosub SetOn
    Else
      Gosub SetOff
    End If
    Gosub WaitOneHour
  Next
Loop
This is the code I want to make thanks a lot
for your precious code .Thank you again for your time help me
 
Top