Pages: [1]   Go Down
Author Topic: Mircos() returning a negative number?  (Read 231 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have read the reference page and believe i have understood how the micros() function works, it calculates the time since the program has been running. However it seems to be returning a negative value for me. i have a Serial.println() functions in my code that prints the word time1, time2 or time3 along with their respective values underneath the word. The serial monitor is giving me negative values however. Why might this be caused?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why might this be caused?

You're assigning the value to a signed variable instead of an unsigned one.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16497
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And did you define time1, time2, and time3 as unsigned long variables?

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow i am hitting myself so hard right now. That was totally it. i had them signed to integers (int) not unsinged long. Ugh that has been upsetting me for so long now. Thank you so much. That works perfect!
Logged

Pages: [1]   Go Up
Jump to: