system
November 14, 2013, 12:46pm
1
Hi, searching I found the following info but I can´t confirm in any of Arduino official pages.
Arduino Leonardo (ATmega32U4)
pin 3 980Hz
pin 5 490Hz
pin 6 490Hz
pin 9 490Hz
pin 10 490Hz
pin 11 980Hz
pin 11 490Hz
Is this right?
I want PWM frecuency of PWM pins by default.
Regards.
fungus
November 14, 2013, 1:03pm
2
The frequency isn't fixed, you can change it.
Those numbers don't sound right to me though.
Timer0 probably 1000Hz for the millis() timer.
The others are probably 500Hz because that's what Servo motors enjoy.
system
November 14, 2013, 1:28pm
3
fungus:
The frequency isn't fixed, you can change it.
Those numbers don't sound right to me though.
Timer0 probably 1000Hz for the millis() timer.
The others are probably 500Hz because that's what Servo motors enjoy.
Hi, thanks for your reply.
I want to know the default frecuency without change it. ( analogWrite() )
fungus
November 14, 2013, 2:29pm
4
lordk:
I want to know the default frecuency without change it. ( analogWrite() )
There's no "default" for the chip.
analogWrite() doesn't change the frequency. The frequencies are set in "main()" (ie. before setup()/loop() are called).
To amplify what fungus said, analogWrite changes the duty cycle, not the frequency.
system
November 15, 2013, 10:53am
6
Yes, you change duty cycle not frequency.
My question is. Without setting any frequency in setup(), what frequency do I get on pins 6 and 5 of Arduino Leonardo.
system
November 15, 2013, 11:34am
7
lordk:
Hi, searching I found the following info but I can´t confirm in any of Arduino official pages.
Arduino Leonardo (ATmega32U4)
pin 3 980Hz
pin 5 490Hz
pin 6 490Hz
pin 9 490Hz
pin 10 490Hz
pin 11 980Hz
pin 11 490Hz
A quick test reveals that is correct:
void setup ()
{
analogWrite (3, 128); // 980 Hz
analogWrite (5, 128); // 490 Hz
analogWrite (6, 128); // 490 Hz
analogWrite (9, 128); // 490 Hz
analogWrite (10, 128); // 490 Hz
analogWrite (11, 128); // 980 Hz
analogWrite (13, 128); // 490 Hz
}
void loop () {}
I measured each one and got the stated results.
I submitted a bug report:
opened 08:46PM - 15 Nov 13 UTC
closed 10:57AM - 19 Nov 13 UTC
Component: Documentation
The documentation for analogWrite is wrong for the Leonardo:
http://arduino.cc/… en/Reference/AnalogWrite
It states that:
> The frequency of the PWM signal is approximately 490 Hz.
However testing reveals that for pins 3 and 11 the frequency is actually 980 Hz.
This needs to be corrected to avoid user confusion.
(Alternatively, if this is inadvertent, then this is a code bug).
dc42
November 15, 2013, 9:29pm
10
The documentation is not only wrong for the Leonardo, it's wrong for the Uno as well. On the Uno, pins 5 and 6 have a PWM frequency of 976.57Hz (= 16MHz/16384). The other 4 PWM pins have a frequency of 490.20Hz (= 16MHz/(510 * 64)).
Lol, I didn't think to test that. I updated the bug report.
system
November 18, 2013, 6:00pm
12
lordk:
Hi, searching I found the following info but I can´t confirm in any of Arduino official pages.
Arduino Leonardo (ATmega32U4)
pin 3 980Hz
pin 5 490Hz
pin 6 490Hz
pin 9 490Hz
pin 10 490Hz
pin 11 980Hz
pin 11 490Hz
A quick test reveals that is correct:
void setup ()
{
analogWrite (3, 128); // 980 Hz
analogWrite (5, 128); // 490 Hz
analogWrite (6, 128); // 490 Hz
analogWrite (9, 128); // 490 Hz
analogWrite (10, 128); // 490 Hz
analogWrite (11, 128); // 980 Hz
analogWrite (13, 128); // 490 Hz
}
void loop () {}
I measured each one and got the stated results.
Great. Do you use a digital oscilloscope?
Yes. Mainly because I was too lazy to look at the source and puzzle out all those defines in the appropriate file.