Design Article

The basics of embedded multitasking on a PIC, part 2

Gamal Ali Labib

12/12/2007 12:22 AM EST

Working with Microchip's PIC18F452, the author demonstrates how you can pack the programs of tasks that have exactly the same functionality but in different domains into one reentrant program that can be invoked several times concurrently to serve all those domains.

Part 1: The basics of embedded multitasking on a PIC--Introduction
Part 3: The basics of embedded multitasking on a PIC--Preemptive multitasking

Cooperative multitasking requires concurrently running tasks to willingly give up system control throughout their execution to a scheduler program so that the latter can switch the control to the task that meets the preset policy. When tasks have exactly the same functionality but in different domains, it is presumably possible to pack all tasks' programs into one reentrant program that can be invoked several times concurrently to serve all those domains. This article describes a project that illustrates this kind of multitasking with some useful pieces of code you can reuse in your own control projects.

Working with PIC18F452
The Microchip's PIC18F452 is a high-performance enhanced flash microcontroller with 10-bit A/D, four I/O ports, on-chip 32KB program memory, 1,538-byte data memory, 256-byte EEPROM, 18 interrupt sources, four timers, and 75 instruction sets. I chose this device for my project as it represents the high-end of the popular PIC18Fxx2 family and realizes the fundamental architecture of Microchip's MCUs. Both factors indicate that multitasking can look appealing for applications based on this device.

The projects' development environment
I used Microchip's MPASM assembler to write the code for my projects. MPASM assembler is a command-line or Windows-based PC application that provides a platform for developing assembly-language code for Microchip's PICmicro microcontroller (MCU) families. I prefer working at the assembly-language level to have full control of the MCU's internal operations and to keep my code optimization in my own hands especially when I work on operating-systems modules such as the task scheduler and interrupt handlers. However, some readers may prefer higher-level programming languages, such as C, which is also supported by Microchip's MPLAB C18 C compiler.

I also used Microchip's MPLAB IDE (integrated development environment), which is a software package that provides a single integrated "environment" to develop code for embedded Microchip microcontrollers.

MPLAB IDE has five built-in components that consist of:

  • The Project Manager, which provides integration and communication between the IDE and the language tools.
  • The Editor, which is a full-featured programmer's text editor.
  • The Assembler/Linker and Language Tools. The assembler works with the linker to build a project from separate source files, libraries, and recompiled objects.
  • The Debugger, which allows breakpoints, single-stepping, watch windows, and all the features of a modern debugger for the MPLAB IDE.
  • The Execution Engines, which run Simulators that use the PC to simulate the instructions and some peripheral functions.

I relied on the Debugger and the Simulators heavily while working in my projects, and I find them extremely important to get a working application well done.

You can also find additional optional components for MPLAB IDE that include compiler language tools, MCU programmers, and in-circuit emulators to test code as it runs in the applications hardware.

You can download MPLAB IDE for free from Microchip's web site www.microchip.com.


Next:




Please sign in to post comment

Navigate to related information

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)

Feedback Form