mcpField
T
timers-pwm-baremetal

timers-pwm-baremetal

github.com/mohitmishra786Development269290 installsUpdated 18w ago
Repository

About timers-pwm-baremetal

timers-pwm-baremetal is an agent skill for configuring MCU timers in bare-metal firmware. It covers PWM, input capture, and SysTick tick sources for embedded developers.

Key features

  1. 01Set timer prescaler and period
  2. 02Configure PWM channels and duty cycle
  3. 03Use SysTick as a tick source
  4. 04Set up input capture and edge detection

Use cases

  1. 01Control motor or LED dimming
  2. 02Measure input pulse width
  3. 03Implement millisecond timing without FreeRTOS
  4. 04Trigger periodic sampling from a timer

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill timers-pwm-baremetal

After installing, type/timers-pwm-baremetalin Claude Code to confirm it loaded.

Details

From the project README

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%
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
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

SymptomCauseFix
Wrong frequencyAPB timer clock doublingCheck RM timer clock x2 rule
No PWM outputCCER/CCMR not enabledEnable channel output
Jittery tickSysTick overriddenOne 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

Comments

Markdown supported