I am experimenting with setting the PWM frequency on Timer/Counter1 of the ATtiny85. In section 12.2.2 Timer/Counter1 in PWM Mode, page 87 of the datasheet states:
The frequency of the PWM will be Timer Clock 1 Frequency divided by (OCR1C value + 1). See the following equation:
fPWM = fTCK1 / (OCR1C + 1)
I am running the ATtiny85 at 1MHz, and I've set the Timer/Counter1 prescale to 1 (no prescale). The value of OCR1C is 255. If I'm reading it right, this formula should give me:
fPWM = 100000Hz / (255 + 1) = 3906.25Hz
However, my oscilloscope shows that I'm actually getting a PWM frequency of exactly 4000Hz.
I get consistent results when I try different prescale values. For example, using a prescale of 16, the formula says:
fPWM = (100000Hz / 16) / (255 + 1) = 244.140625Hz
But my scope shows exactly 250Hz.
I feel like I must be missing something obvious. Anyone have an idea what it is?