9 years, 7 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

9 years, 7 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.

Accepted Answer

Thanks.Just noticed what seemed to be an anomoly. I thought the documentation was autogenerated - but as that is the way it is, perhaps it should be documented. I'm using the float, which of course uses the int.

posted by neil hancock 20 Aug 2014