Noob cnt question
Benj
Posts: 66
I have been trying to figure out how to effectively use cnt and have had some success but am running into a sticking point. My code:
I think the above code should print out "total" every second, but it does not do that. Instead it prints out "total" about every 54 seconds. Instead of it waiting for cnt+80_000_000, it seems to cycle all the way around until it again reaches that value for cnt. I did some more testing to see that cnt takes about 54 seconds to go from 0, back around to 0. What am I doing wrong?
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ text : "vga_text" VAR word total word OneSec word TimeBase PUB Start OneSec := clkfreq TimeBase := cnt repeat waitcnt(TimeBase += OneSec) total += 1 text.dec(total)
I think the above code should print out "total" every second, but it does not do that. Instead it prints out "total" about every 54 seconds. Instead of it waiting for cnt+80_000_000, it seems to cycle all the way around until it again reaches that value for cnt. I did some more testing to see that cnt takes about 54 seconds to go from 0, back around to 0. What am I doing wrong?
Comments
2) 54 seconds is approximately 2^32 clock "ticks" at 80MHz. That should always give you a hint that you've got a problem with a waitcnt.