All paths

Timers, PWM and capture on four chips

The counter, prescaler, top and compare behind every timer, set up by hand on the Uno, the ESP32-C3’s LEDC, the RP2040’s PWM slices and the STM32’s TIM3, every frequency checked by a counter on the pin; input capture as a reciprocal counter; and one PWM driver with the same calls on all four chips.

Arduino Uno R3Free7 lessons6 h4 chapters1,727 XPEmbedded engineering · Intermediate+150 XP

0 of 7 done

What you will build

2 projects, built step by step

7 lessons in 4 chapters, about 6 hours on a simulated Arduino Uno R3. Free, in your browser, every step checked by the simulator.

Chapter 1 project

AVR timers

Timer1 in fast PWM mode 14, with ICR1 as the top: 1000 Hz at 25 percent on pin 9 with 2000 steps of resolution, beside analogWrite()’s fixed 490 Hz on pin 3, and then 5 kHz from one register.

Open it in the simulator
Chapter 2 project

STM32 timers

TIM3 on the STM32F411 Black Pill with two PWM channels on PA6 and PA7 sharing one period: PSC and ARR from an 84 MHz clock, a CCR per channel, and center-aligned counting that halves the frequency.

Open it in the simulator
The map

Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

What a timer is

A counter, a prescaler and a compare register, then PWM on the AVR.

  1. Open200 XP

    Timer basics

    A timer is a counter, a prescaler and a compare register. Timer1 on the Uno toggles pin 9 in hardware once a second and fires an interrupt on every match; one register change makes it sing at 1953 Hz.

    0 of 6 steps

  2. ProjectLocked374 XP

    AVR timers

    Timer1 in fast PWM mode 14, with ICR1 as the top: 1000 Hz at 25 percent on pin 9 with 2000 steps of resolution, beside analogWrite()’s fixed 490 Hz on pin 3, and then 5 kHz from one register.

    0 of 5 steps

4 questions, graded as you go.
Chapter 2

Three more timer designs

The ESP32-C3’s LEDC, the RP2040’s slices and the STM32’s TIM3.

  1. Locked205 XP

    ESP32 LEDC

    The ESP32-C3’s LED PWM controller: a channel on any pin, a frequency and a resolution traded against an 80 MHz clock, a 440 Hz tone on a second pin, and a pair of settings the hardware refuses.

    0 of 5 steps

  2. Locked187 XP

    RP2040 PWM slices

    The RP2040’s eight PWM slices by register: a divider, a TOP and two compare values. GP2 and GP3 share slice 1 and so one frequency, each with its own duty, and an 8.4 fixed-point divider doubles the frequency.

    0 of 5 steps

  3. ProjectLocked374 XP

    STM32 timers

    TIM3 on the STM32F411 Black Pill with two PWM channels on PA6 and PA7 sharing one period: PSC and ARR from an 84 MHz clock, a CCR per channel, and center-aligned counting that halves the frequency.

    0 of 5 steps

4 questions, graded as you go.
Chapter 3

Measuring

Input capture, overflow counting and a reciprocal counter.

  1. Locked169 XP

    Measuring a frequency

    Input capture: Timer1 timestamps every rising edge on pin 8 in hardware, an overflow count makes the time 32 bits wide, and timing many periods at once makes a reciprocal counter that reads 1000.0 Hz, then 50.1 Hz.

    0 of 5 steps

3 questions, graded as you go.
Chapter 4

Project

One PWM driver with the same calls on four chips.

  1. Locked218 XP

    Project: one PWM driver, four chips

    The same three calls (pwmBegin, pwmDuty, pwmTone) and the same application on an Uno, an ESP32-C3, a Pico and a Black Pill at once: a breathing lamp at 1 kHz and a 440 Hz tone, each driver on its own chip’s timers.

    0 of 6 steps

3 questions, graded as you go.
Syllabus

Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

What a timer is

  1. Timer basicsA timer is a counter, a prescaler and a compare register. Timer1 on the Uno toggles pin 9 in hardware once a second and fires an interrupt on every match; one register change makes it sing at 1953 Hz.
  2. AVR timersTimer1 in fast PWM mode 14, with ICR1 as the top: 1000 Hz at 25 percent on pin 9 with 2000 steps of resolution, beside analogWrite()’s fixed 490 Hz on pin 3, and then 5 kHz from one register.
Chapter 2

Three more timer designs

  1. ESP32 LEDCThe ESP32-C3’s LED PWM controller: a channel on any pin, a frequency and a resolution traded against an 80 MHz clock, a 440 Hz tone on a second pin, and a pair of settings the hardware refuses.
  2. RP2040 PWM slicesThe RP2040’s eight PWM slices by register: a divider, a TOP and two compare values. GP2 and GP3 share slice 1 and so one frequency, each with its own duty, and an 8.4 fixed-point divider doubles the frequency.
  3. STM32 timersTIM3 on the STM32F411 Black Pill with two PWM channels on PA6 and PA7 sharing one period: PSC and ARR from an 84 MHz clock, a CCR per channel, and center-aligned counting that halves the frequency.
Chapter 3

Measuring

  1. Measuring a frequencyInput capture: Timer1 timestamps every rising edge on pin 8 in hardware, an overflow count makes the time 32 bits wide, and timing many periods at once makes a reciprocal counter that reads 1000.0 Hz, then 50.1 Hz.
Chapter 4

Project

  1. Project: one PWM driver, four chipsThe same three calls (pwmBegin, pwmDuty, pwmTone) and the same application on an Uno, an ESP32-C3, a Pico and a Black Pill at once: a breathing lamp at 1 kHz and a 440 Hz tone, each driver on its own chip’s timers.
Kits

Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.

See every kit
Questions

About Timers, PWM and capture on four chips

Is Timers, PWM and capture on four chips free?

Yes. All 7 lessons of Timers, PWM and capture on four chips are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Arduino Uno R3?

No. Every lesson runs on a simulated Arduino Uno R3 with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Timers, PWM and capture on four chips take?

About 6 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: AVR timers and STM32 timers.

Where do I start?

With "Timer basics", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.