Just For Starters
decode logic. A state machine may not always increment
between consecutive states. Instead, it can jump around in
its state space (i.e., counter value) similar to the way a
computer program branches back and forth between
routines. State machines can be as simple as our LED
blinker or complex enough to rival a small microprocessor.
State Machines in Software
Hardware state machines are appropriate in many
circumstances. Simple tasks — such as blinking an LED —
are readily solved with a few logic gates. Complex tasks that
must be performed with utmost speed are natural applications
for hardware state machines. Yet, there is a large middle
ground of algorithms that have relaxed speed requirements.
Software running on a microprocessor can implement
these state machines. Software implementations allow state
machines and algorithms to be readily changed without
having to connect new logic gates as with hardware.
General purpose microprocessors are often too bulky
for small projects. Your microwave oven doesn’t have a
Pentium in it and likely makes do with a microcontroller
that costs around $1.00. Microcontrollers contain small
microprocessors along with some memory and a few
basic peripherals. They are often self-contained devices
that require only power and a clock to function. As such,
microcontrollers are perfect devices for implementing control
algorithms that do not require high speed processing.
Practically every microcontroller contains at least one
timer peripheral that can be programmed to generate an
interrupt at regular time intervals. The timer is a counter
that is similar to the discrete counter discussed previously.
The discrete counter provides eight blinking states with a
62. 5 ms increment period. Therefore, the microcontroller’s
timer would be programmed to generate an interrupt every
62. 5 ms.
Programming a timer varies among specific micro-controllers. Generally speaking, a timer is clocked using a
derivative of the microcontroller’s main clock. If the
microcontroller runs at 8 MHz, the timer may be clocked at
1 MHz. In this case, the timer would be programmed to
roll-over and generate an interrupt every 62,500 cycles.
Microcontrollers also contain input/output (I/O) pins that
software can read and write. These pins are used to query
status from the outside world and to control actions such
as blinking an LED. Figure 3 shows a general purpose micro-controller that would be used in our application. Note the
on-chip, read only memory (ROM) for software storage and the
random access memory (RAM) for general software variables.
Blinking With Software
You can design software to blink an LED after creating
Table 1. Three-bit blinker
Get Next LED State
From Current State
Drive LED Control Pin
With LED State
Figure 4. LED blinking
interrupt service routine.
a regular interrupt with the
microcontroller’s timer. The
software called an interrupt service routine (ISR) whenever
the timer generates an interrupt. Between interrupts, the
microcontroller executes a main routine. The main routine
initializes the system and then remains in an idle loop
for the rest of the time. All of the blinking functionality is
time-driven and implemented in the ISR.
186 Processor @ 40 MHz
DOS w/ Flash File System
Hardware Clock / Calendar
512K DRAM & 512K Flash
Console / Debug Serial Port
16 Digital I/O lines
5V DC Power
Compact 3. 75” x 2.50”
(2) Serial Ports
(2) 16-bit Timers
Borland C/C++ Compiler v4.52
TCP/IP, PPP & Web Server
Serial Driver Library
AC Adapter and Cables
Call 530-297-6073 Email sales@ jkmicro.com
On the web at www.jkmicro.com
Circle #110 on the Reader Service Card.