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.

asked May 23, 2016 at 6:03

1 Answer 1

3

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.
answered May 23, 2016 at 7:39
2
  • Where is that function called? is it in the bootloader? Commented May 28, 2016 at 20:08
  • 1
    @LuisRamonRamirezRodriguez: No, init() is called by main(). Commented May 28, 2016 at 20:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.