CNT Overflow/Wrap-around; What happens?
WildDave
Posts: 2
Forgive me if·this has been documented somewhere else, but what happens if CNT is within say 100_000 ticks of its maximum value (almost ready to wrap around) and·a WAITCNT(3_000_000 + CNT) is issued?· Does the·SPIN interpreter handle the carry/overflow and perform the full wait of 3_000_000 ticks or does it only wait for 100_000 ticks?· Since the counter will wrap almost every minute at full speed, I was wondering if it might be something we need to program around.
All the examples seem to use that syntax (3_000_000 + CNT) with no mention of what might happen if the counter is ready to wrap, and I was just curious if it's handled or if it's something·we need to think about.
Thanks.
All the examples seem to use that syntax (3_000_000 + CNT) with no mention of what might happen if the counter is ready to wrap, and I was just curious if it's handled or if it's something·we need to think about.
Thanks.
Comments
Make sure you use "3_000_000 + CNT" and not "CNT + 3_000_000" to make sure you get the latest value of CNT in your calculation as the expression is evaluated left to right.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Play Defender - Propeller version of the classic game
Prop Room Robotics - my web store for Roomba spare parts in the UK
Take care.
The Propeller has no delay instruction for good reasons, as a "delay" can NEVER be timed precisely without considering the EXACT time for instruction performance.
In most cases a delay is not needed with reference to the time of issueing the wait instruction, but from a quite different basis, either an exit from a former wait, or a CNT caught as soon as possible after a certain external event.
Something like WAITCNT(..CNT...) is always so far away from precise timing that the position of CNT within the expression makes little difference.
Recommended best practices for WAITCNT are:
or
Post Edited (deSilva) : 1/8/2008 1:39:25 AM GMT
-Phil
Getting acquainted to "wrap around arithmetic" also needs some time. My imagination works best when I pretend all numbers are unsigned (so it's the mathematical "modulus" operation you perform). Then, only when using SPIN compare operations I consider the consequences. This last step is not necessary in assembly, as it has unsigned compare instructions as well.
What to do when you want to sync to 1 sec but cannot engage a WAITCNT as you want to do things during that time?
This will - sometimes - not work
The correct code is:
Post Edited (deSilva) : 1/12/2008 12:08:26 PM GMT