Range of mills() on ATTiny1616? #1072
-
I am using mills() to do some timing on this chip using megaTinyCore and I have a weird bug where if I try add more than 30 seconds to my time
If I do a test:
I get an error on compile:
Which smells to me like I am stepping on an integer overflow in the first example... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If you don't want the warning change
to
|
Beta Was this translation helpful? Give feedback.
-
Strictly speaking, it's a warning, not an error, but the root cause is that it's treating the "60" and "1000" as ints (16-bit signed) and deciding that there's a risk of overflow. I'm not guru enough to know if the code it generates is correct. There's a voice inside me that's paranoid about order of operations (and readability to some extent), so I'd pretty much always do "millisNow + ( 60 * 1000L)" :-) |
Beta Was this translation helpful? Give feedback.
Strictly speaking, it's a warning, not an error, but the root cause is that it's treating the "60" and "1000" as ints (16-bit signed) and deciding that there's a risk of overflow. I'm not guru enough to know if the code it generates is correct.
There's a voice inside me that's paranoid about order of operations (and readability to some extent), so I'd pretty much always do "millisNow + ( 60 * 1000L)" :-)