I've got this code from the MultiWii project, which is relevant to the hardware, ATmega32u4, I have. It is part of a function called initOutput()
.
In the comment it says "connect pin 6", which is the bit of that which specifies pin 6 as I would like to change it to another pin, specifically A0.
// Enhanced PWM mode
TCCR4E |= (1<<ENHC4);
// Prescaler to 16
TCCR4B &= ~(1<<CS41);
TCCR4B |= (1<<CS42) | (1<<CS40);
// Phase and frequency correct mode and top to 1023, but
// with enhanced PWM mode we have 2047.
TCCR4D |= (1<<WGM40);
TC4H = 0x3;
OCR4C = 0xFF;
// Connect pin 6 to timer 4 channel D
TCCR4C |= (1<<COM4D1) | (1<<PWM4D);
1 Answer 1
It's the (1<<COM4D1)
that enables pin 6, or more specifically OC4D for timer output. You cannot use A0 instead, since there is no output compare capability on that pin; only pins 13, 5, 10, 9, 6, and 12 can be connected to timer 4. See the datasheet for details.
-
thanks for your answer, maybe you can help with my latest question: arduino.stackexchange.com/questions/13557/32u4-timer-4-helpHayden Thring– Hayden Thring2015年07月19日 04:04:44 +00:00Commented Jul 19, 2015 at 4:04