Multi-Tasking and Real-Time Operating Systems

Nearly all microcontroller-based systems perform more than one activity. For example, a temperature monitoring system is made up of three tasks that normally repeat after a short delay, namely:

• Task 1 Reads the temperature

• Task 2 Formats the temperature

• Task 3 Displays the temperature

More complex systems may have many complex tasks. In a multi-tasking system, numerous tasks require CPU time, and since there is only one CPU, some form of organization and coordination is needed so each task has the CPU time it needs. In practice, each task takes a very brief amount of time, so it seems as if all the tasks are executing in parallel and simultaneously.

Almost all microcontroller-based systems work in real time. A real-time system is a time responsive system that can respond to its environment in the shortest possible time. Real time does not necessarily mean the microcontroller should operate at high speed. What is important in a real-time system is a fast response time, although high speed can help. For example, a real-time microcontroller-based system with various external switches is expected to respond immediately when a switch is activated or some other event occurs.

A real-time operating system (RTOS) is a piece of code (usually called the kernel) that controls task allocation when the microcontroller is operating in a multi-tasking

environment. RTOS decides, for instance, which task to run next, how to coordinate the task priorities, and how to pass data and messages among tasks.

This chapter explores the basic principles of multi-tasking embedded systems and gives examples of an RTOS used in simple projects. Multi-tasking code and RTOS are complex and wide topics, and this chapter describes the concepts pertaining to these tools only briefly. Interested readers should refer to the many books and papers available on operating systems, multi-tasking systems, and RTOS.

There are several commercially available RTOS systems for PIC microcontrollers.

At the time of writing, mikroC language did not provide a built-in RTOS. Two popular high-level RTOS systems for PIC microcontrollers are Salvo (www.pumpkin.com), which can be used from a Hi-Tech PIC C compiler, and the CCS (Customer Computer Services) built-in RTOS system. In this chapter, the example RTOS projects are based on the CCS (www.ccsinfo.com) compiler, one of the popular PIC C compilers developed for the PIC16 and PIC18 series of microcontrollers.

Leave a comment

Your email address will not be published. Required fields are marked *