Site Search

Preparation for understanding microcontrollers: Understanding the inside of a microcontroller from the mechanics of a computer

If you were to ask, "What is a microcontroller?", there might be surprisingly few people who can answer right away.

In fact, a microcomputer is a compact version of the "mechanism of a computer." For example, the once widely used microprocessor called Z80 carried out various processes by executing instructions in sequence and communicating with memory and input/output devices. This basic mechanism has been passed down to modern microcomputers.

In this preparatory section, we will first look at the "basic structure of a computer" in order to understand what is inside a microcontroller. By learning about the building blocks such as the CPU, memory, and input/output devices, you will gain a deeper understanding of how a microcontroller works. Through this preparatory section, we will deepen our understanding of how a microcontroller works, step by step.

What is the basic configuration of a computer?

Computers are used in a variety of situations around us. Computers are built into smartphones, personal computers, home appliances, and automobiles. Although these computers appear to perform complex processes, their basic mechanisms are surprisingly simple.

A computer is broadly composed of three blocks: the central processing unit (CPU), memory devices, and input/output devices. In order for these components to work together, they also need paths to exchange information. These paths are called buses, and although they are not building blocks themselves, they are essential for understanding how computers work.

Basic computer configuration
Figure 1: Basic computer configuration

Central Processing Unit (CPU)

The CPU (Central Processing Unit) is the "brain" of a computer. It reads the instructions written in a program in order, and carries out processing while performing calculations and decisions. For example, the CPU is responsible for all operations such as "add A and B" and "if a condition is met, proceed to the next instruction."

The CPU contains the following internal functions:
・Arithmetic and logic unit (ALU): Performs calculations such as arithmetic and logic operations
・Control unit (CU): Interprets commands and issues instructions to each device
・Register: Temporary data storage area

Storage device (memory)

Memory is a place where data and instructions are temporarily stored. Information processed by the CPU is first read into memory and then retrieved from there for use. Memory includes RAM (random access memory), which stores data while it is being worked on, and ROM (read-only memory), which retains its contents even when the power is turned off.

Input/Output Devices (I/O)

Input/output devices are mechanisms through which computers exchange information with the outside world. "Input" includes control signals from sensors and switches, while "output" includes control signals that control things like turning on an LED or operating a motor. Through these devices, computers connect to the outside world and control and respond to it.

In this way, a computer works by linking together blocks with three roles: "calculation," "memory," and "input/output." This structure remains fundamentally the same whether it's a system using an older microprocessor like the Z80 or a modern microcontroller. A microcontroller combines these blocks onto a single chip, and is a compact implementation of the workings of a computer.

What are the "buses" that connect the blocks?

The CPU, memory, and input/output devices do not operate independently, but rather work together, exchanging information with each other. To do this, a "path" is needed to connect the blocks. This path is called a "bus." A bus is like a wire that connects each block inside a computer, and there are the following types:

・Address bus: Specifies where to access
・Data bus: Carries the data itself
・Control bus: Controls the timing and direction of processing

The bus allows the CPU to read data from memory and send instructions to input/output devices.

CPU structure and instruction flow

The CPU controls the overall operation of the computer by reading and processing the instructions written in the program one by one. This instruction processing is carried out in the following steps:

Instruction processing steps: Fetch ➡ Decode ➡ Execute

■ Fetch (reading instructions)
The next instruction to be executed is read from memory. The location of the instruction is managed in an internal memory area called the "program counter."

■ Decoding (decoding instructions)
The read instruction is then decoded to determine what it does, such as "assign 5 to A" or "add B and C."

■ Execution (execution of instructions)
According to the decoded information, it performs calculations, moves data, and performs other processes. If necessary, it also communicates with memory and input/output devices.

The CPU repeats this series of steps at high speed in sync with the clock signal, processing millions, or even billions, of instructions per second.

Instruction sets and CPU characteristics

The types of instructions that a CPU can understand are predetermined, called the instruction set. The instruction set includes basic operations such as "read data," "add," and "branch depending on a condition."

The content and expression of this instruction set varies depending on the type of CPU. For example, CPUs such as Z80, ARM, and RISC-V each have their own unique instruction sets, and even when performing the same process, the instructions are written and used differently. These differences in instruction sets give each CPU its own "personality." Some CPUs emphasize simple, fast instructions, while others have multifunctional, flexible instructions.

The role and types of memory

In order for a computer to perform processing, it needs a place to temporarily store data and instructions. This role is played by "memory." The CPU carries out processing by reading and writing information stored in memory.

There are several types of memory, each with a different role.

RAM (Random Access Memory)

RAM is memory used to temporarily store data and programs while you are working. Instructions and data processed by the CPU are first loaded into RAM, and then retrieved from there for use. A distinctive feature of RAM is that its contents are lost when the power is turned off. In other words, it acts like a "notepad" while you are working. Memory that loses its contents when the power is turned off is called volatile memory.

