Arduino Due PWM Frequency

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rubidium
 
Posts: 43
Joined: Sun Nov 18, 2012 10:36 am

Arduino Due PWM Frequency

Post by rubidium »

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.

User avatar
adafruit_support_mike
 
Posts: 65265
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Due PWM Frequency

Post by adafruit_support_mike »

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

User avatar
rubidium
 
Posts: 43
Joined: Sun Nov 18, 2012 10:36 am

Re: Arduino Due PWM Frequency

Post by rubidium »

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

...
/*
 * 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
...

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

Re: Arduino Due PWM Frequency

Post by moshang »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”