Time delay & CNT roll over ??
twm47099
Posts: 867
I'm trying to learn Spin, and have a question about the WAITCNT command.
According to the Prop Manual states that at 80MHz clock, it takes about 53 seconds for the System Counter to wrap around.
If I wrote:
delay := clkfreq * 30
waitcnt(delay + cnt)
The cog should wait for 30 seconds. But that would also result in a high probability that cnt would roll over to 0, and the wait would not be satisfied. Using smaller delays would have a smaller but finite probability of having that occur.
Is that correct? What am mixing up? How does this work, and is there a way to specify long deterministic delays?
Thanks
Tom
According to the Prop Manual states that at 80MHz clock, it takes about 53 seconds for the System Counter to wrap around.
If I wrote:
delay := clkfreq * 30
waitcnt(delay + cnt)
The cog should wait for 30 seconds. But that would also result in a high probability that cnt would roll over to 0, and the wait would not be satisfied. Using smaller delays would have a smaller but finite probability of having that occur.
Is that correct? What am mixing up? How does this work, and is there a way to specify long deterministic delays?
Thanks
Tom
Comments
-Phil
Andy
If you take a look at your actual code, you retrieve the value of CNT and add it too your DELAY to make up a target.
Since that is all in 32 bit binary math in the actual machine, the addition compensates for the CNT roll over at Zero if and only if your total delay is less than the 53 seconds.
The 53 seconds limit is bases on going higher than what CNT originally read. That is a second and importantly different roll over.
The 53 second is roughly based on 80Mhz clock being very near to the where you pass the same value that you got in CNT.