ROM (Read Only Memory)

ROM is memory that retains its contents even when the power is turned off. It is mainly used to store programs required at startup and setting information that does not change. In microcontrollers, flash memory is often used instead of ROM, and programs can be written and updated. Flash memory is similar to ROM in that it retains its contents even when the power is turned off, but it has the advantage that it can be rewritten later. Memory that retains its contents even when the power is turned off is called non-volatile memory.

Memory and Address Relationship

When the CPU accesses memory, it uses a number called an "address" to specify the location of the data to read or write. This address is like a memory location, and is used in expressions such as "read the data at address 100" or "write a new value to address 200."

Program instructions and variables are also assigned to specific addresses, and the CPU refers to those addresses according to the instructions as it carries out its processing. This mechanism is similar to that of microcontrollers, and it is important to efficiently manage addresses within a limited memory area.

Input/Output Devices and Interfaces

What are input/output devices?

Computers use "input/output devices (I/O devices)" to exchange information with the outside world, which function like the eyes, ears, mouth, and hands of humans.

・Input device: A device that receives information from the outside
Examples: sensors (temperature, light, acceleration, etc.), switches, keyboards, microphones
・Output device: A device that transmits processing results to the outside
Examples: LEDs, motors, displays, speakers

These devices are connected to the CPU via a data bus and a control bus, allowing for two-way communication. For example, the CPU can read signals from sensors and control things like turning on LEDs depending on the conditions.

What is an interface?

An "interface" is required for input/output devices and computers to communicate correctly. An interface is a "common rule" or "connection method" that allows different devices to exchange information.

For example, a CPU communicates using address, data, and control signals, while external devices communicate in other formats such as USB or I2C. The role of an interface is to "translate" these differences. Figure 2 below shows how an interface is included in an input/output device, mediating communication between the CPU and external devices. The blue arrows represent bus communication with the CPU, and the orange arrows represent communication with external devices (bus or port type).


Figure 2: The interface inside the input/output device "translates" and mediates communication between the CPU and external devices.
Figure 2: The interface inside the input/output device "translates" and mediates communication between the CPU and external devices.

■ Why is it necessary?
  
For example, even when people speak to each other in Japanese and English, they cannot understand each other.
In the same way, computers and devices need to speak the same language (interface).
Even if it appears possible to communicate directly with external devices, there is actually a "minimal interface" inside that converts the information into a format that the CPU can understand.

■ Interface type

Interfaces are important blocks that show the target applications and features of microcontrollers. They are available in a variety of combinations to suit different uses.
- GPIO (General Purpose Input/Output)
- UART (serial communication)
- SPI/I2C (a bus system for connecting multiple devices)
- USB
- Ethernet
- CAN etc.

Microcomputers are "miniature computers"

We have looked at the basic structure of a computer, but in fact a microcontroller is a "miniature computer" that combines all of these blocks onto a single chip.

・CPU (calculation and control)
・Memory (storing programs and data)
・Input/output devices (interaction with the outside world)
・Interface (communication rules and connection method)

Because all of these functions are integrated into a single chip in a microcontroller, control and communication are possible on a standalone basis without the need for a complex external configuration.

Why was the microcomputer created?

In the past, in order to control sensors, motors, etc., it was necessary to configure a single computer by separately combining a CPU, memory, I/O devices, and interfaces. However, this method had issues such as high cost, large size, and high power consumption.

This is where the "microcomputer" came in. By miniaturizing and consolidating only the functions necessary for control, and making it possible to complete the process on a single chip, it has the following advantages:

・Can be installed in small devices and embedded devices
- Low cost and low power consumption
Simple configuration and easy control

In other words, microcontrollers act as "small computers" that can simply control sensors, motors, and other devices. The diagram below compares the configuration of a conventional computer on the left with the configuration of a microcontroller on the right. Both share the same basic building blocks: CPU, memory device, and input/output devices (including interfaces), but whereas in a computer these are independent and connected by a bus, in a microcontroller these are integrated onto a single chip. By looking at this diagram, you should be able to more clearly understand that a microcontroller is "a computer's building blocks that have been miniaturized and consolidated," and the differences and similarities between the two.

Figure 3: Traditional computer configuration
Figure 3: Traditional computer configuration
Figure 4: Microcontroller configuration
Figure 4: Microcontroller configuration

Related Information

If you are interested in detailed product information on Nuvoton Technology's microcontrollers, please visit the following page.

Inquiry

If you have any questions regarding this article, please contact us below.

Nuvoton Technology Manufacturer Information Top

Nuvoton Technology Manufacturer Information If you would like to return to the top page, please click below.