Hello,
I am using Leonardo so I base on ATmega32U4 datasheet.
On the datasheet is information when I set Timer1 on FastPWM mode with WGM13:0 = 14 or 15 and COM1A1:0 = 1 output pin OC1A (pin 9) should toggle on compare match.
In theory everything is very easy and should works but it doesn't.
void setup()
{
pinMode(9, OUTPUT);
TCCR1A = 0; // Reset entire TCCR1A to 0
TCCR1B = 0; // Reset entire TCCR1B to 0
TCNT1 = 0x0; // set Timer1 start value
TCCR1A |= B01000010; // COM1A1:0 = 1 (enable D9) and WGM11:0 = 2
TCCR1B |= B00011111; // WGM13:2 = 3 and clock external rising edge
ICR1 = 30; // set TOP value
OCR1A = 10; // set OCR1A value
}
void loop()
{
//nothing
}
Pin9 should toggle but is constantly low.
When I change mode to 15 everything works but I need TOP different than OCR1A value because I plan use also OCR1B with higher value.
Makes no difference on the Uno R3. Both work as expected. However, the OP's original code (modified for internal clock) still has no output on D9 with that change. It is not clear to me why.
void setup()
{
pinMode(9, OUTPUT);
TCCR1A = 0; // Reset entire TCCR1A to 0
TCCR1B = 0; // Reset entire TCCR1B to 0
TCNT1 = 0x0; // set Timer1 start value
ICR1 = 30; // set TOP value
OCR1A = 10; // set OCR1A
TCCR1A = B01000010; // COM1A1:0 = 1 (enable D9) and WGM11:0 = 2
TCCR1B = B00011011; // WGM13:2 = 3 and clk/64
}
void loop(){}