|Shopping Cart Checkout Shipping Cost Download Website|
|You are here: Teensy Teensyduino Libraries MsTimer2|
MsTimer2 and FlexiTimer2 LibrariesMsTimer2, by Javier Valencia, lets you periodically run a function, by a configurable number of milliseconds.
FlexiTimer2 is version of MsTimer2 by Wim Leers, which makes the interval resolution configurable, rather than being fixed at 1 millisecond steps
Hardware RequirementsTODO: table showing pins unusable as PWM: Teensy 2.0: 10 and 12. Teensy++ 2.0: 1 and 24.
MsTimer2 & FlexiTimer2 work on Teensy LC & 3.0 - 3.6. Internally, IntervalTimer is used these 32 bit boards. For new projects, direct use of IntervalTimer is recommended.
Basic UsageTODO: write this
Example ProgramTODO: add this
Interrupt Context IssuesMsTimer2 and FlexiTimer2 will call your function from interrupt context. Because it will interrupt your program at any moment, special design is necessary to share data with the rest of your program.
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume variable can not spontaneously change. Because your function may change variables while your program is using them, the compiler needs this hint. But volatile alone is often not enough.
When accessing shared variables, usually interrupts must be disabled. Even with volatile, if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly. If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled for the entire sequence of your code which accesses the data.
TODO: an example.
DetailsThe original version of these libraries are at: