Changing Arduino Micro PWM Frequency

Hi,

Is there a way to change the PWM frequency from the default 490Hz to something higher e.g 2Khz using the Arduino Micro? It's not for any particular project, will just be useful to drive DC motors with minimal audio noise!

Thanks!

Yes, you can run the PWM at rates of nearly 1MHz. You just have to change the values in the pre scale register to do this.

With what duty range? 0-15 ?

It doesn't matter with the prescale register you still get the 0 to 256 range, from the default other parameters.

To get a 0-256 range with a 1 MHz PWM frequency, the timer must run at 256 * 1 = 256 MHz
The maximum possible PWM frequency (with 8bit duty 0-256) on MCU with a core frequency of 16 MHz = 16MHz / 256 = 62.5 KHz
(not even close to 1 MHz)

Thanks,

Would you know of any examples as I cannot dicipher the datasheet?

A half of minute searching of the forum:

See the last message

Thanks,I've tried dozens of examples made for the uno and libraries but none appear to work with the Micro board.

The example in the cited topic is for atmega32U4 mcu

But well, if other people’s recipes don’t help, you’ll have to figure out the datasheet yourself

Correct. This is because the Uno and Micro (Or Leonardo) have totally different processors. Their insides are totally different, and this also goes for timers as well as a lot of things. So there is no way code that works on a Uno can possibly work on a Micro.

A micro is based on the ATmega16U4 processor.

To see how to get fast PWM on this processor see this this link :-

Thanks Grumpy_Mike,

The link you found pointed me in the right direction. The examples worked on the Micro board..