Dimmer
A colleague prototyped a lighting controller on the STM32F4 but couldn't get the dimmer working before going on vacation. The timer output compare registers need to be configured for a 50% duty cycle at 1 kHz.
The STM32F4 runs at 16 MHz. TIM2 Channel 1 should be set up so that the output compare produces a symmetric waveform: high for half the period, low for the other half.
After your firmware runs, the platform reads TIM2 registers directly, like probing a real chip with a debugger. Correctness is judged by register state, not actual pin output.
Expected register state for 50% duty at 1 kHz:
- Timer prescaler divides 16 MHz down to a 1 MHz tick (PSC = 15)
- Auto-reload sets the period to 1 kHz (1000 ticks, ARR = 999)
- Capture/compare register sets the duty cycle to 50% (CCR1 = 500,
half of the 1000 tick period)
- Output compare mode is set to PWM Mode 1
- Channel 1 output is enabled