I have a atmega32u4 with 8Mhz and try to generate a clock signal with 1,2 or 4 MHz using timer 4 and output it on PD6 (!OC4D)
For timer 1 and on PB5 (OC1A) I used CTC mode:
TCNT1=0;
// Toggle OC1A on Compare Match
TCCR1A = 0x00;
bitSet(TCCR1A, COM1A0);
// Clear Timer on Compare Match
TCCR1B = 0x00;
bitSet(TCCR1B, WGM12);
//8Mhz
// Set frequency (0 = 4Mhz, 1 = 2MHz, 3 = 1MHz)
OCR1A = <value>;
// No prescaling
bitSet(TCCR1B, CS10);
but timer4 does not have this CTC für OC4D (or have I got that wrong from datasheet?)
Is there another way to create that output?