본문 바로가기
HW 프로그래밍/아두이노

아두이노 millis() 함수의 최대치

by N2info 2020. 12. 31.

Maximum number of days for millis()

The count that an unsigned long is capable of holding is: pow(2,32)-1 or 4,294,967,295 or 4 billion 294 million 967 thousand and 295. So if every count is worth a millisecond then how many days is that?

First divide by 1000 for the seconds, then by 60 for the minutes then by 60 for the hours then by 24 for the days = ~ 49.71 days.

After approximately 50 days (or a bit more than 49.71 days) the timer wraps round to zero and this is the Arduino millis overflow problem.

Note: Arduinos may have a resonator (3 pin) instead of a crystal (2 pin) and these are not as accurate as crystals.

If you are designing a project that must time for more than 49 days then this could cause a problem because at the wrap around point, time that was increasing incrementally in milliseconds, suddenly goes to zero. If you recorded a time stamp for a data logging device using millis() after 49.71 days the time stamp would return to the start time i.e. wrong.

 

www.best-microcontroller-projects.com/arduino-millis.html