Skip to content
Tactiverge

School/△ Builder/Week 19

A whole computer on one chip

Your washing machine, your bike light and a Mars rover's wheel all hide the same kind of tiny computer. What is inside it?

About 30 min · 3 goals · Checked by automated tests

1.Why should I care?

There are far more microcontrollers in the world than laptops and phones put together: one in every remote control, toaster, car window and toy robot. Each one is a complete computer squeezed onto a chip that costs about the same as a chocolate bar and runs on a trickle of power. If you can program one, you can make almost any object respond to the world.

  • ◇ Name the main parts of a microcontroller: CPU, flash memory, RAM, clock and peripherals.
  • ◇ Explain what each part does using an everyday machine as the example.
  • ◇ Explain why a machine uses a microcontroller rather than a laptop-style computer.

2.Watch

→ Listen for each part the video compares with a desktop computer, and write down which job each one does.

A chip maker's beginner tour that compares the parts of a microcontroller with the parts of an ordinary computer.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

3.Predict

A microcontroller loses power and then switches back on. Its program is still there. Where was the program kept?

Guess first. Being wrong here is how the surprise works.

4.Discover

Open Level 4 of the Virtual Computer and step through a program one instruction at a time. Each step is one fetch–execute cycle: notice where the instruction comes from (memory), where the working number lives (a register) and what decides which instruction comes next.

Can't use the interactive? Read a description instead

The Virtual Computer activity can be followed as a list: the program counter points to an instruction in memory; the CPU fetches it, decodes it and executes it (for example LOAD a number into a register or ADD); then the program counter moves on, or jumps if the instruction says so. Repeat until HALT.

5.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

A variable counting button presses is lost every time the device is switched off. Which memory is it stored in?

6.Understand

Five parts, one chip

A microcontroller (MCU) packs a whole computer onto one chip. The CPU follows instructions one at a time. Flash memory stores the program, even with the power off. RAM holds the variables while it runs. The clock is a steady tick that keeps everything in step. Peripherals are small helper circuits for the outside world: pins that read buttons and drive LEDs, an ADC that measures voltages, timers that count time, and serial ports that talk to other chips.

Microcontroller or laptop?

A laptop processor is fast and general: it runs many programs, needs lots of separate memory chips and uses tens of watts. A microcontroller is small, cheap and dedicated: it runs one program forever, starts in a fraction of a second and can run for months on a coin cell. It is slower, but a washing machine does not need to edit video; it needs to read a door switch reliably, millions of times.

Following the instructions

The CPU repeats one cycle: fetch the next instruction from flash, decode what it means, execute it (add, compare, read a pin), then move on. A special register called the program counter remembers where it is. A jump instruction changes the program counter, which is how loops and decisions work underneath your code.

Explain it another way

Think of a microcontroller as a tiny kitchen. The recipe book is flash, the worktop is RAM, the cook is the CPU, the kitchen timer is the clock and the oven, tap and scales are the peripherals.

Worked example 1

A bike light flashes, reads a button and dims when the battery is low. Which microcontroller parts are involved?

Flash holds the program. The CPU runs it. A timer peripheral sets the flash rhythm. A GPIO pin reads the button and another drives the LED. The ADC measures the battery voltage. RAM holds variables such as the current mode.

Common mix-ups

  • A microcontroller is just a slow, cheap laptop chip.
    ✓ It is designed differently: memory, clock and peripherals are built in, so one chip can run a machine by itself.
  • RAM and flash are the same thing.
    ✓ Flash keeps the program with the power off; RAM is fast working memory that forgets on power-down.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

Which peripheral turns a sensor voltage such as 1.2 V into a number the program can use?

Practice 3

Why does a TV remote use a microcontroller rather than a laptop processor?

Practice 4

What does the CPU do over and over while the program runs?

Practice 5 · a fresh version every time

A microcontroller's clock runs at 160 MHz. How long is one clock period, in nanoseconds?

ns

8.Apply it

Pick a machine at home (microwave, kettle, toy, alarm clock). Draw a box for the microcontroller with its five parts, then draw arrows to every button, sensor, light and motor you think it uses. Label which peripheral each arrow connects to.

Open BUILD 008: Create a Virtual Computer →

9.Reflect

Concepts: Inside a microcontroller