WebheadFred
11-11-2010, 01:25 PM
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
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)
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)