Source: https://mokxi.com/teachers/plans/timers-pwm-across-chips
Updated: 2026-11-19

Lesson plan

# Timers, PWM and capture on four chips lesson plan

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.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- A counter, a prescaler and a compare register, then PWM on the AVR.
- The ESP32-C3’s LEDC, the RP2040’s slices and the STM32’s TIM3.
- Input capture, overflow counting and a reciprocal counter.
- One PWM driver with the same calls on four chips.

### Materials for the whole unit

- Arduino Uno R3
- ESP32-C3-DevKitM-1
- Frequency counter x 4
- LED x 4
- Raspberry Pi Pico
- Resistor x 4
- STM32F411 Black Pill

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 50 min

## What a timer is

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

Lesson | Time | What students do

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. | 60 min

- Run it: a counter that keeps time
- A pin the CPU never touches
- An interrupt on every match
- Choosing a prescaler
- Make it sing
- The vocabulary

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. | 50 min

- Run it: PWM you set yourself
- Measure it
- What analogWrite() gives you
- Frequency against resolution
- 5 kHz from one register

### Materials

- Arduino Uno R3
- Frequency counter x 2
- LED
- Resistor

### Check for understanding

Each student finishes "AVR timers" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "5 kHz from one register".

Chapter 2. About 2 h 30 min

## Three more timer designs

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

Lesson | Time | What students do

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. | 50 min

- Run it: ask for a frequency
- Measure it
- A tone
- What the hardware refuses
- Above hearing

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. | 50 min

- Run it: a slice by register
- Which pin is which slice
- Two pins, one counter
- Fixed point
- Slices compared

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. | 50 min

- Run it: TIM3, two channels
- Pins and alternate functions
- Shared period, separate duty
- Center-aligned
- Four chips in one table

### Materials

- ESP32-C3-DevKitM-1
- Frequency counter x 2
- LED
- Raspberry Pi Pico
- Resistor
- STM32F411 Black Pill

### Check for understanding

Each student finishes "STM32 timers" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Four chips in one table".

Chapter 3. About 50 min

## Measuring

Input capture, overflow counting and a reciprocal counter.

Lesson | Time | What students do

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. | 50 min

- Run it: the timer as a stopwatch
- Check against the reference
- Wider than 16 bits
- Measure something slow
- Capture everywhere

### Materials

- Arduino Uno R3
- Frequency counter
- LED
- Resistor

### Check for understanding

Each student finishes "Measuring a frequency" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Capture everywhere".

Chapter 4. About 1 h

## Project

One PWM driver with the same calls on four chips.

Lesson | Time | What students do

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. | 60 min

- Run it: four boards, one program
- The Uno’s driver
- The ESP32-C3 and the Pico
- The Black Pill
- Change the application, once
- Design the API

### Materials

- Arduino Uno R3
- ESP32-C3-DevKitM-1
- Frequency counter x 4
- LED x 4
- Raspberry Pi Pico
- Resistor x 4
- STM32F411 Black Pill

### Check for understanding

Each student finishes "Project: one PWM driver, four chips" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Design the API".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
