multitasking with arduino

I need to implement a very simple operating system for arduino, and, obviously, it has to be multitasking capable. I wonder if anyone here has done something similar, has tips/tricks etc for me.



The blink without delay example and the Metro library both provide some examples of how you can manage multiple events on different schedules without delaying. You can also use the attachInterrupt() function for some asynchronous events. None of which is proper multi-tasking, but it might help.

Actually I want to implement a round-robin similar scheduler scheme, that is, attatch to each process a fixed time slot to execute - let's say, 10 ms. Thus, the scheduler should be able switch among processes every 10ms, "pausing" the execution of non-working processes. In simpler words, my processes will be c functions and all I want is to be able to start a function execution, pause it when needed and resume its execution. I don't know how to implement on arduino this.

A true preemptive multitasking OS is a lot harder than you need to do to get "useful" multitasking. Run-to-completion "cooperative" multitasking even has some advantages. However, implementing something like this on an arduino is going to be pretty difficult, since most schedulers tend to be quite RAM-intensive (a stack per process plus a stack for the scheduler plus ram to describe the processes themselves...) It doesn't take long to use up 1k. (for instance, there is, which does run on AVRs. It needs 236 bytes ram for the scheduler, 76+ bytes for each "queue", and 64 bytes + stack for each task.

I completely agree with westfw, cooperative multitasking is much more resource friendly in the relatively limited arduino environment. But an approach I think works best with limited resources is a Finite State Machine for driving your functions. If you are not familiar with the State Machine construct, here is an article that provides an overview.

And here is a free eval tool. Its limited to 20 states and I haven't tried it but it could be a help for your app.

I am curious to know what you are wanting to build.

ok, you're right. There's too little ram on arduino. I'll try a state machine.

Hi, we have ported FreeRTOS past year (2009), you can look at these links:

The versión 0.1 Alpha (for the 0017 IDE) is available here:

And there is a v0.2 Alpha which runs in 0018 at:

We did not make the v0.2, but are working in the v0.3.

Regards, Julián Back to top