title: Generating a variable frequency PWM signal for AVR
body: <p>I want to generate a PWM signal with variable frequency and a fixed duty cycle(50%). Frequency should vary between 0-25KHz. This is for a ATMEGA32U4 microcontroller and I'm writing it in C using Atmel Studio. I did read the datasheet but I can't get my head around on how to do the calculations and which modes I should use. After going through different tutorials I found that its best to use CTC mode. </p>
  
  <p>How do I select which prescalar I should use since the frequency is a variable? Do I need to use interrupts? Any help on how to setup these timer registers are appreciated.   </p>