I found this issue, and I noticed that in this code the delayMicroseconds() function uses micros(). On an arduino UNO (ATmega328), can the delayMicroseconds() function suffer any effect every 70 minutes?
The overflow ‘problem’ is simply that an unsigned long (32 bit integer) can’t hold any more than ~4.2 billion ticks
(11111111 11111111 11111111 11111111)…
When that number overflows, the count ‘rolls over’ to begin from zero again…
(00000000 00000000 00000000 00000000)
Both millis() and micros() suffer the same issue when the counter overflows, as would any other numerical counter with any data type.
Yes, the explanation about the overflow is understandable.
The question is about the delayMicroseconds() function. I don't want to be susceptible to a time variation every 70 minutes, so I made an improvised timer using while() instead of using delayMicroseconds().
Interesting that before I was using a 16-bit variable with the delayMicroseconds() function, and the maximum time I was needing was 50ms, so the value of the 16-bit variable was getting close to 50000.
But using a 16-bit variable and while() every millisecond needed more than 2000 counts so overflow would occur (50x2000=100000), but when using a 32 bit variable, the value of every millisecond dropped to about 500 counts.
In the future, whoever reads this code without knowing the differences in processing time of the variables in relation to the length of the variable, may think that it was unnecessary to use a 32-bit variable to operate with a count with a maximum value of only 25000.
I had seen this information, but I tried it with 50ms and apparently had no problem. I don't know if the current code is capable of operating with the full 32 bits, and only the documentation is out of date. But there is a caveat in the documentation: