Baffling background running behaviour using Timer object [SOLVED]
4Alex
Posts: 119
Good morning all,
I am using background cogs for monitoring sensors. In my development, I want to use a LED to monitor passage of critical breakpoints in my program. Backgroung seems to work fine but there is something going on that I can't explain: when I try to toggle a LED in the backgroung code, absolutely nothing happens! I use the excellent Timer object written by Jon Williams from Parallax as a heartbeat generator and I do get a reliable time increase, so I know the object is working just fine. However, if I try to toggle an LED from within updateTimer then it doesn't work at all. Does anyone know why can't toggle a pin from a background cog? BTW, ANYWHERE ELSE in the rest of the object (start, stop, reset, set, etc) I can successfully toggle the LED!
Here's a code snippet of what I am trying to do:
Any explanation for this behaviour (an a workaround) would greatly contribute in maintaining my sanity...
Cheers,
Alex
Post Edited (4Alex) : 7/22/2009 4:02:13 PM GMT
I am using background cogs for monitoring sensors. In my development, I want to use a LED to monitor passage of critical breakpoints in my program. Backgroung seems to work fine but there is something going on that I can't explain: when I try to toggle a LED in the backgroung code, absolutely nothing happens! I use the excellent Timer object written by Jon Williams from Parallax as a heartbeat generator and I do get a reliable time increase, so I know the object is working just fine. However, if I try to toggle an LED from within updateTimer then it doesn't work at all. Does anyone know why can't toggle a pin from a background cog? BTW, ANYWHERE ELSE in the rest of the object (start, stop, reset, set, etc) I can successfully toggle the LED!
Here's a code snippet of what I am trying to do:
PRI updateTimer '' Updates timer registers '' -- start method launches this method into separate cog repeat ' run until cog unloaded if running ' if timer enabled outa[noparse][[/noparse]LED]~~ '<=== turn LED on but doesn't work! waitcnt(clkfreq / TIX_DLY + cnt) ' do tix delay tix := ++tix // 100 ' update tix if (tix == 0) ' rollover? scs := ++scs // 60 ' yes, update seconds if (scs == 0) ' rollover? mns := ++mns // 60 ' yes, update minutes if (mns == 0) ' rollover? hrs := ++hrs // 24 ' yes, update hours if (hrs == 0) ' rollover? ++dys ' yes, increment days
Any explanation for this behaviour (an a workaround) would greatly contribute in maintaining my sanity...
Cheers,
Alex
Post Edited (4Alex) : 7/22/2009 4:02:13 PM GMT
Comments
Before You can use ...
outa[noparse][[/noparse]LED]~~
You must have one...
DIRa[noparse][[/noparse]LED]~~ else ~
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
Thank you so much for your reply. You are prefectly right: adding a dira[noparse][[/noparse]20]~~ just before the outa[noparse][[/noparse]20]~~ in THAT specific portion of the code made it work.
But what I don't get is that it I already had the dira[noparse][[/noparse]20]~~ in the startup code only and the toggling did work everywhere else but in the background routine. What is the reason for that? For sure understanding why will not only teach me a new thing but will also prevent many future bugs in backgroung running.
In any case, many thanks again for your help.
Cheers,
Alex
Yuo said
...."just before the outa[noparse][[/noparse]20]~~"
Just before the OUTA YOU have one REAPAT Loop.
You must have DIRA before That in first place.
NEXT ... Look in Yours Start up if that Starts in DIRA in Background COG else if It start DIRA in Main COG.
For corect funktion DIRA must be started in same COG that will Control that OUTA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
Now I get it: the DIRA was obviously started in the main COG, NOT in the new background cog. Stupid me for not thinking of this one! So, of course, toggling would work everywhere BUT in the background cog!
I've re-read about DIRA/OUTA in the manual and I was on the impression that changing DIRA would change the register at propeller level, not just for the current cog. This will obviously have to be taken into consideration in my program...
Thank you very much for putting that directly under my nose, I've learn something today!
Cheers,
Alex
BTW, the heartbeat output is a 1Hz square wave -- that seemed to make the most sense.
Post Edited (JonnyMac) : 7/22/2009 6:46:10 PM GMT