CalculateeLearning paths
Embedded Systems8–10 min read

Microcontrollers: CPU, Memory and Peripherals

Understand what runs inside a microcontroller and how firmware turns sensor inputs into useful outputs.

Mental model

Think of a small workshop: the CPU follows instructions, memory holds plans and measurements, and peripherals are dedicated machines that keep working between CPU visits.

CPUcontrol + ALUFlashRAMGPIOADCTimer
A microcontroller integrates a CPU, program and working memory, plus hardware peripherals on one chip.
UNDERSTAND THE BEHAVIOR
01

A microcontroller combines a processor, memory and peripheral circuits on one chip. The processor executes instructions from a program. Flash typically retains the program when power is removed, while RAM holds changing values such as samples, counters and temporary results. A reset starts execution from a defined entry sequence; it does not resume wherever the previous run stopped.

02

Peripherals connect software to the physical world. GPIO reads logic levels, an ADC converts voltage into a digital code, and timers count clock ticks. A hardware timer can generate pulses without executing one software instruction per edge. This distinction explains why a busy CPU may delay a software action while a correctly configured hardware waveform continues.

03

In a simple superloop, initialize the hardware once, then repeatedly read inputs, update state and write outputs. Each part must finish soon enough for the next task to run. A blocking sensor read can delay button detection or motor control even if the processor is otherwise fast. Start by listing the required response times, not just the processor clock speed.

04

Board names and chip names are different. A development board adds a power regulator, programming connection and pin headers around the microcontroller. Check the actual chip, supply voltage, memory size and pin capabilities before moving code between boards. A pin that supports PWM or interrupts on one board may not provide the same function on another.

Why it matters

Understand what runs inside a microcontroller and how firmware turns sensor inputs into useful outputs.

Core ideas

  • The CPU executes instructions; peripherals perform specialized hardware work.
  • Flash and RAM serve different purposes.
  • Choose a sampling and response schedule before writing the main loop.
Key equationsSample interval = 1 / sample rate200 samples/s → 5 ms per sample
EXAMPLE

Work through a practical example

1A temperature logger samples at 200 Hz, so a new sample is due every 5 ms.

2Reserve RAM for a buffer: 100 samples stored as 16-bit values require 200 bytes for sample data.

3Convert the reading, update the display less frequently, and transmit buffered data when the interface is ready.

4Measure the worst-case loop time. If a display update takes 12 ms, it cannot run as a blocking operation in every 5 ms sampling cycle.

Common mistake

Assuming a faster clock automatically solves blocking code, insufficient RAM or incorrect voltage levels.

RememberThe CPU executes instructions; peripherals perform specialized hardware work.

Practice and check your understanding

Try each question before opening the worked answer.

1. How many bytes hold 250 unsigned 16-bit samples, excluding overhead?

Show answer and reasoning

250 × 2 = 500 bytes. The program also needs RAM for its stack, globals and other buffers.

2. Does a 10 ms blocking task fit a 2 ms response deadline?

Show answer and reasoning

No. Break it into smaller steps, use a suitable asynchronous peripheral, or change the schedule so the deadline is met.

Continue learning

Technical references and further reading

References are for further study, not endorsements. Report an error or suggest an improvement.

Progress stays on this browser only. Clearing site data removes it; it does not sync across devices.