Design Idea
Sequential state machine aids in automatic control
Edited by Bill Travis
Abel Raynus, Armatron International, Malden, MA -- EDN, 9/2/2004
Creating a sequential state machine is a common approach for automatic-control design. The method finds wide use for controlling sequential processes in industry, robotics, and measuring. The concept of a state machine is simple: A number of states describe a process under control; each state produces some output signals and advances to the next state according to received input signal.
Two kinds of state machines exist. In a Moore machine, only the current state determines an output. A Mealy machine's output depends on both the current state and the inputs. A state diagram uniquely and completely specifies a Moore machine (Figure 1). Based on this diagram, you can create a microcontroller program that assigns five assembler directives to each state: an address offset, the outputs, a time to remain in this state (delay value), the next state to go to for an input of zero, and the next state to go to for an input of one.
As an example of a Moore machine, consider a phototimer, which automatically lights a lamp for a given time when it becomes dark. After that time expires, it switches off the lamp and waits for the next night to repeat the process (Figure 2). The design uses an eight-pin Motorola (www.motorola.com) MC68HC908QT2 microcontroller; Listing 1 shows the program code. The photocell determines the Moore machine's input signal. The threshold of darkness is equal to 1.6V, which corresponds to a value of 52H after built-in analog-to-digital conversion. The sensitive triac, Q1, model L2004F31 from Teccor (www.teccor.com) activates the lamp. The triac needs a gate current of 3 mA from the microcontroller can drive load current as high as 4A rms at a maximum voltage of 200V. The two LEDs with built-in resistor, LTL-4231T-R1s from LiteOn (www.liteon.com), indicate a current state in binary code. Thus, the Moore machine has two outputs—the lamp and the state indicator—both of which the Port A setting determines. The delays occur at 2 sec for states 1 and 3, and 4 minutes for state 2. In a real project, you can set any delay, even several hours or days. The delay affects only the complexity of the timer-interrupt routine.
Check out our Best of Design Ideas section!



















