Embedded Systems

How microcontrollers read the world and drive it: platforms and tools, pins and interrupts, timers, analog input, serial buses, architecture and RTOS, memory, power, wireless updates and debugging.

An embedded system is a small computer built into a device to do one job: a thermostat, a motor controller, a data logger, a sensor node. At its heart is a microcontroller (MCU): a processor, memory and peripherals (pins, timers, converters, communication ports) on one chip. Writing the software for it, called firmware, is different from writing a desktop program: memory is measured in kilobytes, timing is real, the program runs forever without an operating system to rescue it, and a bug can move a motor. This guide covers the firmware side, with the formulas and worked numbers behind real designs: platforms and tools, pins and interrupts, timers and PWM, analog input, serial buses, architecture and RTOS, memory and reliability, power, wireless and updates, and debugging. The matching hardware (power, reset, clocks, level shifting, driver circuits) is in Microcontroller Electronics.

Start here: what do you need?

I need to…Go to
choose a chip or board, or set up tools for a first projectPlatforms and Toolchains
read a switch, drive an LED or handle an interrupt properlyGPIO, Interrupts and Debouncing
generate a precise period, a PWM signal or a servo pulseTimers, PWM and Timing
read a sensor with the ADC, average, filter or convert to unitsAnalog Input and Signal Processing
talk to a chip over UART, I²C, SPI or CAN, or fix a bus that does not respondUART, I²C, SPI and CAN in Firmware
structure a program: state machine, scheduler, RTOS, watchdogFirmware Architecture, State Machines and RTOS
save memory, use fixed-point math, store settings or check data with a CRCMemory, Number Formats and Reliability
make a battery device last months or yearsPower and Low-Power Firmware
connect a device to Wi-Fi or Bluetooth, use MQTT or update firmware in the fieldWireless, Networking and Updates
find a bug, crash or resetsDebugging, Testing and Troubleshooting

A suggested order

If you are new to firmware, read the pages in order: the first builds the working set-up, the next four cover the peripherals every project uses, and the last five are about making that code robust, efficient, connected and testable.

  1. Platforms and Toolchains: Choosing a microcontroller family and board, development tools, the build and flash cycle, and a first project that works.
  2. GPIO, Interrupts and Debouncing: Reading and driving pins in firmware, pull-ups, interrupt service routines, debouncing and the rules that keep ISRs safe.
  3. Timers, PWM and Timing: Prescaler and compare math, periodic interrupts, PWM frequency and resolution, servo pulses and timing without blocking.
  4. Analog Input and Signal Processing: ADC resolution and reference, sampling, oversampling and filtering, calibration and scaling, with a thermistor worked through.
  5. UART, I²C, SPI and CAN in Firmware: Frames and timing, baud-rate error, addresses, modes, reading registers, DMA, and the faults that stop a bus working.
  6. Firmware Architecture, State Machines and RTOS: Super-loop, event-driven and RTOS designs, state machines, scheduling and deadlines, priority inversion and the watchdog.
  7. Memory, Number Formats and Reliability: Flash, SRAM and the stack, integer and fixed-point math, endianness, checksums and CRCs, and storing settings safely.
  8. Power and Low-Power Firmware: Sleep modes, duty cycling, battery life from a current profile, regulators, brown-out and wake-up design.
  9. Wireless, Networking and Updates: Wi-Fi, Bluetooth LE and MQTT for devices, security basics, bootloaders and safe over-the-air updates.
  10. Debugging, Testing and Troubleshooting: Print debugging, logic analyzers, scopes, SWD debuggers, hard faults, unit tests and a symptom-to-cause table.

What firmware actually does

  • Reads the world: switches, sensors and communication ports (GPIO, ADC, buses).
  • Decides: a control law, a state machine or a schedule, within a fixed time (architecture).
  • Acts on it: PWM, outputs, messages (timers and PWM).
  • Survives: bad inputs, power loss and bugs: watchdog, memory limits, checksums and safe updates (memory and reliability, updates).
  • Sips power: sleeping between jobs so that a battery lasts (power).

Quick reference: formulas

TopicFormulaPage
ADC step (LSB)LSB = Vref ÷ 2nAnalog Input and Signal Processing
Timer tick and periodtick = prescaler ÷ fclk; compare = period ÷ tick − 1Timers, PWM and Timing
PWM frequencyf = fclk ÷ (prescaler × counts)Timers, PWM and Timing
UART byte time10 bits ÷ baud (8N1)UART, I²C, SPI and CAN in Firmware
I²C pull-upR ≤ tr ÷ (0.8473 × Cbus)UART, I²C, SPI and CAN in Firmware
CPU utilizationU = Σ Ci ÷ Ti; rate-monotonic bound n(21/n − 1)Firmware Architecture, State Machines and RTOS
Fixed-point Qm.nvalue = integer ÷ 2nMemory, Number Formats and Reliability
Battery lifeh = capacity ÷ average currentPower and Low-Power Firmware

Calculators and related guides

Safety

  • Firmware controls real things. A stuck output can run a motor, heater or valve: make outputs fail safe, use a watchdog, and put hardware limits (fuses, thermal cut-outs, limit switches) where a software fault could hurt someone.
  • Mains and batteries. A pin never switches mains power directly; use an approved relay or solid-state relay with isolation. Lithium cells need a protection circuit and a proper charger.
  • Safety-critical functions (machine guarding, medical, vehicles) need certified components and processes; a hobby microcontroller is not a safety system.
  • Static and ratings: exceed a pin’s voltage or current rating and it fails; read the absolute maximum ratings.

FAQ

Arduino or a “real” microcontroller?

Arduino boards use real microcontrollers with a simplified software library. The library is fine for prototypes and many products. Move to the manufacturer’s tools when you need tight timing, low power or the full peripheral set (see Platforms and Toolchains).

When should I use an interrupt?

For events that are short and must not be missed: an encoder edge, a communication byte arriving, a timer tick. For slow events a main-loop poll is simpler and easier to debug. See GPIO, Interrupts and Debouncing.

Do I need an RTOS?

Not for most small projects. A well-written super-loop with a state machine and timer ticks goes a long way; an RTOS helps when there are several independent activities with different timing, or a network stack. See Firmware Architecture, State Machines and RTOS.

Why is my ADC not accurate to its bits?

Resolution is the number of steps; accuracy is how close each step is to the true value. Reference error, offset, gain error and noise typically cost the last one to three bits. See Analog Input and Signal Processing.

Where did the old Embedded Systems sections go?

All of them are in this guide, with much more depth: GPIO and interrupts, ADC, PWM and timers, serial buses, power, memory and debugging each have their own page.

References

  • Microcontroller datasheets and reference manuals (Microchip ATmega328P, Raspberry Pi RP2040, Espressif ESP32, STMicroelectronics STM32).
  • Barr, M. and Massa, A., Programming Embedded Systems, O’Reilly.
  • White, E., Making Embedded Systems, O’Reilly.
  • Labrosse, J., MicroC/OS and the FreeRTOS documentation (real-time kernels).

Last reviewed: October 2026. Check your chip’s datasheet for exact registers, limits and timing; the worked numbers here use common parts and typical values.