Software vs Hardware Timers

So I’m learning about timers so I can call a function every 18 seconds to push data into an Array.

I see there are Software Timers built into the Particle OS which from what I can tell are very easy to use if you don’t need timer accuracy of less than 1 Millisecond.

Then I see the famous SparkInteveralTimer library that is a Hardware Timer based on Interrupts.

It looks like the SparkInterveralTimer library could be used for any timing need while the Software Timer is good for anything less than 1 Millisecond accuracy.

I’m using System Threaded mode so I’m not sure if that has any effect on either of these methods or not.

For the simple job of pushing a few variables into Array slots every 18 seconds, it sounds like the software timer would be just fine, but I wanted to ask the Pro’s on here if there is more to consider between the two different timing options?

@RWB, Software Timers are run from a single thread and are perfect for simple, non-blocking code much like an ISR. They are simple to use and offer different modes like one-shot timing.

SparkIntervalTimer was designed to provide timer based interrupts down to sub 10 microseconds. HOWEVER, because these code you provide runs in an ISR, they must be kept short, non-blocking and care must be taken with the call-depth when calling other functions. I used the SparkIntervalTimer library to drive the RGBMatrixPanel library with 50uS interrupts. Often, I will use it in place of Arduino’s Timer1 hardware timer library when porting code.

Software timers are likely to fit the bill for most timing applications. Timer interrupts can be used were accuracy is needed and where you a FreeRTOS-independent timing operation is needed. Writing good ISRs, however, is not for novices.