The best solution to at least half of all timing problems is using a timer interrupt. I don't know why so many people avoid that technique!
If you use an interrupt, you can do all your timing in the background.
The best solution to at least half of all timing problems is using a timer interrupt. I don't know why so many people avoid that technique!
If you use an interrupt, you can do all your timing in the background.
Charles Linquist
While I don't disagree, when the level of accuracy is as low as this app seems to be, polling the flag seems the easier to understand solution. The OP is looking for time between 0 and 30 minuites. Seems like an INT may be just a bit overkill. Granted, we have no idea what else needs to be done in the program, so an Interrupt may well be the best overall solution.![]()
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
If Time accuracy is not an issue then a simple routine like this should solve the problem:
All the time your Pin_1 will go to zero the time check will be activated.Code:Counter Var WORD Main: IF Pin_1 = 0 then PAUSE 1000 ' one second delay Counter = Counter + 1 IF Counter >1800 then Output_3 = 1 ENDIF IF Pin_1 = 1 and Counter > 1 then IF Counter <= 120 then Output_1 = 1 IF Counter >120 and Conter <= 1200 then Outpt_2 = 1 IF Counter >1200 then Output_3 = 1 Counter = 0 ENDIF GOTO Main
Cheers
Al.
Last edited by aratti; - 10th March 2011 at 06:48.
All progress began with an idea
another option with more time to do other things:
Nothing wrong with Aratti's example, just showing another way.Code:counter var word counting var bit turn on 16 bit timer ' @4mHz osc, this will take .065535 seconds to roll over counter = 0 MAIN: IF TxIF = 1 THEN GOSUB TIMESTUFF ' TxIF is the timer interrupt flag 'USER CODE GOES HERE GOTO MAIN TIMESTUFF: TxIF = 0 'clear interrupt flag IF PIN_1 = 0 THEN COUNTER = COUNTER + 1 COUNTING = 1 ENDIF IF (COUNTING) AND (PIN_1) THEN IF COUNTER <= 1830 THEN OUTPUT_1 = 1 ' 1 second = aproxx 15.25 counts IF COUNTER >1830 AND COUNTER <18300 THEN OUTPUT_2 = 1 ' if you want to do anything for time between 20 and 30 mins, here's a good spot for that IF COUNTER >27450 THEN OUTPUT_3 = 1 COUNTER = 0 COUNTING = 0 ENDIF RETURN
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Bookmarks