Pages: [1]   Go Down
Author Topic: [reference] analogWrite has to be more specific on frequence  (Read 1908 times)
0 Members and 1 Guest are viewing this topic.
0
Online Online
Shannon Member
****
Karma: 131
Posts: 10473
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
from the reference on analogWrite:
Quote
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.

reading this i would expect an error of +-10%, but the truth is that on arduino uno/2009/diecimila etc (don't know about mega and leonardo) the frequency on pin 6 and 6 is DOUBLED, almost 1kHz instead of 500Hz.

This should be pointed out and maybe tell the user this is a feature, not a bug (like, you can have 500Hz PWM on pin x, y, and z, and 1kHz on pin a, b, c)
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
reading this i would expect an error of +-10%,
The reference talks about duty cycle, not frequency in this respect.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Online Online
Shannon Member
****
Karma: 131
Posts: 10473
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, but because duty cicle is linear to pwm, so the error on pwm is 10%

BTW you are right, the real problem is there:
Quote
The frequency of the PWM signal is approximately 490 Hz.
should be changed into
Code:
The frequency of the PWM signal is approximately 490 Hz on pin x, y,  z and 980Hz on pin a, b, c.
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Global Moderator
Italy
Online Online
Brattain Member
*****
Karma: 332
Posts: 22804
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree with lesto. The infos in that page of the Reference aren't accurate.
PWM frequency is ~490 Hz on pins 9, 10 (timer 1), 11, and 3 (timer 2), and ~976 Hz on 5 and 6 (timer 0).pins .
« Last Edit: October 08, 2012, 08:09:15 am by leo72 » Logged


Rome (Italy)
Offline Offline
Tesla Member
***
Karma: 129
Posts: 9493
"Il Vero Programmatore ha imparato il C sul K&R, qualunque altro testo è inutile e deviante."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I agree with lesto. The infos in that page of the Reference aren't accurate.
PWM frequency is ~490 Hz on pins 5 and 6 (timer 0), and ~976 Hz on pins 9, 10 (timer 1), 11, and 3 (timer 2).

Is exactly the opposite, pins 5-6 @980 Hz, pins 3-9-10-11 @490 Hz  smiley
Logged

Global Moderator
Italy
Online Online
Brattain Member
*****
Karma: 332
Posts: 22804
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right, my mistake. I corrected.
« Last Edit: October 08, 2012, 11:02:09 am by leo72 » Logged


Pages: [1]   Go Up
Jump to: