#define PWM_PIN (PB5) // Use the OCR1A pin
#define PRESCALER (64) // Define prescaler value as 64
#define FREQ_HZ (1000UL) // Define the frequency as 1000 Hz
#define TOP_VALUE (F_CPU/(FREQ_HZ * PRESCALER))
void initTimer1() {
TCCR1A = TCCR1B = 0;
TCNT1 = 0x000;
// Set TOP value for the PWM period
ICR1 = (uint16_t)(TOP_VALUE - 1);
// Set OCR1A value for 25% duty cycle
OCR1A = (uint16_t)(TOP_VALUE / 4);
// Configure Timer1 in Fast PWM mode (mode 14) with prescaler of 64
// Set non-inverted output on OC1A
// Use Fast PWM mode and set prescaler to 64
TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << WGM12) | (1 << CS11) | (1 << CS10);
}
void setup() {
DDRB |= (1 << PWM_PIN);
initTimer1(); // Initialize Timer1
}
void loop() {
}