We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Refer to this app note, page 4. The routine to delay for a while. Rignt or wrong, this while will never end if 65535 - startcount is less than count?(ie..the number of ticks needed for the delay is more than the number the variable can increase before overflowing back to zero)
Refer to this app note, page 4. The routine to delay for a while. Rignt or wrong, this while will never end if 65535 - startcount is less than count?(ie..the number of ticks needed for the delay is more than the number the variable can increase before overflowing back to zero) That's not at all correct. The type of all variables used is unsigned. There are no negative numbers with unsigned types. For example, suppose we want to delay for 100 counts and that the current timer tick is 65530. This means that we need to delay until the timer tick is 95. Now, we all know that 95 - 65530 = -65435 However, you can't represent negative numbers in unsigned types. In an unsigned type 0 - 1 is 65535 (not -1). Actually, it-s 65536 + -1. So, 95 - 65530 is 65536 + -65435 which is 101. And that's correct (since we delay while the different is <= 100 -- 101 is the first number that is > 100). Jon