0

Arduino Due PWM Frequency
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Due PWM Frequency

by rubidium on Fri Apr 18, 2014 11:24 pm

Any simple way(s) to raise the PWM frequency (on pins 2-9) from the default 1 KHz? I'm driving some fans and getting a nasty 1KHz "whine" that I'd like to eliminate.

rubidium
 
Posts: 42
Joined: Sun Nov 18, 2012 10:36 am

Re: Arduino Due PWM Frequency

by adafruit_support_mike on Sat Apr 19, 2014 12:29 am

It seems to be possible.. this thread from the Arduino forums discusses the subject: http://forum.arduino.cc/index.php?topic=131323.0

adafruit_support_mike
 
Posts: 49448
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Due PWM Frequency

by rubidium on Sat Apr 19, 2014 10:36 pm

Looks like making the following simple changes in variant.h in the Arduino library did the trick, and doesn't appear to mess up things like delay(), micros(), or ADC sample rate. I'm now getting 20KHz PWM on Pins 2-9.
Code: Select all | TOGGLE FULL SIZE
...
/*
 * PWM
 */
#define PWM_INTERFACE      PWM
#define PWM_INTERFACE_ID   ID_PWM
//#define PWM_FREQUENCY     1000    // <----- original
#define PWM_FREQUENCY      20000    // <----- change
#define PWM_MAX_DUTY_CYCLE   255
#define PWM_MIN_DUTY_CYCLE   0
#define PWM_RESOLUTION      8

/*
 * TC
 */
#define TC_INTERFACE        TC0
#define TC_INTERFACE_ID     ID_TC0
//#define TC_FREQUENCY       1000    // <----- original
#define TC_FREQUENCY        20000    // <----- change
#define TC_MAX_DUTY_CYCLE   255
#define TC_MIN_DUTY_CYCLE   0
#define TC_RESOLUTION      8
...

rubidium
 
Posts: 42
Joined: Sun Nov 18, 2012 10:36 am

Re: Arduino Due PWM Frequency

by moshang on Wed Aug 05, 2015 9:44 pm

Thanks @rubidium - this was exactly the solution to my problem today.

moshang
 
Posts: 1
Joined: Fri Aug 17, 2012 12:22 am

Please be positive and constructive with your questions and comments.