|
Forum Index : Microcontroller and PC projects : Processing at a particular time
| Author | Message | ||||
| Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 137 |
Hi Guys I need to have a process on my CMM to occur at 2am in the morning plus or minus a couple of minutes. I have used settick set to 1hr and then checked the hour, but the problem with that was that it depended on when I loaded and started the program. Short of constantly checking the time, is there a better way. Has someone written a better solution? Chrisk |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
No, there is not an "interrupt at a specific time" function. However, there is nothing wrong with constantly checking the time. Nearly all embedded control programs have at their core a continuously running loop. Checking the time in that loop is very fast so it will not impact on your program. The processor is mostly doing nothing useful anyway while spinning in the loop. An alternative is to get the time when your program starts, calculate the number of microseconds to 2AM them set a tick timer to that number. In the tick timer interrupt subroutine you would then reset the tick time to 86400000 (the number of microseconds in a day). Geoff Geoff Graham - http://geoffg.net |
||||
Chopperp![]() Guru Joined: 03/01/2018 Location: AustraliaPosts: 1106 |
Hi I currently use 2 time checks for my CMM2. One to do stuff just before midnight & then restart & another just after midnight to do day initialisation. Both are run in a continuous DO...LOOP which does various other things. The code below gives a 5 sec window from 21:59:55 to do stuff IF LEFT$(TIME$,7) = "23:59:5" THEN ... endif This other piece of code gives a minute window to do stuff after restarting IF LEFT$(TIME$,5) = "00:00" then ... endif You may need to set a flag once the process is done so it doesn't run again within the specified time period. The following would give you a 10 sec window at 2am to run your process IF LEFT$(TIME$,7) = "02:00:0" then ... endif I also use the following code to start the main program at the top of the minute if restarted at other times. SU$ = RIGHT$(TIME$, 1) 'units seconds of time$ DO WHILE MID$(TIME$,7, 1) <> "0" 'start prog on the minute. IF SU$ <> RIGHT$(TIME$, 1) THEN PRINT @(12, 60) "Waiting for Minute " + TIME$ PRINT @(12, 75) ver$ 'print prog version SU$ = RIGHT$(TIME$, 1) ENDIF LOOP EDIT I forgot I also run the code below to do a screen save at 3am, 6am, 9am etc IF DS_4_Flag THEN 'Flag Set. Update Graph etc every - 30secs graph_Save_Time = (VAL(LEFT$(TIME$,2)) * 60) + VAL(MID$(TIME$,4,2)) 'Cal number of minutes IF NOT (Graph_Save_Time MOD 180) THEN 'N0 minutes / by 180 (3hrs) IF NOT Graph_Done_Flag THEN Save_Graph 'save graph at "03:00", "09:00", "12:00" etc ELSE Graph_Done_Flag = 0 'set flag ENDIF Graph1 'Update Main graph. ENDIF Brian Edited 2021-02-10 16:57 by Chopperp ChopperP |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
See my Timer pack below. It is a standard include in any stuff I write that requires timers of any kind, I think it's a lot easier as only a single timer Sub handles everything and you just check a flag to know when a particular event has occurred - you decide when to service a timer which is often better than getting an interrupt with no control over at what part of you code that happens. Check AT() or EVERY() http://www.fruitoftheshed.com/MMBasic.AFTER-EVERY-REMAIN-Flexible-State-Machine-Timers-using-Semaphores.ashx Edited 2021-02-10 22:15 by CaptainBoing |
||||
| Chrisk Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 137 |
Thanks guys for your prompt help. Chrisk |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |