How millis() resets itself to 0
up vote
8
down vote
favorite
Looking at the documentation for the millis()
function , it says:
Returns the number of milliseconds since the Arduino board began
running the current program. This number will overflow (go back to
zero), after approximately 50 days.
How's this possible? Is Arduino detecting when millis()
overflow then resets the value to 0? If so, how does it do it? I just want to know what exactly is going on under the hood with the variable that is being returned by the millis()
function.
millis
add a comment |
up vote
8
down vote
favorite
Looking at the documentation for the millis()
function , it says:
Returns the number of milliseconds since the Arduino board began
running the current program. This number will overflow (go back to
zero), after approximately 50 days.
How's this possible? Is Arduino detecting when millis()
overflow then resets the value to 0? If so, how does it do it? I just want to know what exactly is going on under the hood with the variable that is being returned by the millis()
function.
millis
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Looking at the documentation for the millis()
function , it says:
Returns the number of milliseconds since the Arduino board began
running the current program. This number will overflow (go back to
zero), after approximately 50 days.
How's this possible? Is Arduino detecting when millis()
overflow then resets the value to 0? If so, how does it do it? I just want to know what exactly is going on under the hood with the variable that is being returned by the millis()
function.
millis
Looking at the documentation for the millis()
function , it says:
Returns the number of milliseconds since the Arduino board began
running the current program. This number will overflow (go back to
zero), after approximately 50 days.
How's this possible? Is Arduino detecting when millis()
overflow then resets the value to 0? If so, how does it do it? I just want to know what exactly is going on under the hood with the variable that is being returned by the millis()
function.
millis
millis
asked 21 hours ago
Programmer
22217
22217
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
17
down vote
accepted
It is not a property of millis(). Every counter with limited number of digits once returns to zeros. For example a 4 digits tally counter returns to zeros after 9999.
Under the hood the variable for millis() is of type unsigned long which is 32 bits on the Arduino. Here the 32 bits are the digits of the tally counter. With only two digits of binary 0 and 1. The maximum is 11111111 11111111 11111111 11111111
. After then it returns to zeros if adding 1. The 32 ones is 2^32 - 1, or 4294967295 in decimal. The maximum value for the counter is then 4294967295 milliseconds. Converted to days you get approximately 49.71 days.
And now, you know how computers work. Thousands of binary tally counters.
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
17
down vote
accepted
It is not a property of millis(). Every counter with limited number of digits once returns to zeros. For example a 4 digits tally counter returns to zeros after 9999.
Under the hood the variable for millis() is of type unsigned long which is 32 bits on the Arduino. Here the 32 bits are the digits of the tally counter. With only two digits of binary 0 and 1. The maximum is 11111111 11111111 11111111 11111111
. After then it returns to zeros if adding 1. The 32 ones is 2^32 - 1, or 4294967295 in decimal. The maximum value for the counter is then 4294967295 milliseconds. Converted to days you get approximately 49.71 days.
And now, you know how computers work. Thousands of binary tally counters.
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
add a comment |
up vote
17
down vote
accepted
It is not a property of millis(). Every counter with limited number of digits once returns to zeros. For example a 4 digits tally counter returns to zeros after 9999.
Under the hood the variable for millis() is of type unsigned long which is 32 bits on the Arduino. Here the 32 bits are the digits of the tally counter. With only two digits of binary 0 and 1. The maximum is 11111111 11111111 11111111 11111111
. After then it returns to zeros if adding 1. The 32 ones is 2^32 - 1, or 4294967295 in decimal. The maximum value for the counter is then 4294967295 milliseconds. Converted to days you get approximately 49.71 days.
And now, you know how computers work. Thousands of binary tally counters.
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
add a comment |
up vote
17
down vote
accepted
up vote
17
down vote
accepted
It is not a property of millis(). Every counter with limited number of digits once returns to zeros. For example a 4 digits tally counter returns to zeros after 9999.
Under the hood the variable for millis() is of type unsigned long which is 32 bits on the Arduino. Here the 32 bits are the digits of the tally counter. With only two digits of binary 0 and 1. The maximum is 11111111 11111111 11111111 11111111
. After then it returns to zeros if adding 1. The 32 ones is 2^32 - 1, or 4294967295 in decimal. The maximum value for the counter is then 4294967295 milliseconds. Converted to days you get approximately 49.71 days.
And now, you know how computers work. Thousands of binary tally counters.
It is not a property of millis(). Every counter with limited number of digits once returns to zeros. For example a 4 digits tally counter returns to zeros after 9999.
Under the hood the variable for millis() is of type unsigned long which is 32 bits on the Arduino. Here the 32 bits are the digits of the tally counter. With only two digits of binary 0 and 1. The maximum is 11111111 11111111 11111111 11111111
. After then it returns to zeros if adding 1. The 32 ones is 2^32 - 1, or 4294967295 in decimal. The maximum value for the counter is then 4294967295 milliseconds. Converted to days you get approximately 49.71 days.
And now, you know how computers work. Thousands of binary tally counters.
edited 18 hours ago
answered 21 hours ago
Juraj
6,0432824
6,0432824
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
add a comment |
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
Old versions of Windows also maintained a milliseconds count in a 32-bit integer, causing lots of software to misbehave after 49 days uptime.
– Russell Borogove
3 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f58164%2fhow-millis-resets-itself-to-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown