ferdinandkeil.com

Simple Task Scheduler for Microcontrollers

with 4 comments

For a project I’m currently working on I need to write a (at least for me) fairly complex firmware. The code I used in the last version of this circuit grew out of a test program and became unmaintainable. So I looked around for some inspiration and found Alan Burlison’s Arduino task manager. It’s a great piece of code, so I wanted to give it a try. One problem remained: his code is for the Arduino, but I use plain C with avr-gcc. So I adapted his code for my use.
While trying to convert his code to C I found one flaw. His implementation of timed tasks doesn’t handle timer roll-overs gracefully. As my circuit is supposed to run for months without reset, that was out of the question. Finally I found a solution by Bombastic Bob on Arduino Playground.
Now it works like a charm. I attached my code, you are free to use it for your projects. The included example is for an ATmega168 with a 12MHz crystal and an LED on PD6. But I see no reason why this code can’t be used with other micro-controllers as well.

TaskScheduler.zip

Written by Ferdinand

November 3rd, 2012 at 16:19

Posted in Elektronik

Tagged with , , , , ,

4 Responses to 'Simple Task Scheduler for Microcontrollers'

Subscribe to comments with RSS or TrackBack to 'Simple Task Scheduler for Microcontrollers'.

  1. Hi Ferdinand,
    I wrote my own version that allows me to enable/disable a task and run a task out of sync.

    http://www.riunx.com/~meirm/taskschedulertest.zip

    meirm

    21 Jan 13 at 23:34

  2. That’s a nice piece of code 🙂 Glad to be of assistance.

    ferdinand

    22 Jan 13 at 11:57

  3. I added more samples. sample 11, shows how many interactions runs the scheduler in one second:

    number of interactions: 17271904

    meirm

    22 Jan 13 at 17:45

  4. That number looks unlikely high to me. When you run your micro at 20 MHz and have 17 million interactions per seconds, each interaction takes only 1,17 instructions!

    ferdinand

    30 Jan 13 at 10:41

Leave a Reply