-
Notifications
You must be signed in to change notification settings - Fork 239
millis() in the example for Arduino Uno resets after 65535 #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey! I am not entirely certain but this sounds a lot like a miscompilation to me... We'll need to investigate further but the code does not do anything which would induce a 16-bit overflow and we've seen similar issues with If you need a quick and dirty workaround, I think storing two static MILLIS_COUNTER: avr_device::interrupt::Mutex<cell::Cell<(u16, u16)>> =
avr_device::interrupt::Mutex::new(cell::Cell::new((0, 0)));
// ...
let (mut count_upper, mut count_lower) = counter_cell.get();
if count_lower == u16::MAX {
count_lower = 0;
count_upper += 1;
} else {
count_lower += 1;
}
counter_cell.set((count_upper, count_lower)); |
You're right. I checked it out and UPD: I managed to check |
Ref: rust-lang/rust#83281 |
@ThisIsRex are you sure this is a bug with rust and not with ufmt? I've seen issues in the past where ufmt doesn't print |
Similar to what @drmorr0 mentioned, I found that trying to output u32 variables via ufmt would result in an overflow, displaying the time on the Uno (via a 7-segment display) was not affected by the issue with |
@drmorr0 @quantumferret Sorry for delay. I guess, you're right. I wrote a test without ufmt and there was all right. ( |
I tried an example "millis" on Arduino Nano and found out that milliseconds value resets after reaching 65535. But it has a
u32
return type. I tried to modify the prescaler value and timer counts, but it's no use. How to make it use all the bits of u32?The text was updated successfully, but these errors were encountered: