Teensy Timer Tricks #34
Replies: 2 comments
-
|
This is good to know. I remember some place having to worry about rollover. 73, Steve |
Beta Was this translation helpful? Give feedback.
-
|
What I am looking for is a function call that will execute a given function at some later time, without taking care of that. So, if the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The Teensy has two nifty timing classes named
elapsedMillisandelapsedMicros. The classes are used to count milliseconds or microseconds. The implementation is a wrapper around auint32_twhich stores the 'epoch' we are counting from. The only overhead is a call tomillis()ormicros()when you reference the timer. They're nifty because they spare you worrying about those times whenmicros()andmillis()roll over from0xffffffffto0You can also set a negative count and fire at the zero crossing, but you need to cast the timer to a signed value when you read it.
The documentation is https://www.pjrc.com/teensy/td_timing_elaspedMillis.html
The C++ source the next version of hasak uses for an
elapsedSamplesclass is a straightforward hack onelapsedMillis.I can see how to write a C preprocessor macro to generate these for arbitrary name and counter function. But it seems there should be a C++ template class definition that takes a class name and a static counter function and generates elapsedAnyCounter's.
Beta Was this translation helpful? Give feedback.
All reactions