Uncategorized

How to use the Arduino Timer Interrupt

https://github.com/MarginallyClever/ArduinoTimerInterrupt has what you need on github. Call a single function to set the timer interrupt frequency, in hertz. The INO file also includes a test suite in the loop() method that will set many different frequencies. Each time the counter is called it will blink a light. Replace that with whatever non-blocking code you want. (That means calling Serial.print is a bad idea.)

Now that I’ve got this timer working correctly I’m going to reuse it in many places, starting with CNC machines – I can use the timer to move the motors while the main thread is still receiving instructions and queueing them into the system. That means no “hiccup” between steps. It also means the machine can “look ahead” several steps and plan speeds better.