Professional Documents
Culture Documents
Back to top
Introduction to Microcontrollers: 1 of 6
Our purpose here is to present basic concepts for up-and-coming systems engineers. Now that we have
completed our introductory look at electronic circuits and digital circuitry, we are finally ready to begin
looking at the microcontroller unit (MCU) that sits at the core of each system. We start with an introduction to
the MCU’s basic structure and operation. In the next session we will look at the MCU’s peripheral circuitry.
And finally we will try using an MCU in an actual system.
Figure 1 shows the structure of a typical MCU. The MCU incorporates a CPU (central processing unit), some
memory, and some circuitry that implements peripheral functionalities. If we wish to anthropomorphize, we
can say that the CPU does the "thinking," the memory stores the relevant information, and the peripheral
functions implement the nervous system―the inputs (seeing, hearing, feeling) and the responses (hand and
foot movements, etc.).
And these instructions themselves are by no means sophisticated—there is no instruction that can tell the
machine to "walk" or to "talk," for example. Instead, a typical instruction might tell the CPU to "read data from
address XXX in memory," or "write data to memory address YYY," or "add" or "multiply" two values, and so
on. But while each instruction is simple, they can be organized into long sequences that can drive many
complicated functionalities.
Instruction Decoder
The decoder circuitry decodes each instruction read from the memory, and uses the results to drive the MCU’s
arithmetic and operational circuitry. An actual decoder is a somewhat more complicated version of the decoder
circuitry we studied in the session titled "Introduction to Digital Circuits-Part 2". It restores the encoded
instructions to their original, unencoded form.
Figure 2: What the CPU Does
Step 1: When the CPU starts, it fetches the instruction stored at the address given in the program counter: in
this case, at address 0000. It decodes and then executes this instruction. In this example, the instruction tells
the CPU to get the value in memory address 0100 and write it into Register 1.
Step 2: The CPU fetches the instruction stored at address 0001 (the new value in the program counter), then
decodes and executes it. The program counter is incremented again.
Register 2: 0→4
PC: 0001→0002
Step 3: The CPU fetches the instruction stored at address 0002 (the new value in the program counter), then
decodes and executes it. The instruction tells the CPU to add the contents of Registers 1 and 2, and write the
result into Register 1.
Register 1: 3→7
PC: 0002→0003
Register 1 now holds the sum of 3 and 4, which is 7. This completes the addition. As you can see, the CPU
executes a program by carrying out an ordered sequence of very simple operations.
Many Renesas MCUs use flash memory in place of ROM. Like ROM, flash memory retains its content even
while power is off. Unlike ROM, this content can be overwritten.
RAM (Random-access Memory)
This memory can be freely rewritten. Its disadvantage is that it loses its content when the power goes off. This
memory is mainly used to store program variables.
Many single-chip MCUs1 use static RAM (SRAM) for their internal RAM. SRAM offers two advantages it
supports faster access, and it does not require periodic refreshment. The disadvantage is that the internal
circuitry is complex, making it difficult to pack large quantities on the chip’s limited space. SRAM is not
suitable for implementing large memory sizes.
The alternative to SRAM is DRAM (dynamic RAM). The simple structure of DRAM allows large quantities to
be mounted in small spaces; typical DRAM sizes are much bigger than typical SRAM sizes. But it is difficult
to form DRAM together with high-speed logic on a single wafer. For this reason, DRAM is generally not used
within single-chip MCUs. Instead, it is typically connected to the chip and treated as peripheral circuitry.
1. An MCU implemented on a single LSI (large scale integration) chip. The chip holds the CPU, some ROM, some RAM,
oscillator circuitry, timer circuitry, serial interfacing, and other components. If the chip also includes the system’s main
peripheral circuitry, it is called a "system LSI."
Clearly, the design is now more complicated. Why spend the extra time and money to develop such a design,
when the other version is so much simpler?
But let’s consider this for a moment! Suppose that we later decide to modify the operation of the circuits
shown above, so that the LED lamp will begin flashing at a certain time after the switch is pressed. For the
circuit with the MCU, all we need to do is to change the program—there is no need to touch the design itself.
For the circuit without the MCU, however, we need to redesign the circuit—adding a timer IC to count the
time, a logic IC and FPGA to implement the logic, and so on.
So the presence of the MCU makes it much easier to change the operation and to add new functionality. That’s
why so many devices now include MCUs—because they make things so much easier.
In part 2 of this MCU introduction, we will talk about the MCU’s peripheral circuitry. We look forward to
your continued participation.
Introduction to Microcontrollers: 2 of 6
We continue with our presentation of basic technical concepts that must be mastered by all students of
embedded systems engineering. In our previous session, we looked at some basic microcontroller concepts. In
this session, we look at some of the hardware (peripheral circuitry) required to run a microprocessor. In our
next session, we will see how to put a real microcontroller to work.
An MCU, like any of its various components introduced in Digital Circuits, needs a power supply to drive it.
So it must be connected to an outside battery or other suitable power source. Figure 1 shows the pin
arrangement on a 64-pin RL78 Family (RL78/G14) chip. Pins 13/14 (VSS/EVSS0) and 15/16 (VDD/EVDD0)
are the power pins, which connect as follows:
The datasheet (hardware manual) for the RL78 Family (RL78/G14) indicates that the power voltage (VDD)
must be between 1.6 and 5.5 V. This means that the MCU is guaranteed to run when supplied with any voltage
within this range. This voltage range is referred to as the operating voltage, or, in some hardware manuals, as
the recommended operating voltage.
Figure 1: Pin Diagram of a 64-pin RL78/G14 MCU (in the RL78 Family)
Figure 2 shows an example of an actual power-connection configuration of a 64-pin RL78 Family (RL78/G14)
MCU.
Pin 15 connects to bypass capacitor C1. This bypass prevents malfunctions that might otherwise occur
when a current spike causes the voltage to drop. A typical bypass capacitor is a ceramic capacitor with
capacitance between 0.01 and 0.1 µF.
The power-supply voltage is stepped down by an internal regulator to the voltage used to drive the
MCU's internal circuitry: that is, to either 1.8 V or 2.1 V. The regulator itself is stabilized by another
capacitor, C2, at pin 12.
Figure 2: Power Circuitry of a 64-Pin RL78 Family (RL78/G14) MCU
"Conductor" Oscillators
As we saw in our third session on digital circuitry basics, sequential circuits operate in sync with the rising
or falling edge of a clock (CK) signal. MCUs consist of sequential circuits, and so they require a CK signal.
This external clock signal is provided by an external oscillator connected to the MCU.
Figure 3 shows an example of an external oscillator connected to an RL78 Family (RL78/G14) MCU.
Specifically, a crystal oscillator is connected to pins X1 and X2. The MCU includes two internal clock
oscillators that work in conjunction with the external clock signal.
Because the RL78 Family (RL78/G14) uses a highly precise on-chip oscillator (accurate to within 1%) to drive
its robust set of peripheral circuitry, it can operate without need of an external clock. MCUs driven by internal
clocks are less expensive to design.
Even where an on-chip oscillator is present, however, an external crystal oscillator may be used in cases where
it is necessary to achieve better precision and lower temperature-induced variation; for example, in MCUs used
to control watches and so on.
The signal into the reset input pin must remain LOW until the power-supply and clock signals stabilize; this
pin must connect internally to that part of the circuitry that needs time to stabilize. Figure 4 shows how this can
be accomplished using a power-on reset circuit (an RC circuit).
The incoming power voltage moves through this circuit's resistor, causing some of the initial current to flow
into the capacitor. As a result, the voltage rise into the reset pin is gradual. The reset condition is cleared when
the rising voltage reaches a predetermined level.
As you can see in the above figure, there is also a manual reset circuit located next to the power-on reset
circuit. The user can reset the MCU at any time by throwing the manual circuit's reset switch.
On a general-purpose MCU, the reset signal must stay LOW for a predetermined interval. This interval is
specified in the MCU's hardware manual or datasheet. The values for the power-on reset circuit's resistor (R)
and capacitor (C) must be selected accordingly.
Conveniently, the Renesas RL78 Family (RL78/G14) uses its own internal power-on reset circuitry to handle
its resets. The MCU automatically clears the reset when the power input rises to the MCU's operating voltage.
CPU Reset
A reset operation causes the CPU to reinitialize the value of its program counter. (The program counter is the
register that stores the address of the next instruction that the CPU will execute.) Upon reinitializing, the
program counter (PC) will hold the start address of the first program to be run. Either of two methods may be
used for getting this first address: either static start addressing or vector reset addressing.
In static start addressing mode, the MCU always starts program execution at the same fixed address.
The address itself is different for each MCU model. If the PC value is 0, for example, then program
execution will start with the instruction at address 0.
In vector reset mode, the CPU starts by reading a pointer value stored at a fixed address (called the
reset vector) in ROM. Specifically, the CPU gets and decodes the pointer value, then places the
resulting value into the program counter. This may seem more complicated than the static method
described above; an important advantage, however, is that it allows the initial program address to be
freely changed.
In our third installment of this MCU introduction, we will look at the MCU development environment and try
out some real MCU operations. As always, we look forward to your continued participation.
We continue our review of MCU basics for aspiring embedded systems engineers. In earlier segments we
covered MCU hardware, programming languages, and the development environment. This time we look at the
basics of peripheral circuitry control.
1. The MCU writes 0 or 1 into a SFR bit to set output to the peripheral to LOW or HIGH level, which is
connected to the SFR bit.
2. The MCU reads the value of a SFR bit to get the status from the connected peripheral.
In the Figures below, pin A is a general-purpose I/O line that connects to a specific bit (call it bit “k”) in one of
the SFRs (call it SFR “j”).
Let’s first look at how the MCU uses the SFR bit to set the peripheral to either HIGH or LOW level.
To set to LOW (0V), write 0 into bit k.
To set to HIGH (5V), write 1 into bit k.
Assume, for example, that Pin A is connected to an LED, as shown in Figure 2. To turn the LED on, the MCU
writes a 0 into SFR-j bit-k. To turn the LED off, it writes a 1 into the bit. This very simple design is actually
used by many different types of peripherals. For example, the MCU can use the bit as a switch for turning a
motor ON and OFF. (Since most MCUs cannot output enough current to drive a motor, the pin would typically
connect to a drive circuit incorporating FETs or other transistors). More complex controls can be implemented
by utilizing multiple I/O ports.
If the MCU reads 0 from SFR-j bit-k, it knows that the peripheral is inputting a LOW signal (0V) into
Pin A.
If the MCU reads 1 from SFR-j bit-k, it knows that the peripheral is inputting a HIGH signal (5V) into
Pin A.
Figure 4 shows how an external switch can be set up so that MCU can read the switch setting through its SFR.
When Switch S is OFF, voltage is pulled up by Resistor R, resulting into HIGH input into Pin A. This
sets the value of the SFR bit (SFR-j bit-k) to 1.
When Switch S is ON, the voltage into Pin A is LOW, and the SFR bit value resets to 0.
MCU can easily determine whether the switch is ON or OFF by reading the SFR bit.
Figure 4: Implementing a Switch through General I/O
Each MCU incorporates numerous SFRs capable of implementing a wide range of functionalities. Programs
can read these SFRs to get information about external conditions, and can write these SFRs to control external
behavior. If an MCU were a human being, its SFRs would be its hands, its feet, and its five senses.
This concludes our introduction to peripheral control basics. In our next and final segment on MCU basics, we
will be looking at interrupts. See you then.
In the concluding session of this MCU Introduction series, we will be looking at interrupts. Interrupt
processing is one of the most important features of MCU programming.
Module List
Introduction to Microcontrollers: Interrupt
Processing
Back to top
Introduction to Microcontrollers: 5 of 6
In this final session of our series covering MCU basics, we look at interrupt processing—one of the core
concepts of MCU programming. We also look at the alternative process of polling.
Now assume that you are reading the book and waiting for the delivery, but you don’t have a doorbell and the
delivery person has agreed to quietly drop the package off at your door. (In other words, you won’t be
interrupted.) In this case, you would stop reading from time to time and go to the door to see if the package has
been reached. In the MCU world, this type of periodic checking—the alternative to interrupts—is called
polling.
2) The delivery person rings bell. An interrupt signal lets the MCU know that an event has oc
3) Stop reading. The MCU receives the interrupt signal, and suspends exec
4) Bookmark your current page. The MCU saves the current program execution state into its
5) Get the delivery. The MCU executes the interrupt routine corresponding to th
6) Go back to the marked page. The MCU restores the saved program execution state.
7) Resume reading from where you left off. Resume program execution.
The above analogy should clarify the general idea. Now let’s look a little more closely at the actual process
within an MCU.
When an event occurs, an interrupt signal is sent to notify the MCU. If the event occurs at an external device,
the signal is sent into the MCU’s INT pin. If the event occurs in the MCU’s on-chip peripheral circuitry such
as a timer increment or a serial I/F event—then the interrupt signal is issued internally.
These interrupt signals are received and processed by the MCU’s Interrupt Controller (IC). If multiple interrupt
signals are received, the IC’s logic decides the order in which they are to be handled (based on each device’s
priority level), and then sends the corresponding interrupt request signals to the CPU in the appropriate order.
(The IC can also be set to ignore, or “mask,” particular interrupts, to block out unwanted interruptions.) When
the CPU receives the request, it suspends current program execution and then loads and runs the interrupt
processing code corresponding to the interrupt.
Real-Time Processing
While interrupts and polling carry out similar processing, there is a notable difference. Where interrupts are
used, the MCU is immediately alerted when an event occurs, and can quickly switch to the requested
processing. This rapid responsiveness is often referred to as real-time processing.
In theory, polling can also be rapid, provided that the polling frequency is very high. In practice, however,
operation is slowed by the need to poll for multiple events, and by the difficulties of the main processing with
a sufficiently short polling loop.
For example, consider the case where an MCU is expecting a user to eventually press a switch. Since the MCU
has no way to predict when this will happen, it must continue looping and polling indefinitely. This idle
looping can consume considerable amounts of CPU processing time. And if it is necessary to poll for a variety
of events, then it becomes increasingly difficult to keep the polling interval short enough for rapid response.
Interrupt processing may be slightly more difficult for programmers to write, since it requires a reasonable
understanding of the MCU’s hardware. But interrupts are an essential feature of MCU programming, and
cannot be sidestepped. Programmers are encouraged to deepen their knowledge of MCU architecture and learn
how to write effective interrupt handlers.
This completes our series on MCU basics. We hope you have found these sessions interesting, and we
encourage you to proceed to some hands-on practice with MCUs.
Module List