![]() ![]() But again, this is only applicable if the "jitter" really happens. ![]() Our solution is casting the systick slsleeptimergettickcount () to milliseconds with function: slsleeptimerticktoms. The millis () function in the Arduino environment will overflow for almost 49 days. If it refers to the fact that the next returned millis() value may sometimes be slightly smaller than the previous one, then function #1 is unacceptable because it will generate huge numbers (99-100 will fully overflow it) and regularly break the logic. Subtraction of the actual value from the previous timestamp in the case of unsigned integers is handling the overflowing of the counters. This condition won't be triggered on overflow and will wait for the timer to run until the delay really reaches 2 seconds.īut here's the thing: I've heard that the millis() value may jitter, this term is mentioned on Arduino forums, but I'm not really sure what it refers to. In a regular overflow scenario, first function will give a sanely small number because both operands are UL, so the result will be calculated in UL as well, and on millis() overflow the function result will overflow as well and return a relatively regular number.The second one will subtract the bigger number (on overflow that will be t2) from the smaller number (on overflow that will be millis()) and return a huge num.So in this case, function #1 seems like a better choice because it will not break the logic on overflow, like if there's a condition if (tFrom(lastBlink) > 2000) I have two variants: unsigned long tFrom(unsigned long t2) I'm making a universal function to count the time passed between a previous timestamp and current millis().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |