4Alex
07-22-2009, 09:54 PM
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:
PRI updateTimer
'' Updates timer registers
'' -- start method launches this method into separate cog
repeat ' run until cog unloaded
if running ' if timer enabled
outa[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
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[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