Page 149 - Embedded Microprocessor Systems Real World Design
P. 149
had states that included armed, waiting for arm, triggered, and alarm on. This
method has the advantage of compartmentalizing the functionality. You need not
worry about some process getting confused as to what state everything is in because
every state has its own unique code. And you can change the code for a particular
state without affecting the code for any other state. The disadvantages to this
method are that there usually is a lot of duplication. A keypad, for example, must
be monitored regardless of the state, so the key monitoring code (or at least a
call to the subroutine) is duplicated in the code for every state that needs it. In
addition, if a number of parallel processes can be in different states, you need
a unique state for every combination, which makes the code grow exponentially.
State machine architecture is best suited for designs that perform a single
function.
Multiple State MachinewPolling Loop
In this variation on the state machine architecture, each process can have unique
states. A polling loop goes to each process, which then branches to code for the
particular state it is in. When done, the process code exits to the next process (or
to the polling loop, which goes to the next process). The pool timer uses this
method. The polling loop checks the motor state to see whether the motor should
be on or off, and then checks for timer rollover. What happens after that depends
on whether the code is in powerfail, time set, or normal timekeeping mode (state).
For example, if the code is in powerfail mode, the code for the other modes is not
even executed.
Incremental State Machine
Each process executes a few steps of whatever operation it performs in whatever
state it is in; it then transfers control to the next process. Each process also keeps
track of where in its internal sequence it is. The next time the process is executed,
it takes up where it left off and executes a few more steps. This gives all pro-
cesses the appearance of executing simultaneously, albeit slowly. I once had to find
a bug in one of these that was written by someone else, and I am not fond of this
method.
RTOS
Real-time operating systems (RTOSs) warrant a dedicated overview in their own
chapter. Basically, a RTOS allows the code to inanage tasks by starting and stopping
them based on priority or time. For example, the code to communicate with
another system might be activated only if there are data to send.
130 Embedded Microprocessor Systems