waitcnt problem
MinimumWage
Posts: 72
Hi all,
I'm hoping someone can help me with this. I am trying to run the program below but am getting unusual results with the waitcnt statement in the BeatCount subroutine. I stripped it down from another program for troubleshooting - all it does is pass a shared value between cogs. No matter what value I use in that waitcnt statement the cog gets stuck for almost a minute before updating the beatavg value. I'm sure that indicates that the cog is waiting for the system counter to roll over, but I don't understand why. I've never had a problem like this with a simple waitcnt statement and feel like I must be missing something obvious...
Basically, when I run this code as-is the LED flash frequency doesn't get set to 1/10 sec for almost a minute. If I comment out the first waitcnt statement, it updates instantly.
Post Edited (MinimumWage) : 1/26/2008 8:23:05 AM GMT
I'm hoping someone can help me with this. I am trying to run the program below but am getting unusual results with the waitcnt statement in the BeatCount subroutine. I stripped it down from another program for troubleshooting - all it does is pass a shared value between cogs. No matter what value I use in that waitcnt statement the cog gets stuck for almost a minute before updating the beatavg value. I'm sure that indicates that the cog is waiting for the system counter to roll over, but I don't understand why. I've never had a problem like this with a simple waitcnt statement and feel like I must be missing something obvious...
CON _clkmode = xtal1 + pll8x 'set for SPINSTAMP!! _xinfreq = 10_000_000 b_out1 = 1 VAR long stack1[noparse][[/noparse]50] long stack2[noparse][[/noparse]50] long beatavg PUB Main cognew(BeatCount, @stack1) cognew(FlashLED, @stack2) PUB BeatCount waitcnt(clkfreq + cnt) beatavg := clkfreq/10 PUB FlashLED dira[noparse][[/noparse]b_out1]~~ repeat while true outa[noparse][[/noparse]b_out1] := !outa[noparse][[/noparse]b_out1] waitcnt(beatavg + cnt)
Basically, when I run this code as-is the LED flash frequency doesn't get set to 1/10 sec for almost a minute. If I comment out the first waitcnt statement, it updates instantly.
Post Edited (MinimumWage) : 1/26/2008 8:23:05 AM GMT
Comments
Graham
IMHO the problem is that the BeatCount Cog and the FlashLED Cog are startet immediate consecutively without waiting for the BeatCount has finished. So the beatavg value is zero for the first waitcnt in the loop, and thats why you have to wait 54 seconds.
Andy
Quite right! It is essentially waiting for cnt which will have passed by the time it starts waiting.
Graham
Thanks for the replies. I had thought something along those lines might be the case, so I tried running the code with beatavg explicitly init'ed to 0, and then changing the loop to "repeat while beatavg <> 0". With that change the LED never flashes (even after waiting a minute). I would expect it to update the variable after a second and start flashing, right? Am I still missing something?
Graham
Thanks - that's what I realized I could do after re-reading the posts. I was spending too much time thinking about what would happen after the variable had been set, not what was happening before it was initalized. Thanks again!
Mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
Post Edited (Dgswaner) : 1/27/2008 8:59:25 AM GMT