Changing PWM Frequency of the Arduino

A place to talk about all the Operating Systems, Software & Hardware
Forum rules

- Posts are to be made in the relevant forum. Users are asked to read the forum descriptions before posting.

- Members should post in a way which is consistent with "normal writing". That is users should not post excessive numbers of emoticons, large, small or coloured text, etc. Similarly users should not SHOUT or use excessive punctuation (e.g. ! and ?) in topic titles or posts.

- Members should use an appropriate, descriptive subject when posting a new topic. Examples of bad subjects include; "Help me!", "I'm stuck!", "I've got an error!", etc. Examples of good subjects include; "Getting an TABLE FULL error upon login", "Cannot restore a backup".

- Members are asked to post in English only so that posts can be well received and properly monitored.

- Spam is not tolerated here under any circumstance. This includes offering hosting services (charged and free), installation services, solicitation etc. Recruiting members for your own projects (moderators, designers, professional MOD work, etc.) is not permitted and is also considered spam. Users posting spam will be warned and their post removed.

- Members should post in a way that is respectful of other users. Flaming or abusing users in any way will not be tolerated and will lead to a warning. Vulgar language and inappropriate material is not allowed and will be removed. We try to maintain a family friendly atmosphere whenever it is possible within the main subject matter of this community. Please keep this in mind when participating.

- Each user is allowed to create one account. If you would like to change your username, please contact us and, most likely, we can do it for you while you can keep all of your profile data, posts, and other content.

- If a user violates our guidelines and shows a disregard for them, our staff and our community, they run the risk of losing their account. We reserve the right to deactivate any account and to edit or remove any content without warning. These guidelines are subject to change at any time without notice.

Thank you for visiting!
Post Reply
User avatar
Posts: 31
Joined: Mon Jun 06, 2016 10:47 am

Tue Aug 23, 2016 2:06 pm


I am trying to setup a fan control using PWM and the analogwrite() function.
However when I set a value below 255 my cooling fan starts rotating but also gives a high tone.
I was told that the reason for this is most likely the PWM frequency of the Arduino and that it is probably too low.
It was suggested to change it to at least 31kHz.

I googled a bit around and found the following: ... nardo.html

I am using pin 11 of the Arduino. From the links it looks like that 31kHz is not supported on pin 11. Instead I am using 62kHz.

The example from the playground link doesn't compile. I think this is not for a Arduino Leonardo so the registers do not exist.

The blogspot link compiles but I guess it doesn't change the frequency.
I am using the StandardFirmata on the Arduino and changed it to this:

I added this function:

Code: Select all

void pwm91011configure(int mode)
// TCCR1A configuration
//  00 : Channel A disabled D9
//  00 : Channel B disabled D10
//  00 : Channel C disabled D11
//  01 : Fast PWM 8 bit

// TCCR1B configuration
// Clock mode and Fast PWM 8 bit

// TCCR1C configuration
And I changed the setup() function to this. Basically I just added a call to the other function.

Code: Select all

void setup()

  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
  Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
  Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
  Firmata.attach(SET_PIN_MODE, setPinModeCallback);
  Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback);
  Firmata.attach(START_SYSEX, sysexCallback);
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  // to use a port other than Serial, such as Serial1 on an Arduino Leonardo or Mega,
  // Call begin(baud) on the alternate serial port and pass it to Firmata to begin like this:
  // Serial1.begin(57600);
  // Firmata.begin(Serial1);
  // However do not do this if you are using SERIAL_MESSAGE

  while (!Serial) {
    ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101
  systemResetCallback();  // reset to default config
Is this the wrong way to do? Does it even work with the standard firmata?

User avatar
Posts: 31
Joined: Mon Jun 06, 2016 10:47 am

Fri Aug 26, 2016 9:17 am

I now created a post on the forums.
Anyone interested in a solution (hopefully I'll get one) can follow it here:

Post Reply