Go Down

Topic: "Virtual" Timer Template Sketch (Read 2055 times) previous topic - next topic

Hi.
I'm an industrial control systems integrator. Have been since Noah was playing with toy boats, it seems, and i program PLC's for my bread and butter. Back in the day, i spent many hours programming PC's in C. Other languages too, but C was always my favorite.

One of my clients keeps bending my ear about converting one of his mills to CNC, cheaply of course. I happened on the Arduino with the 3 axis stepper shield and the grbl library, which is about as cheap as it gets. I cut my teeth on CNC systems and that combination simply blew me away.

Anyway, thinking to get up to speed with the Arduino, i thought i'd code a template sketch using a timed interrupt to drive any number of "virtual" timers. I call virtual timers those that are software driven. I used to do this on PC's - taking control of the system timer, and reprogramming it to "tick" every millisecond, instead of 18.2 times per second.

I've attached the sketch. It doesn't do much, in fact it's not connected to the outside world in any way, but it may be useful as a starting point for sketches requiring more timers than the hardware provides. It does count the number of loop() scans per second, which is always useful info, and i have two timers set up for lamp flashing.

Jeff

robtillaart


Maybe you should provide some more example sketches with "real life problems" to show its value ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

WizenedEE

That looks exactly like millis(), except less efficient.

Go Up