Timing issue
WebheadFred
Posts: 27
I'm having a small issue with a timer. This is a snippet of the code below and the following is happening. Everything is in spin.
When the pll16x is used, the first time through the loop takes 2 seconds and all subsequent times takes a second. If I change to pll2x or lower, it times correctly. What am I missing?
Best regards,
Fred
When the pll16x is used, the first time through the loop takes 2 seconds and all subsequent times takes a second. If I change to pll2x or lower, it times correctly. What am I missing?
Best regards,
Fred
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 . . . . repeat clock := cnt 'Get the current clock for accuracy as the instructions take time to run. load_array(minutes,tens,sec) 'Minutes, Tens, Sec are set from the button COGS send_frame 'Send it.... case sec 'Now we're going to count down. Case statements I thought were the easiest to use. 0: 'Seconds at zero...are we at zero? if (minutes | tens) 'Nope...Sec wraps back to 9 sec := 9 ' case tens 'check Tens.... 0: tens := 5 'Zero?....Tens wrap back to 5 if minutes > 0 'Minutes are decremented if minutes-- 'greater than Zero other: if tens > 0 'and then....tens are decremented... tens-- 'if greater than Zero other: sec-- 'if sec is anything else.....decrement it. waitcnt(clkfreq + clock) 'Wait for the rest of the second to pass..... while (minutes | tens |sec)
Comments
-- this will provide the synchronization you're looking for.
Fred
I have minutes, tens, and sec set by another cog. This other cog simply monitors a button and debounces it. If pushed, minutes, tens, and sec are set. Strange that it all works if the pll is set to 2x or 1x. I'll keep at it till I find out what's happening.
Regards,
Fred
The entire program is posted in the completed projects forum. It's the original iteration of the program so I'm sure the problem would be obvious to the experts. To fix the problem, I essentially placed the case statements loop in a cog of it's own and and the main loop simply displayed the numbers for the digits. It worked as I wanted and the additional benefit was that the user could select the color they wished while the display sat at 0:00 instead of waiting for the count to commence. We're using in my air traffic control tower now and the controllers are pleased with it's ease. Thanks for your input.
Regards,
Fred