Multitasking for PIC Micros

Every time you turn on your computer it is multitaskingwon't fit many tasks into a mid-range PIC micro.
and all the tasks that the PC performs are done usingSimple Multiple task scheduling
one instruction at a time.You can make a simple multiple task scheduler using
Multitasking simply means switching attention from oneinterrupts and careful coding and it won't need a huge
task to another to make it appear that many tasksamount of memory or resources.
are happening all at the same time.The advantage of this method is that you have full
To make it work in a PC the task manager shares outcontrol over the code generated and can therefore fit
the processing time between each task giving it a setit into tiny devices.
amount of time and then moving on to the next task.The disadvantage is that you have to be completely
The key to its operation is the speed of the processoron top of how your code is working. With an RTOS
- the faster it is the more tasks it can handle and thetime slices are assigned to each task giving them a fair
more complex they can be. For really difficult tasks ashare of processing time. With this method you need
separate processor may be involved e.g. a graphicsto decide how tasks are assigned processor time as
processor or a floating point co-processor (built intoyou design the code.
Pentium chips now).All you do is place all your code in an loop and use
You can use the same idea for a PIC microcontrollervariables within the loop to test the conditions you
but since it is not going at GHz speeds you have toneed e.g polling an input. Each test section is more or
carefully decide what tasks you need to do and howless equivalent to a task in an RTOS.
to make it work distributing a fair share of processingInterrupts
time to each task (or peripheral).As with any multitasking system the heart of a task
RTOSscheduler is the main timer that can assign time slices
An RTOS (Real Time Operating System) is theto each process. For this method a timer interrupt e.g.
ultimate multitasking system and it makes writing codeTimer 0 operating every n milliseconds calls
easier using flag signals for inter-processsubordinate functions that require the highest priority.
communication and provides prioritized task scheduling.Everything else is a low priority task that gets
The penalty for using an RTOS is that it takes upinterrupted by the highest priority task.
code space and RAM resource (and there is aWhen you use this multitasking method you have to
learning curve as there are a lot of details for RTOSbalance the processing time of the interrupt routine
control and task switching).against the processing needed by subordinate tasks
On the web you can find RTOS code for PIC microsso that enough time is spent doing the subordinate
but this is probably more appropriate for the larger 18Ftasks. All this really means is make the ISR (Interrupt
series micros as RTOS's tend to require larger RAMService Routine) as short as possible and as
and program resources (Ram is used to save all theinfrequent as possible.
current task data between task switching) so youYou can find more information from the website here.