using NANO and 3.3.9, I got legacy code in 2.x from my colleague. I ported the project into 3.x. when I try use the stopwatch, the elapsed time always return as 0. When I comment out the HiResTimer Init function, the stopwatch work properly.
Instead of porting from 2.x, have you tried the example in 3.x: \nburn\examples\timers\Stopwatch?
Can you try that and let us know if the example works properly?
yes it did. In fact, the example is what I start with the stopwatch. However like in my test project, if I have the follow two lines of code incorporated into the example, the stopwatch will return 0 elapsed time.
#include <HiResTimer.h>
...
HiResTimer *hrt = HiResTimer::getHiResTimer(0);
hrt->init(); // thise cause stopwatch return 0 elapsed time
I test it out, it still return as 0. The stopwatch only works when I specify the parameter to 1 or greater.
I don't use the HiResTimer at all, it inherits from my coworker's 2.x source code. I can specify it to 1, and my code still runs.
It's just something alert me that I need to fix.
The stopwatch and hirestimer use the same set of timers.
DEFAULT_TIMER is supposed to make the code choose an unused timer.
(Not sure why it isn't I'll look at that on Wedensday)
Your fix Putting a 1 in also works as it seems the stopwatch is using timer 0, so hires uses timer 1. ....
Please confirm you are using HiResTimer and Stopwatch from the 3.0 ,library code and not code pulled in from the port?
So I verified this is broken in the current release....
The short answer:
You should not be using HiResTimer. in 3.X apps.
You should using
HiResDelay.h //For microsecond precise delays.
IntervalTimer.h //For repeat timers from 2 to 50Khz.
StopWatch.h //For precise time measuremnts.
Long answer:
HiResTimer is a direct transplant from 2.x to 3.x it ONLY works with the coldfire platforms..... MOD5441X, NANO, SB800EX.
It DOES NOT WORK with the arm M7 parts, will not be supported in any future platform(s).
The three timer headers/functions listed above are supported on ALL 3.x platforms, and will be supported for all future 3.X hardware.
(We have a couple new platforms in Alpha/early Beta.)
If you use these functions your code is guaranteed to be more portable to new platforms.
If you want help porting a 2.X app that used HiResTimer to 3.X please submit a support request...