ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

EMBEDDED MULTITASKING


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

EMBEDDED MULTITASKING

The Easy Way
by Charles Kosina

Start ý An Example ý State Machine Control ý Keyboard Scanning ý Receive Serial Data ý LCD Module ý Transmit Data ý Debugging Techniques ý Other Options ý Sources and PDF

STATE MACHINE CONTROL

Following reset, you need to initialize the state machines to the zero state. This means setting the normal housekeeping tasks such as I/O ports, interrupts, timers, resetting flags, and memory locations to correct starting values. Next is the main loop, which is quite simple (see Listing 1). Every time a state machine is called, only one state is executed. This gives equal priority to all tasks. If a task requires attention more often, simply call it more than once within the main loop.

There are important requirements to remember. All variables must be saved to memory within each block of code representing a state. This is because, as soon as you exit from the state back into the main loop, all the registers must be available for reuse by the next task. Avoid using software loops for delay generation; instead use the interrupt-driven timer for this. And never test a status bit using a loop within a state. Always exit out to the control loop. Listings 2a and b show the right and wrong approaches.

In fact, essential in almost all of my embedded designs using this technique is a timer with a number of different counters that are used to generate different delays. The interrupt service routine (ISR) in Listing 3 generates three different time delays used by software drivers. This is where the fast instruction execution of the ýF000 pays off. The overhead of the timer ISR is only about 1.5% of the CPU time, with a standard clock speed of 11 MHz.

PREVIOUSNEXT


Circuit Cellar provides up-to-date information for engineers. Visit www.circuitcellar.com for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com or subscribe online. ýCircuit Cellar, the Magazine for Computer Applications. Posted with permission.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