Skip to main content
skill CX Codex

timers-pwm-baremetal — Claude Code skill: PWM and timer setup

timers-pwm-baremetal — a skill to configure MCU timers without an OS: PWM for LED dimming and motor control, input capture for pulse measurement, and periodic interrupts via SysTick. Works on STM32 and other bare-metal platforms.

MIT 367 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a claude-code
Open on GitHub

What timers-pwm-baremetal does

This skill helps set up general-purpose timers by calculating prescaler (PSC), auto-reload register (ARR), and compare value (CCR) for PWM signals. It provides ready-to-use code examples for TIM2 on STM32, shows how to route the output to a GPIO pin via alternate function, and explains the math behind frequency and duty cycle.

Includes SysTick initialization as a simple tick source without RTOS, input capture configuration for measuring pulse width, and a troubleshooting table for common issues: wrong frequency due to APB clock doubling, no PWM output when CCER or CCMR are not enabled. Use this when driving a motor or LED via PWM, setting up periodic sampling, or measuring external signal timing on bare metal.

What it helps with

  • Set up PWM to dim an LED or control motor speed
  • Calculate timer prescaler and period for a target frequency
  • Measure incoming pulse width using input capture
  • Implement periodic ticks on SysTick without FreeRTOS
  • Debug missing or unstable PWM output

Example prompts for the agent

  • Configure 1 kHz PWM with 25% duty cycle on TIM2 channel 1
  • Enable input capture on TIM3 to measure signal frequency
  • Calculate prescaler for 84 MHz timer to get 1 MHz tick

How to install timers-pwm-baremetal

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a claude-code

2Manually: put the files in place

~/.claude/skills/timers-pwm-baremetal/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/timers-pwm-baremetal/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about timers-pwm-baremetal

How do I install the timers-pwm-baremetal skill?

Run npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a claude-code, then open ~/.claude/skills/timers-pwm-baremetal/SKILL.md.

What does timers-pwm-baremetal do?

It provides formulas and code examples for configuring MCU timers on bare metal: PWM generation, input pulse capture, and periodic SysTick ticks without an operating system.

Which microcontrollers does this skill support?

Examples target STM32, but the principles apply to any MCU with hardware timers and SysTick. Core concepts: PSC and ARR divisor math, CCMR and CCER register control.

Source text

SKILL.md · MIT
---
name: timers-pwm-baremetal
description: Bare-metal timer and PWM skill. Use when configuring general-purpose timers for PWM, input capture, or periodic ticks without RTOS. Activates on queries about timer prescaler, PWM duty cycle, input capture, or SysTick bare-metal.
---

# Timers and PWM (Bare-Metal)

## Purpose

Configure MCU timers for PWM output, input capture, and periodic scheduling: prescaler/ARR setup, compare channels, and SysTick as a simple tick source.

## When to Use

- Motor/LED dimming via PWM
- Measuring pulse width (input capture)
- Bare-metal `millis()` without FreeRTOS
- Hardware periodic sampling trigger

## Workflow

### 1. PWM on TIM2 CH1 (STM32)

```
f_pwm = f_timer_clk / ((PSC+1) * (ARR+1))
duty = (CCR / (ARR+1)) * 100%
```

```c
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;

TIM2->PSC  = 83;      /* 84MHz / 84 = 1 MHz tick */
TIM2->ARR  = 999;     /* 1 kHz PWM */
TIM2->CCR1 = 500;     /* 50% duty */
TIM2->CCMR1 |= (6U << TIM_CCMR1_OC1M_Pos);  /* PWM mode 1 */
TIM2->CCER  |= TIM_CCER_CC1E;
TIM2->CR1   |= TIM_CR1_CEN;
```

GPIO: PA0 AF1 TIM2_CH1.

### 2. SysTick tick

```c
volatile uint32_t tick_ms;

void SysTick_Handler(void) {
    tick_ms++;
}

void systick_init(uint32_t hz) {
    SysTick_Config(SystemCoreClock / hz);
}
```

### 3. Input capture

Configure channel in `CCMR` as input, set `CCER` polarity, read `CCR` on interrupt when edge captured.

### 4. Agent usage

```
/timers-pwm-baremetal 1 kHz 25% duty PWM on TIM2 channel 1
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| Wrong frequency | APB timer clock doubling | Check RM timer clock x2 rule |
| No PWM output | CCER/CCMR not enabled | Enable channel output |
| Jittery tick | SysTick overridden | One owner for SysTick |

## Related Skills

- `skills/baremetal/gpio-baremetal` — timer pin AF
- `skills/embedded/freertos` — replace SysTick with RTOS tick
- `skills/baremetal/adc-dac-baremetal` — timer TRGO for ADC trigger

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Programming languages →

From the same set140

The whole set →
llvm-passes llvm-passes guides coding agents in creating, building, and verifying LLVM optimization passes with the New Pass Manager. CX Codex +1 373installs openmp Teaches the agent to write and fix OpenMP code: parallel loops, reductions, tasks, SIMD hints and GPU offload. CX Codex +1 371installs numa-programming Skill teaches the agent NUMA programming: detect topology with numactl and lstopo, bind processes to local memory, use libnuma API, build per-node data structures, and diagnose remote access penalties. CX Codex +1 369installs dpdk Skill for DPDK work: EAL init, poll-mode driver setup, mbuf pools, rte_ring, huge pages, RSS, and testpmd validation. CX Codex +1 369installs mlir Skill for working with MLIR, a compiler infrastructure where each abstraction level lives in its own dialect. Useful when building domain-specific compilers and optimizers. CX Codex +1 366installs hypervisor-internals The hypervisor-internals skill explains Intel VT-x and AMD-V internals, from VMCS and VMCB to EPT/NPT and VMEXIT handling. Use it while studying or building a small hypervisor. CX Codex +1 365installs hip-rocm hip-rocm is a Claude Code skill for writing HIP kernels and moving CUDA code to AMD GPUs. It activates for HIP, ROCm, HIPIFY, profiling, and debugging tasks. CX Codex +1 364installs io-uring Skill for working with io_uring, the new asynchronous I/O interface in Linux. Use it when building high-performance servers and you need to reduce syscall overhead and enable zero-copy data transfer. CX Codex +1 361installs

Project sponsors

Companies that keep this analytics open