#define F_CPU 8000000UL
#include <avr/io.h>
void T1_PWM(uint16_t dutyCycle);
int main(void) {
DDRB |= (1<<PB5);
uint8_t duty=90; // duty cycle in percent
T1_PWM(duty);
}
void T1_PWM(uint16_t dutyCycle)
{
uint16_t TOP = 31249; // This corresponds to 31250 Hz
TCCR1A |= (1 << COM1A1) | (1 << COM1A0) | (1 << WGM11);
TCCR1B |= (1<<WGM13) | (1<<WGM12) | (1 << CS12);
OCR1A = (dutyCycle/100.0)*TOP; // The ON time is stored in OCR1A
ICR1 = TOP; // Set the period to 1 second.
}