■ BY JOE PARDUE SMILEY’S WORKSHOP
Doing Things in the Background:
Microcontrollers — like the Atmel ATmega328 used in
the Arduino UNO — are made of several internal sections
on an IC (Integrated Circuit) that work together to
provide intelligence, communications, sensing, and
control. The intelligence is provided by the CPU (Central
Processing Unit): a section that runs (processes) the code
you write one step at a time.
Peripheral devices do the communications, sensing,
and control. These are sections on the IC that can do
things independent of the CPU. For example, the Arduino
serial communications use a UART peripheral device to
communicate with a PC. The CPU loads a byte of data
into the UART and tells it to send the byte. The UART
then — with no further help from the CPU — sends each
of the eight bits of the byte, one at a time to the PC.
The UART also receives data from the PC; again, one
bit at a time until it has the required eight bits for a byte of
data. This sending and receiving of bytes of data happen
at the same time that the CPU is processing unrelated
commands elsewhere on the IC. This work is done as
background processing, meaning without requiring the
CPU to do the work.
Another peripheral device we have used is a timer for
analog voltage output. We — via the CPU — use the
analogOutput() function to tell this timer peripheral device
to create a PWM (Pulse Width Modulation) signal and
output it on a specific pin. The timer then generates the
PWM signal on the pin — also in the background without
further use of the CPU.
Likewise, we measure voltage on some pins by using
the analogInput() function that reads the ADC (
Analog-to-Digital Conversion) peripheral.
In early designs of microcontrollers, some of these
sorts of tasks were done directly by the CPU, but they
take up a lot of CPU time. Later designs added the
peripheral devices so they could do common repetitive
tasks without burdening the CPU.
To make an analogy, you can think of a
microcontroller as a small company with a boss and some
employees. The boss is up front and in charge, while
employees are laboring away in the background. Think of
the CPU as the boss, and the program you write as the
tasks that need to be done. The boss may do some of
those tasks, or may assign other tasks to employees (who
are the equivalent of the microcontroller peripheral
These separate sections are visible on the silicon in
the IC as shown for an Atmel chip in Figure 1. These
In this chapter, we will learn to make
sounds using the Arduino. In order to
make sounds, we will need to learn
about arrays and interrupts.
The Arduino Classroom
Arduino 101 — Chapter 11:
C PROGRAMMING - HARDWARE - PROJECTS
December 2014 57
■ FIGURE 1: ATmega AVR silicon.