Skip to content

Latest commit

 

History

History
60 lines (37 loc) · 1.97 KB

README.md

File metadata and controls

60 lines (37 loc) · 1.97 KB

PWM Frequency Arduino Library

Library for Setting the PWM Frequency

Originaly written by kiwisincebirth 2014 https://github.com/kiwisincebirth/Arduino/tree/master/libraries/PWMFrequency

Please keep in mind that changing the PWM frequency changes the Atmega's timers and disrupts the normal operation of many functions that rely on time (delay(), millis(), Servo library).

This Library supports ATMega 328, 32U4 (Leonardo) and ATMega4809 (Nano Every).

Example

Here are some usage examples of the function:

// Set pin 9's PWM frequency to 3906 Hz (31250/8 = 3906) // Note that the base frequency for pins 3, 9, 10, and 11 is 31250 Hz setPwmFrequency(9, 8);

// Set pin 6's PWM frequency to 62500 Hz (62500/1 = 62500) // Note that the base frequency for pins 5 and 6 is 62500 Hz setPwmFrequency(6, 1);

// Set pin 10's PWM frequency to 31 Hz (31250/1024 = 31) setPwmFrequency(10, 1024);

See

http://playground.arduino.cc/Code/PwmFrequency

Thanks to macegr of the Arduino forums for his documentation of the PWM frequency divisors. His post can be viewed at: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4

Thanks to MacTester57 (aka TheDIYGuy999) for providing ATMega 32U4 testing http://www.tonymacx86.com/imac-mods/107859-kiwis-next-project-imac-g5-10.html#post765116

Thanks to plymdiver of the Arduino forums for his explaination on how the ATmega4809 timers works and which timer corresponds each pin. https://forum.arduino.cc/index.php?topic=626736.msg4503396#msg4503396

Version History

2.0 2014-07-30 Added Support for ATMega 32U4 Leonardo timers

Because it looks like, that this repo (https://github.com/kiwisincebirth/Arduino/tree/master/libraries/PWMFrequency) is not maintained anymore, I've cloned it.

The following changes were done by me, TheDIYGuy999:

2.1:

  • Syntax coloration enhanced
  • folder structure changed, so you can download and install it as usual

Changes done by arufl:

2.2

  • Support for Nano Every