![]() |
Forum Index : Microcontroller and PC projects : On timer ...
Author | Message | ||||
plasma Guru ![]() Joined: 08/04/2012 Location: GermanyPosts: 437 |
What do you think of a new command Such like " on timer(x) gosub xyz" I know an interupt enabled pin and a 555 will do to same but a command can change the timer with software. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9501 |
You could do the same thing with an interrupt... Example: SETTICK 1000,XYZ You can have up to four different tick timers running like this. The above example assumes timer #1, as no number is specified, however, if you needed to setup multipule ones, you could use SETTICK 1000,XYZ,2 which would set tick timer #2 to loop to sub XYZ every second. Smoke makes things work. When the smoke gets out, it stops! |
||||
plasma Guru ![]() Joined: 08/04/2012 Location: GermanyPosts: 437 |
Ah ok , i forget this .. Thx a lot |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9501 |
SETTICK is a great command. ![]() I use it in my system in a couple of ways. One is every 250ms to update the on-screen clock display, a 2nd timer to check if there is any data in the serial buffer that needs attention, and a 3rd to check every second if the system needs to crank up the screensaver cos no-one has pressed a key. Just remember - use IRETURN in your sub, as this is an interrupt, tripped by the timer(s), so plain END SUB won't work, or will give unpredictable results. Smoke makes things work. When the smoke gets out, it stops! |
||||
plasma Guru ![]() Joined: 08/04/2012 Location: GermanyPosts: 437 |
Will a to long working interrupt routine Overriding the next calls. ? Cant test yet so i ask Pseudocode Settick 100,xyz Sub Xyz : Pause 250 Ireturn End dub |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3272 |
Just a point of clarification. IRETURN is used to return from the interrupt when the interrupt called a label. A subroutine can also be specified for the interrupt target and in that case return is via EXIT SUB or END SUB (not IRETURN). Geoff Geoff Graham - http://geoffg.net |
||||
plasma Guru ![]() Joined: 08/04/2012 Location: GermanyPosts: 437 |
Thx Geoff |
||||
G8JCF![]() Guru ![]() Joined: 15/05/2014 Location: United KingdomPosts: 676 |
@plasma ISRs/Setticks should be kept as quick as possible, Only do the bare minimum in the ISR. This approach tends to lead to a more responsive system. The technique I use is to have Main Do ..forever.. Loop which checks for Global flags which are set ON by the ISRs/Setticks when an Interrupt occurs, eg ========================================================= ' 'Here on Settick 1 'Settick 1 ISR ' UpdateLCD: 'Signal that if the LCD needs updating now's the time to do it DispTick=1 'Is Backlight already OFF IF BacklightTimer>0 THEN 'No so count down BacklightTimer=BacklightTimer-1 'Is it time to turn OFF the backlight ? IF BacklightTimer<1 THEN 'Signal request that Backlight should be turned OFF BacklightOnOff=&H01 ENDIF ENDIF IRETURN Then in the Main Do ...Forever .... Loop, when it notices that one of these global flags is set ON, code is actioned, and that code can be long stuff. When that code has finished, the Main loop resets the global flag. eg 'Has there been a Display Tick AND a Request to Display ? IF (DispTick AND DispRqst) THEN CPU 48 DispFreq 'Reset the Display Request & Display Tick flags DispRqst=0 DispTick=0 'Slowdown the CPU to save power CPU 5 ENDIF 'Has there been a request to Turn ON | OFF the LCD backlight ? IF (BacklightOnOff<>0) THEN CPU 48 IF BacklightOnOff=&H01 THEN LCDI2C_BackLight(0) ELSE LCDI2C_Backlight(1) ENDIF BacklightOnOff=&H0 CPU 5 ENDIF Hope this helps Peter The only Konstant is Change |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9501 |
I had that wrong then - sorry Plasma! ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |