📖 How to Use
🎯 Getting Started
This calculator helps you configure microcontroller timers for precise frequency generation and PWM control.
- Clock Speed: Enter your microcontroller's timer clock frequency (e.g., 72MHz for STM32, 16MHz for Arduino)
- Target Frequency: Enter the desired output frequency (e.g., 50Hz for servos, 1kHz for PWM)
- Auto-Calculate: The tool finds optimal Prescaler and Period (ARR) values
- Code Generation: Get ready-to-use C code for timer initialization
📐 The Math Behind It
Basic Formula:
Frequency = Clock / ((Prescaler + 1) × (Period + 1))
- Clock: Timer input frequency (usually system clock or peripheral clock)
- Prescaler (PSC): Divides the clock before the counter (0-65535 for most MCUs)
- Period (ARR): Auto-Reload Register value, counter counts from 0 to this value (0-65535)
💡 Adding 1 to both values is because these are zero-indexed registers
⚙️ PWM & Duty Cycle
PWM Duty Cycle Formula:
Duty Cycle (%) = (Compare Value / Period) × 100
- Compare Value (CCR): When counter reaches this value, PWM output toggles
- 50% Duty: CCR = Period / 2
- Servo Control: Typically 1-2ms pulse width at 50Hz (5-10% duty cycle)
🔧 Common Use Cases
- Servo Motors: 50Hz signal, 1.5ms pulse (7.5% duty) for center position
- Motor Control: 1-20kHz PWM for DC motor speed control
- LED Dimming: 500Hz-2kHz PWM to avoid visible flicker
- Timing Events: 1Hz-1kHz for periodic interrupts
🎓 Optimization Tips
- Higher Period = Better Resolution: Use smaller prescaler and larger period for finer duty cycle control
- 16-bit Limit: Most timers have 16-bit registers (0-65535 max)
- Error Percentage: Watch the calculated error - lower is better
- Balanced Values: The calculator tries to balance PSC and ARR for optimal resolution
⚡ Quick Examples
🧮 Timer Configuration
Hertz (supports: kHz, MHz, GHz)
Hertz (supports: Hz, kHz, MHz)