0

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

4

3 回答 3

1

PWM 信号由定时器产生。定时器增加一个寄存器,各种方法基于它创建一个方波信号。

频率取决于三件事:

  • 主时钟:通常在 Arduino 上为 8MHz 或 16MHz)
  • 预分频器(或下页上的除数):要减慢频率,您可以设置定时器以每 1、2、4、8、16... 主时钟周期增加计数
  • 最大计数:有多种计数方法,但一个重要的限制是寄存器大小(在 Arduino 上通常为 8 位和 16 位)

你会在这个页面上找到具体的细节:http: //playground.arduino.cc/Main/TimerPWMCheatsheet

于 2017-02-06T12:14:53.127 回答
0

那么,确切的 PWM 频率是多少?

imo 有很多变量可以给出板和其他因素之间的“准确”PWM 频率。

例如,如果我要测试来自同一家公司的两块不同的电路板,我将无法获得完全匹配的结果。

于 2018-01-15T10:47:53.843 回答
-1

您已经使用了 PWM 信号工作频率为 980hz 的两个引脚之一!更具体地说是引脚 5 和 6!

这是 Arduino 的网站上所说的:

大多数引脚上的 PWM 信号频率约为 490 Hz。在 Uno 和类似电路板上,引脚 5 和 6 的频率约为 980 Hz。

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

于 2014-05-25T22:00:30.050 回答