Page 1147 - The Mechatronics Handbook
P. 1147
V+
digital output
FIGURE 43.5 A digital output can control a high- cur-
rent device (such as a lamp pictured to the right) using a
transistor as a switch.
many pins as there are bits of resolution, but can transfer an entire analog reading in one transaction
for faster throughput.
Some microcontrollers have built-in ADC peripherals with multiple input channels enabling highly
integrated low-cost analog sensor systems.
Analog voltages that are very small may be amplified with an instrumentation amplifier prior to analog-
to-digital conversion. Instrumentation amplifiers have very high gain and high impedance, and hence,
are suitable for sensors with very weak driving voltages and currents.
Simple Actuators
Embedded computers are not usually capable of driving most practical actuators directly, since the latter
often require voltages and currents not compatible with digital circuitry. As with sensors, however, some
simple interface circuitry is all that is required. Simple on/off actuators such as lamps, LEDs, relay coils,
etc. can be driven from a digital output, using a transistor as a switch, as shown in Fig. 43.5. The digital
output controls the on/off state of the transistor, which, in turn, either allows or does not allow current
to flow through the actuator.
Motors can also be controlled using transistors as interfaces between digital outputs and the high-
current motor coils. The lamp in Fig. 43.5 can be replaced with a DC motor to allow simple on/off
control of the motor. A set of four transistors arranged in an H-bridge configuration allows such a motor
to rotate in either direction. Two H-bridge configurations can be used to control a stepper motor. In all
cases, the speed and direction of rotation are under direct control of the embedded computer through
its digital outputs.
Analog Outputs
For actuators that require a variable analog voltage or current, a digital-to-analog converter (DAC) can
be used as an interface between the embedded computer and the actuator. As with ADCs, DACs are
available in a variety of bit widths, conversion speeds, number of channels, etc. Often, the current driving
capacity of these devices is not sufficient and an additional buffer amplifier is required to meet the current
demands of the actuator.
Programming Languages
Embedded computers are most commonly programmed in low-level languages for maximum control
over the hardware resources. The most time-critical sections of the code are generally programmed in
assembly language, which is the lowest-level language understood by a microcontroller. The C language
is generally used for higher-level structured programming. Even higher-level languages, such as C++ or
Java, are not well suited for embedded programming as they require larger amounts of memory and are
not designed for low-level access to hardware resources.
Figure 43.6 shows a fragment of an assembly language program written for the Microchip PIC 16F84A
microcontroller. It enables power to a DC motor (through an external interface circuit) when two digital
inputs are both at a logic 1 level. The code runs continuously, always checking for the status of the two
digital inputs (which may be manual switches, current sensors, etc.).
The same code fragment written in C is shown in Fig. 43.7. The code is more compact and easier to
read since C is a higher-level language than assembly.
©2002 CRC Press LLC

