millis() Timer, Long Integers and Overflow

This forum is for all topics related to Simulator for Arduino v0.98. Please include sample code where possible.

Moderator: Adrian

mikeworkman
Master Class
Posts: 10
Joined: Tue Apr 16, 2013 2:27 am

millis() Timer, Long Integers and Overflow

Postby mikeworkman » Sun Apr 21, 2013 1:44 am

Hi Guys -

I have a piece of code that calculates a few timers from events.

The variables are all unsigned long.

like

unsigned long Timer_1;
unsigned long Timer_1_Start_point = 0;
.
.
.
Timer_1 = millis() - Timer_1_Start_point ;

If I run it for a day - I get an error indicating a timer is negative -2,1xx,xxx - in other words something well short of where a legit overflow should have happened with a 32 bit number, and the variable is displayed in the simulator error box as a negative number which also seems odd given that the thing is declared as an unsigned long integer.

Finally - at this point I noticed the MOST ODD thing: millis is displayed in the simulator (top line) as a negative number... :roll:

Any ideas or is this a known bug?

Mike

User avatar
Adrian
Super user
Posts: 56
Joined: Thu Jan 10, 2013 10:22 pm

Re: millis() Timer, Long Integers and Overflow

Postby Adrian » Fri May 03, 2013 10:46 pm

Hi Mike,

This does sound odd, thanks for describing this - not many code fragments get tested over such long periods. I think that this is best left to the developers, I would hazard a guess that it may have something to do with your OS (settings) and so an unexpected program path (bug).
I can't say that I've seen this exact problem although I did report an issue that revolved around long & millis(), but that was resolved.

Can I ask you to post an example sketch please?

Regards
Adrian
Apologies for being opinionated - it's nothing personal, feel free to complain.
usual system: Pro V0.98 Arduino Mega 2560 Samsung i5-3210M 2.5Ghz 6GB windows home premium SP1


Return to “Version 0.98”

Who is online

Users browsing this forum: Google [Bot] and 1 guest