Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 months ago.
Timer.read() gives -ve output
While running a demo program <analog.in KL25Z> with timer.read() the times goes negative.
I don't expect negative time (expect in a Dr Who tardis.), the very most I would expect is it to wrap to 0
Seems like there is a timer cast issue. Can't see how to post a bug report so posting it here
<<code title=timer.h>>
Timer tmrE_sec; Elapsed
float time_[BuffSize];
periodically:
time_[lp2i]=tmrE_sec.read();
pc.printf("%12.3f ....\n\r",time_[lp2i],);
Time output
2142.140 2143.141 2144.142 2145.143 2146.144 2147.145 -2146.821 -2145.820 -2144.819 -2143.818 -2142.817 -2141.816 -2140.815 -2139.814 -2138.813 -2137.812 <</code title>>
Full program here https://mbed.org/compiler/#nav:/kl25z_AdcReadSendData/main.cpp;
1 Answer
10 years, 3 months ago.
This corresponds with the documentation, it returns a signed integer. And I remember an old question where it was stated that there was a reason to use a signed instead of an unsigned integer. You can probably cast it yourself back to unsigned integer, but in general for sure for very long times the Timer isn't intended anymore, but instead the RTC should be used.