No thing happens in vain, but everything for a reason and by necessity.
Before we get into designing a machine, let’s spend some time looking at how to produce the physical machine. Building a computer that doesn’t work is really easy. You may have a perfect design and flawless code, but ignore the physical environment in which the machine exists, and you’ll have built yourself a very intricate paperweight.
In this chapter, I’ll also show you how to lay out a circuit board (and where to be especially careful) and how to debug your hardware. In particular, I’ll examine how to physically produce the design for the ATtiny15 computer, which is presented in Chapter 6. I assume that you’re hand building in small quantities, so I’ll target the discussion accordingly. What I present here is not the state of the art in circuit board design or assembly, but guidelines for cottage-industry computer production. If you need to make production runs of hundreds of thousands, either you already know what you’re doing (and can skip this section) or you need to talk to a professional.
Digital systems are inherently analog in operation. Digital signals suffer degradation and noise due to analog effects present in the system. Spurious noise or reflections from nearby electrical machinery or radio transmissions can induce signals within your circuit that can cause false events to occur or even prevent a digital system from functioning at all. The one way to ensure that your system is immune to electromagnetic interference is to avoid the use of electricity! Unfortunately, the steam-powered microprocessor is not a reality, so if your system is to operate reliably in the real world, you must take electromagnetic effects into account. What follows is not a comprehensive overview of noise and associated problems and solutions. It is far too complex a field to cover properly here. What I will do is just provide an introduction. The subject is worth seeking out more detailed information and understanding these concepts more thoroughly.
The United States, Australia, the nations of the European Union, and many other countries have very strict guidelines and requirements for electromagnetic emission and immunity. The recommendations presented here are good practice only and are not necessarily sufficient to warrant compliance in your country. Therefore, it is important that you check your local regulations and ensure that you meet the appropriate requirements. Compliance cannot be guaranteed just by design. A system must be tested to ensure that it is compliant.
Noise can be a significant problem in digital systems. Noise can disturb signal transmission leading to corrupted data or may even cause a program to crash. Problems with an embedded system may or may not be noise related. Inadequate power-supply levels, insufficient decoupling capacitors, marginal timing tolerances, and software bugs can all cause seemingly random glitches in operation. However, even a well-conceived system can be disrupted by noise. There may be noise problems inherent in the design. Switching noise from integrated circuits, ringing, and cross talk are all due to aspects of the designed system. Other forms of noise may be due to environmental effects (such as nearby motors or radio emissions). The bad news is that electromagnetic problems are getting worse for digital systems. The environment is bathed in ever-increasing emissions from radio, TV, and cell phone towers. At the same time, integrated circuits are becoming increasingly sensitive as designs move toward higher speed and lower power operation.
These sources of noise may not be present during the design and test phase of the system but will only manifest themselves once the system is out in the field and in service. A crashed embedded system may be due to a hardware problem, a software problem, or the fact that the factory a block away turned on a compressor, which caused a spike on the power supply. Field problems created by noise may occur only very occasionally and can often be very difficult to track down. It is not unusual for some problems to occur only once every few days. Any problem is unsatisfactory and must be fixed, but identifying the cause is not always easy. It is better to design the system from the beginning to be as immune to these problems as possible. You have to consider not just what emissions your system may produce, but also how it may be susceptible to external effects. This will not guarantee your system will be problem-free, but every bit of immunity helps.
Electromagnetic interference (EMI) is noise generated by sources external to the embedded system. Some examples of EMI are motors, switches in power consumption, fluorescent lighting, RF emissions, and electrostatic discharges. All can be significant sources of noise. For example, turning a machine with an electric motor on or off can cause a 1000V spike on the AC power-supply line. An electrostatic discharge (ESD) can send a spike of 35kV from a finger into an integrated circuit with a current rise time of 4 Amps per second! This can be enough to permanently damage a sensitive chip. Cars are particularly noisy environments. The 12V supply line to the automotive electronics may be reversed, driven at voltages ranging from 6V to as much as 24V, and have 400V transients spikes. All of these can have very adverse effects on the operation of an embedded system.
In any circuit, there is a wire carrying current in and a wire carrying current out. Current flowing through a wire generates a magnetic field around that wire. Such a magnetic field can be a source of EMI. The intensity of the magnetic field felt is inversely proportional to the distance from the source of the field. The orientation of the field relates directly to the direction of current flow in the wire.
Current flows through a system via the power and signal connections and back to the power supply (thereby completing the circuit) through ground. Ground thus forms the return path for current flowing within the system. If the signal wire and return wire are located close together, the magnetic fields generated by the currents in the wires cancel out within a short distance of the wires. This is known as minimizing the current loop area. The objective is to keep all signal and return paths as close together and as short as possible. Where there are many current loops present in a system (as is common in many large, high-speed, digital systems), a ground plane is used to minimize loop area. A ground plane is a large conducting surface that can serve as the current return path for all loops in the circuit. A ground plane is often implemented as a complete, internal PCB layer.
Capacitive coupling is the coupling of electric fields. A signal on one wire, through its associated electric field, can capacitively induce a phantom “signal” in an adjacent signal line. This is known as crosstalk in digital systems. If not designed correctly, the magnitude of the crosstalk in a system can be significant and can easily cause a crash.
Capacitive coupling may be reduced by shielding the signal lines with
an electrostatic or
Faraday shield. This shield
is a metal conductor placed between the capacitively coupled
elements. The shield is simply part of the PCB (discussed later in
this chapter), formed in the same way as the circuit tracks, and is
usually grounded (though not always). The shield may be a simple
ground plane under an integrated circuit to protect it from signal
lines on the underside of the circuit board. Signal lines may be
shielded from each other (if necessary) by placing a ground line
The principle of keeping current loops
small applies as much to power lines
within a system as it does to signal lines. However, keeping the loop
area small for power is difficult. Power must be distributed
throughout the circuit, and to effectively route this throughout a
PCB), and keep the loop area small, is very
difficult. The power lines can therefore be susceptible to noise, and
this can cause major problems to the circuit.
The solution is to provide a path to ground for any noise present in
the power supply. This may be done locally for each component in the
circuit. It is achieved by adding a
between power and ground for each integrated circuit. The capacitor
decouples the noise from the power source and provides a path to
ground for it. In this way, noise is removed from the power supply,
and the chips have a constant and clean voltage source. The
decoupling capacitors should be placed as close as possible to the
power pins of the devices. Surface-mount capacitors have very low
inductance connections and so are preferable. Ceramic capacitors are
normally used for decoupling capacitors due to their low resistance.
The capacitor has the added advantage of acting as a current source for the device when the device must switch its outputs or internal state. As such, it represents a current source with a much smaller loop area. Generally, the circuit board will be decoupled by a large (22-100μF, say) electrolytic or tantalum capacitor placed near the power input, and each integrated circuit will be separately decoupled by 10nF ceramic capacitors. Multiple decoupling capacitors, one for each power pin, improve the situation. You need to ensure that all frequencies that may affect the circuit have a low impedance path to ground. To this end, several capacitors (100nF, 10nF, and 100pF) can be used to decouple a wide range of frequencies and thereby remove noise from the power-supply circuits.
Additionally, an onboard voltage regulator can provide a degree of isolation between your circuit and the external power supply. You can never have enough decoupling capacitors (within reason).
Noise can also be present in ground lines. Ground is not always at
the same potential in all locations. There can be a voltage
difference between the local grounds in different parts of a circuit
that are both connected to
“ground.” This voltage difference
can drive currents of several Amps through the ground line. This is
referred to as
ground loop and can result in serious problems.
Shielding, decoupling, and minimizing the current loop area can help
protect against ground noise.
Ground bounce is ringing (oscillation)
signal lines caused when one or more outputs on the same device are
being switched from high to low. This ringing can be of significant
amplitude and can adversely affect the system. Some devices are
designed so that ground bounce effects are minimized. Using devices
in packages with shorter leads (such as PLCC and surface-mount) can
reduce ringing effects. Devices with ground and power pins toward the
center of the package have shorter lead lengths, and this also helps
to reduce ringing effects. Termination techniques can also help to
reduce ground bounce.
Another effect you are likely to encounter is caused by the simultaneous switching of several outputs at once. Like ground bounce, it is due to parasitic effects relating to packaging and internal wiring of the chips. When several outputs switch at once, these effects can cause a delay of several nanoseconds in the changing output signals. Component datasheets usually specify timing parameters for a single changing output. You need to consider the effect that several changing outputs may have on your circuit.
If you walk across a carpet on a dry day
or rub a cat against a plastic surface, a
static charge will build up. If you or the cat then touches something
metallic, the jolt you both feel is an
ESD). An ESD can destroy
an integrated circuit permanently. The ESD may be too small to be
felt, but it can still send a semiconductor to that great beach in
Many integrated circuits have internal protection against ESD. This protection is sufficient to safeguard the device against the charge buildup that can occur during normal handling. It is not, however, sufficient to protect the device against the huge electrostatic sparks that can sometimes occur. Once a device is in-circuit, it should not be considered safe. It is possible for a processor to be destroyed by a spark received when a typist puts fingers on a keyboard. The spark, like a lightning strike, will attempt to find a path to ground, even if that means traveling down a data line and through the processor to get there.
One solution is to include a buffer chip to isolate the important components in the system from those that may come in contact with an ESD. This is not an ideal solution. It simply means that the buffer will be destroyed instead of the processor. You still have a system that has failed.
Transient suppressors that can provide protection are available. Such suppressors act as an open circuit at normal voltage levels but conduct power to ground at higher voltages. At no time should a signal ground be used to earth an ESD. Most integrated circuits don’t respond very well to having their ground pins raised to several hundred volts above their power supply by an ESD!
Many semiconductor manufacturers, such as Maxim, are now building protection into their devices that can withstand ESDs of 15kV or more.
When handling chips, it’s a good idea to use a
. This is a conductive sheet that you
connect to the ground of a handy power supply. You then wear a
grounding strap around your arm, connecting you
to the grounding mat. Thus, any electrostatic charge is dissipated
and never gets the chance to build up.
If you’re using a grounding mat, don’t forget to take your embedded system off it before powering up. The ground mat is conductive, and powering up a system while it is in contact can be disastrous!