Shop OBEX P1 Docs P2 Docs Learn Events
Question about the CNT — Parallax Forums

Question about the CNT

krazyideaskrazyideas Posts: 119
edited 2008-11-15 15:27 in Propeller 1
Hello

I am just wondering about the system counter and how it works.

It is my understanding that it counts to 4 billion and the starts back at zero again.· If that is the·case of how it works, that means that everytime that you do a waitcnt command that includes a base time that such as

var
long time

PUB count

time := cnt
· repeat
··· waitcnt (time += 50_000)
··· !outa[noparse][[/noparse]0]

You would have a major glitch in the program, because the counter would eventually reach 4 billion along with the base time. In which case the base time would eventualy become equal to·4 billion + 50_000 and the program would never toggle again because the counter will never reach that number of 4 billion + 50_000.
Which means at 80MHz the program would only operate correctly for 53 seconds before failer.· Is this True???
Or would the base time roll over back to zero as well. Adding the surplus over 4 billion to zero makeing up the difference?
Meaning that 4 billion + 50_000 = 50_000 for both the counter and the base time???
How does that work?

Any thoughts would be great
Thanks

Comments

  • T ChapT Chap Posts: 4,223
    edited 2008-11-15 03:30
    I am not really sure what you are asking, but I think I recall the one time I sent the cnt to an LCD it ran -2B to 2b, not 0 to 4B.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-15 05:03
    All arithmetic on the Propeller is 32 bit, so adding 50_000 to a 32 bit number wraps around in exactly the same way that the hardware adds 1 to CNT for 50,000 system clocks.
  • krazyideaskrazyideas Posts: 119
    edited 2008-11-15 15:27
    Thanks Mike that was what I needed to know
    Take care all

    Krazyideas
Sign In or Register to comment.