Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:56 08 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : On timer ...

Author Message
plasma
Guru

Joined: 08/04/2012
Location: Germany
Posts: 437
Posted: 09:51pm 21 Aug 2014
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9067
Posted: 09:57pm 21 Aug 2014
Copy link to clipboard 
Print this post

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: Germany
Posts: 437
Posted: 10:04pm 21 Aug 2014
Copy link to clipboard 
Print this post

Ah ok , i forget this ..
Thx a lot
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9067
Posted: 10:21pm 21 Aug 2014
Copy link to clipboard 
Print this post

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: Germany
Posts: 437
Posted: 11:42pm 21 Aug 2014
Copy link to clipboard 
Print this post

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: Australia
Posts: 3165
Posted: 11:47pm 21 Aug 2014
Copy link to clipboard 
Print this post

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: Germany
Posts: 437
Posted: 11:53pm 21 Aug 2014
Copy link to clipboard 
Print this post

Thx Geoff
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 12:02pm 22 Aug 2014
Copy link to clipboard 
Print this post

@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 Zealand
Posts: 9067
Posted: 04:31pm 22 Aug 2014
Copy link to clipboard 
Print this post

  Geoffg said   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


I had that wrong then - sorry Plasma!
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024