Shop OBEX P1 Docs P2 Docs Learn Events
Noob cnt question — Parallax Forums

Noob cnt question

BenjBenj Posts: 66
edited 2008-11-06 15:54 in Propeller 1
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:

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

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-06 15:01
    1) You've declared your variables as "word" when they should be "long". "word" is 16 bits while "long" is 32 bits. Neither TimeBase nor OneSec can hold the values they're supposed to hold.

    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.
  • BenjBenj Posts: 66
    edited 2008-11-06 15:32
    Thank you, I thought it might be something like that. The example in the manual does not show the variable being declared.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-11-06 15:54
    That is because it is not an example of everything only a specific thing.
Sign In or Register to comment.