![]() |
|||||||||||||||||
![]() |
|
Custom Search
Readers
comments
|
|||||||||||||||
Multitasking for PIC microsSponsored Links...
Every time you turn on your computer it is multitasking and all the tasks that the PC performs are done using one instruction at a time. Multitasking simply means switching attention from one task to another to make it appear that many tasks are happening all at the same time.To make it work in a PC the task manager shares out the processing time between each task giving it a set amount of time and then moving on to the next task. The key to its operation is the speed of the processor - the faster it is the more tasks it can handle and the more complex they can be. For really difficult tasks a separate processor may be involved e.g. a graphics processor or a floating point co-processor (built into Pentium chips now). You can use the same idea for a PIC microcontroller but since it is not going at GHz speeds you have to carefully decide what tasks you need to do and how to make it work distributing a fair share of processing time to each task (or peripheral). RTOSAn RTOS (Real Time Operating System) is the ultimate multitasking system and it makes writing code easier using flag signals for inter-process communication and provides prioritized task scheduling.The penalty for using an RTOS is that it takes up code space and RAM resource (and there is a learning curve as there are a lot of details for RTOS control and task switching). Sponsored Links...
On the web you can find RTOS code for PIC micros but this is probably more appropriate for the larger 18F series micros as RTOS's tend to require larger RAM and program resources (Ram is used to save all the current task data between task switching) so you won't fit many tasks into a mid-range PIC micro. Simple Multiple task schedulingYou can make a simple multiple task scheduler using interrupts and careful coding and it won't need a huge amount of memory or resources.The advantage of this method is that you have full control over the code generated and can therefore fit it into tiny devices. The disadvantage is that you have to be completely on top of how your code is working. With an RTOS time slices are assigned to each task giving them a fair share of processing time. With this method you need to decide how tasks are assigned processor time as you design the code. All you do is place all your code in an loop and use variables within the loop to test the conditions you need e.g polling an input. Each test section is more or less equivalent to a task in an RTOS. InterruptsAs with any multitasking system the heart of a task scheduler is the main timer that can assign time slices to each process. For this method a timer interrupt e.g. Timer 0 operating every n milliseconds calls subordinate functions that require the highest priority. Everything else is a low priority task that gets interrupted by the highest priority task.When you use this multitasking method you have to balance the processing time of the interrupt routine against the processing needed by subordinate tasks so that enough time is spent doing the subordinate tasks. All this really means is make the ISR (Interrupt Service Routine) as short as possible and as infrequent as possible. You can find more information from the website here. Copyright © John Main 2006 Free to distribute if the article is kept complete. http://www.best-microcontroller-projects.com Sponsored Links...
Jump from multitasking page to Best-Microcontroller-Projects Home Page |
|||||||||||||||||
|
|
|||||||||||||||||
|
|||||||||||||||||