Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:44 29 Nov 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 : Stopping and restaring the TICK timers...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 04:20pm 16 Mar 2014
Copy link to clipboard 
Print this post

I am having issues restarting the tick timers.

In a routine, I stop all the tick timers, which just add to a counter for a screen-saver, and draw the clock and pulse and external WDT.

Stopping them is fine, but then they won't restart for me.

So, at the very top of the code, I start the timers thus:


settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3


...then in the processing routine, I turn them all off to stop them interferring with the processing:


settick 0,0,1:SEttick 0,0,2:settick 0,0,3


This is all fine, but when I exit from the routine back the main menu when the timers need to be restarted, just before I go to the main menu, I try to re-enable the tick timers with:


settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3


...but they don't start - they stay off.

Any ideas what I am doing wrong?

Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 04:35pm 16 Mar 2014
Copy link to clipboard 
Print this post

Well, I wrote a basic testing code thus:


settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3

cls

print "Timers running..."
pause 2000
print "Stopping timers..."
settick 0,0,1:settick 0,0,2:settick 0,0,3
print "Timers stopped."
pause 2000
print "Restarting timers..."
settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3

DO:LOOP

end

DAT:
A=A+1
print @(50,100); A
ireturn

WDT:
B=B+1
print @(50,115); B
ireturn

SST:
C=C+1
print @(50,130); C
ireturn


...and they stop and start fine, so there must be some kind of bug in my code somewhere - perhaps I am stopping them somewhere else.

Hunt, hunt, hunt.........
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 05:41pm 16 Mar 2014
Copy link to clipboard 
Print this post

I can't find any other place where I might have stopped the timers.
I do stop them in the screensaver, but they are re-enabled when you press a key, and those ones DO re-enable.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3196
Posted: 07:44pm 16 Mar 2014
Copy link to clipboard 
Print this post

I have just had a look through the source and I cannot see anything that would stop you from re enabling them.

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 07:48pm 16 Mar 2014
Copy link to clipboard 
Print this post

Yeah, I don't get it - I am about to print out all the code, then lay it all out on the table and examine it line by line - there must be a bug in there somewhere.

I thought that perhaps MMBasic did not like having the tick timers stopped and started more then once or twice, so I wrote this test code:


settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3

mode 4:cls

print @(20,20)"Timers running..."
pause 3500
print @(20,40)"Stopping timers..."
settick 0,0,1:settick 0,0,2:settick 0,0,3
print @(20,60)"Timers stopped. "
pause 3500:gosub clines
print @(20,20)"Restarting timers...(1)"
settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3
pause 3500:gosub clines
print @(20,40)"Stopping timers...(1) "
settick 0,0,1:settick 0,0,2:settick 0,0,3
print @(20,60)"Timers stopped.(1) "
pause 3500:gosub clines
print @(20,20)"Restarting timers...(2)"
settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3
pause 3500:gosub clines
print @(20,40)"Stopping timers...(2) "
settick 0,0,1:settick 0,0,2:settick 0,0,3
print @(20,60)"Timers stopped.(2) "
pause 3500:gosub clines
print @(20,20)"Restarting timers...(3)"
settick 250,DAT,1:SEttick 500,WDT,2:settick 1000,SST,3
pause 3500
print @(20,60)"Test finished. "

DO:LOOP

clines:
print @(20,20)" "
print @(20,40)" "
print @(20,60)" "
return

end

DAT:
A=A+1
print @(50,120); A
ireturn

WDT:
B=B+1
print @(50,140); B
ireturn

SST:
C=C+1
print @(50,160); C
ireturn


But they(the timers) all stopped and started fine to the end of the test code.

Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 08:34pm 16 Mar 2014
Copy link to clipboard 
Print this post

FIXED IT!

I am still learning interrupts, and made the same mistake twice.

I was calling the processing routine from within the interrupt(thinking I was being clever), and thus that interrupt, once called, never got returned, and so the tick timers could never be set again.

The fix was easy - set a flag within the interrupt, and check that OUTSIDE of the interrupt, once it had been returned. Once I did that, everything is working fine.

Perhaps an entry in the MMBasic Bible: "Thou shalt ALWAYS return interrupts."

Edited by Grogster 2014-03-18
Smoke makes things work. When the smoke gets out, it stops!
 
Lou

Senior Member

Joined: 01/02/2014
Location: United States
Posts: 229
Posted: 07:47am 17 Mar 2014
Copy link to clipboard 
Print this post

"Thou shalt ALWAYS return interrupts."


Grog,

I don't have enough fingers and toes (and maybe hairs left) to count the times I've done that. I usually find it after the program crashes in a big WTF.

Usually good for a couple of chuckles...

Lou
Microcontrollers - the other white meat
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:31am 17 Mar 2014
Copy link to clipboard 
Print this post

Grog,

I would suggest using defined subroutines for your interrupt handlers (and other subroutines).
You would then not need a label and a specific ireturn/return.
Also the change of 'falling through' from another label is then impossibe.
Your program will be more robust.
Using it is simple (Ain't everything! :) )

isntead of using this:
[code]
WDT:
B=B+1
print @(50,140); B
ireturn
[/code]
you use this:
[code]
SUB WDT
B=B+1
print @(50,140); B
END SUB
[/code]

Have fun!

Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 11:26am 17 Mar 2014
Copy link to clipboard 
Print this post

@ Lou - Yeah, all fun and games until something goes wrong, and you spend hours scratching your head trying to find the bug! Some bugs can hide themselves VERY well.

@ TZA - Yeah, that is an idea. I thought that an interrupt HAS to return with an IRETURN. However, reading the manual a bit more, I found that with the tick timers, you can call a sub as an interrupt, and just have the END SUB, as you show in your example. Sounds like a good idea - will check it out.
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