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
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/timers-pwm-baremetal/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/timers-pwm-baremetal/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a codex2Manually: put the files in place
.agents/skills/timers-pwm-baremetal/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a cursor2Manually: put the files in place
.cursor/skills/timers-pwm-baremetal/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mohitmishra786/low-level-dev-skills skills/baremetal/timers-pwm-baremetal2Manually: put the files in place
.github/skills/timers-pwm-baremetal/SKILL.md1Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a gemini-cli2Platform CLI
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/baremetal/timers-pwm-baremetalManually: put the files in place
.devin/skills/timers-pwm-baremetal/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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