I am trying to use fast pwm (mode 15) as a (variable) frequency generator. For some reason, OCRnA only accepts 10 bits, if I put in larger values, they get clipped to 10 bits. This is contrary to what the datasheet says:
"The PWM resolution for fast PWM can be fixed to 8-bit, 9-bit, or 10-bit, or defined by either ICRn or OCRnA. The minimum resolution allowed is 2-bit (ICRn or OCRnA set to 0x0003), and the maximum resolution is 16-bit (ICRn or OCRnA set to MAX)."
TIMSK1 = 0; TCNT1H = 0; TCNT1L = 0; TCCR1A = _BV(COM4A0) | _BV(WGM41) | _BV(WGM40); // toggle OCnA on match // OCR1A = 1024; // same as setting to zero OCR1A = 1023; // works and outputs expected freq TCCR1B = _BV(WGM43) | _BV(WGM42) | 1;
If I use mode 14 and ICRn for TOP, this problem is not seen (i.e. values above 1023 work as expected), but the output toggle mode is only available when using mode 15. I might try CTC mode, but that doesn't feature the OCRnA double-buffering feature, unfortunately.
Am I doing something wrong, or what's going on? I am using an oscilloscope to verify the output, btw...