chicken 630 Posted May 29, 2013 Share Posted May 29, 2013 Hmmm, this test sketch // Testing fixed millis, micros and delay functions void setup() { Serial.begin(9600); Serial.print("us resolution measured="); unsigned long us = micros(); unsigned long us2 = micros(); while(us2==us) us2 = micros(); Serial.println(us2-us); } void loop() { unsigned long ms = millis(); unsigned long us = micros(); Serial.print(ms / 1000 / 60 / 60); Serial.print(":"); Serial.print(ms / 1000 / 60 % 60); Serial.print(":"); Serial.print(ms / 1000 % 60); Serial.print("\tmillis()="); Serial.print(ms); Serial.print("\tmicros()="); Serial.println(us); unsigned long now; do { now = millis(); } while(now - ms < 1000); if(now < ms) Serial.println("Overflow!"); } with the "<b>volatile unsigned long wdt_millis = 0xffff0000;</b>" hack gives me this output (about 1 minute in) 1193:2:44 millis()=4294964822 micros()=63062016 1193:2:45 millis()=4294965822 micros()=64062016 1193:2:46 millis()=4294966822 micros()=65062016 Overflow! 0:0:0 millis()=526 micros()=66062080 0:0:1 millis()=1526 micros()=67062016 make sure to work with unsigned long or uint64_t when handling milliseconds to avoid unintended truncation of values. Quote Link to post Share on other sites
chicken 630 Posted May 29, 2013 Share Posted May 29, 2013 uint32_t that is.. got a bit carried away for a moment Quote Link to post Share on other sites
Vad33 0 Posted June 3, 2013 Share Posted June 3, 2013 Hi ! Sorry, I am a beginner. I am testing launchpad stellaris (EK-LM4F120XL). Energia version 0101E0009 void setup() { Serial.begin(9600); } void loop() { Serial.print("Time = "); Serial.println(millis()/1000); delay(1000); } Result: ... Time = 49 Time = 50Time = 51Time = 52Time = 53Time = 0Time = 1Time = 2Time = 3 ... Overflow on 54 ?. ?? What do I do wrong? Quote Link to post Share on other sites
chicken 630 Posted June 4, 2013 Share Posted June 4, 2013 I see the same behavior with the official 0101E0009 build and the Stellaris Launchpad. Looks like there was a major overhaul of wiring.c since then that might fix the issue. Unfortunately I couldn't get the newer version to work for me. Grabbing wiring.c alone seems to completely screw timing (i.e. Serial doesn't work anymore), and grabbing larger parts of the hardware folder causes compile errors about a missing syscalls.h. PS: You might have more luck getting an answer over on Stellarisiti http://forum.stellarisiti.com/ Vad33 1 Quote Link to post Share on other sites
Vad33 0 Posted June 4, 2013 Share Posted June 4, 2013 PS: You might have more luck getting an answer over on Stellarisiti http://forum.stellarisiti.com/ Thanks. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.