0

In the documentation, it shows that the higher frequency that can be reached with an Arduino UNO for and 8bits PWM is using timer0 with the pre-scaler set at 1. That gives a Fs of 62500 Hz, but why is that so?

I understand the Prescaler is dividing the frequency, but why it does start at 62500 Hz and timer1 and timer2 have as maximum 31372 Hz.

4

Timers 1 and 2 are configured by the Arduino core library to run the so called “phase correct PWM” mode. In this mode, the timers count forward from 0 to 255, and then they count backwards to zero. Timer 0 is configured by the same library in “fast PWM” mode, where it counts from 0 to 255 and then overflows back to zero in a single timer cycle.

You can, if you want, configure timers 1 and 2 in fast PWM mode. For doing this, you will have to access their I/O registers directly. C.f. the datasheet of the relevant microcontroller for details.

A couple of links:

  • the datasheet of the ATmega328P microcontroller describes all the possible configurations of the timers (sections 15, 16 and 18 for timer 0, 1 and 2, respectively)
  • the source code of the Arduino init() function to see how Arduino core configures them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.