0
votes

In http://arduino.cc/en/Reference/analogWrite it says,

" The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz. Pins 3 and 11 on the Leonardo also run at 980 Hz. "

I want now to check that frequency. Simply I typed this command analogWrite(9,127), which will generate PWM signal with duty cycle 50%.

Then I used the pulseIn built-in Arduino function (pulseIn descriotion) and typed this command pulseIn(9,HIGH) to measre the period in which the signal is HIGH. It returns in average 1010 us.

So the period time is 2020 (1010 for the High period and 1010 for the low period) and consequently the PWM frequency from that pin is 495.04 ~ 495Hz.

The same is done with pin number 5. The High period is 506 uS, The full period is 1012 uS, The PWM frequency from that pin is 988.14 Hz ~ 988 Hz.

So, What is the exact PWM frequency ?!

The following pictures is snapshots for the Arduino sketch and the results

The Arduino sketch

The Arduino sketch

When I pressed '1' multiple times

When I pressed '1' multiple times

When I pressed '0' multiple times

When I pressed '0' multiple times

3

3 Answers

1
votes

PWM signals are created by timers. A timer increments a register, and various methods create a square signal based on that.

The frequency depends on 3 things:

  • the master clock: 8MHz or 16MHz usually on Arduino)
  • the prescale (or divisor on the page below): to slow down the frequency, you can setup the timer to increase the count every 1, 2, 4, 8, 16… master clock cycles
  • the maximum count: there are several counting methods, but an important limit is the register size (usually 8 bits and 16 bits on Arduino)

You'll find specific details on this page: http://playground.arduino.cc/Main/TimerPWMCheatsheet

0
votes

So, What is the exact PWM frequency ?!

imo There are to many variables to give the "exact" PWM frequency between boards and other factors.

For example, if I were to test two different boards from the same company I would not be able to get an exact match.

-1
votes

You've used one of the two pins where the PWM signal works at 980hz! More specifically the pin 5 and 6!

This is what the website of Arduino says:

The frequency of the PWM signal on most pins is approximately 490 Hz. On the Uno and similar boards, pins 5 and 6 have a frequency of approximately 980 Hz.

http://arduino.cc/en/Reference/analogWrite