analogWrite- Uno vs. Mega

On the Mega board, does pin 5 and 6 have the higher than expected analogWrite duty cycle or is that just an Uno issue?

I would have to say that the answer to your question is no. Neither the UNO or the Mega have "higher than expected" duty cycles on pins 5 and 6.

What leads you to a different conclusion?

PaulS:
What leads you to a different conclusion?

Probably this quote:
"Notes and Known Issues
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles."

from

http://www.arduino.cc/en/Reference/AnalogWrite

But I could just be guessing.

But I could just be guessing.

Well, I guess that might be where OP's impression came from. I'd never noticed that.

[quote author=James C4S link=topic=60077.msg434821#msg434821 date=1304526111]Probably this quote:...
[/quote]
That's right.

AeroQuad uses analogWrite to command ESC's but it doesn't work if you use pins 5 and 6 on a duemilanove. The mega has more timers so I'm guessing there isn't such a problem on that board.

This was with 1.7 though. Maybe the new 2.4 doesn't have such an issue.

[quote author=James C4S link=topic=60077.msg434821#msg434821 date=1304526111]Probably this quote:...
[/quote]
That's right.

AeroQuad uses analogWrite to command ESC's but it doesn't work if you use pins 5 and 6 on a duemilanove, even if the "Servo" library isn't being used. The mega has more timers so I'm guessing there isn't such a problem on that board.

This was with 1.7 though. Maybe the new 2.4 doesn't have such an issue.

I just found the MegaMini board recently so the size of a mega isn't such a problem any more for me. I'll just use that.

By default on the Uno and similar pins 5 and 6 run at 976Hz and the other PWM pins at 490Hz.

On the mega pins 4 and 13 run at 976Hz and all the other PWM at 490Hz.

This is because timer0 controls those pins and it is run in 'fast PWM mode' to provide timing for millis(). Other timers are run in 'phase-correct PWM mode' which (for a given clock prescale) is nearly twice as slow.

Something learned everyday, I wasn't aware of the difference PWM frequencies on the different pins.

But I again womder why some insist on using pwm output to control a ESC rather then the servo library? How can one get useful resolution from a PWM signal assuming a standard 1-2mSec command pulse width?

Lefty

MarkT:
By default on the Uno and similar pins 5 and 6 run at 976Hz and the other PWM pins at 490Hz.

On the mega pins 4 and 13 run at 976Hz and all the other PWM at 490Hz...

Thanks. Is there a way to slow down the execution of code on pin 5 and 6 without affecting mills? Could a part of the code for those pins execute every other loop or something like that to bring the Hz down near 490?

retrolefty:
But I again womder why some insist on using pwm output to control a ESC rather then the servo library? How can one get useful resolution from a PWM signal assuming a standard 1-2mSec command pulse width?...

As I understand it analogWrite offers a much higher update rate than the servo library does, which quadcopters need to fly. The servo library has been used in the past if you change the Arduinos (servo.h) file to (#define REFRESH_INTERVAL 12000) but apparently it can have some jitter problems since it uses software interupts which can hang for a while if a lot is going on.

None of that really answers your question though :cold_sweat:

But I again womder why some insist on using pwm output to control a ESC rather then the servo library? How can one get useful resolution from a PWM signal assuming a standard 1-2mSec command pulse width?

If you directly program timer1 you can get 16 bit resolution. If you use 8bit PWM you can just up the pulse frequency to enhance the resolution (6 bits of resolution if a 4ms period)?

RCvertt:

MarkT:
By default on the Uno and similar pins 5 and 6 run at 976Hz and the other PWM pins at 490Hz.

On the mega pins 4 and 13 run at 976Hz and all the other PWM at 490Hz...

Thanks. Is there a way to slow down the execution of code on pin 5 and 6 without affecting mills? Could a part of the code for those pins execute every other loop or something like that to bring the Hz down near 490?

If you change to phase-correct PWM there's no easy way to use the timer's counter to measure time as it counts both up and down. Could probably be done with complete rewrite of millis() micros() etc.

MarkT:
If you change to phase-correct PWM there's no easy way to use the timer's counter to measure time as it counts both up and down. Could probably be done with complete rewrite of millis() micros() etc.

No problem. I'll leave it the way it is. Thanks for all the help.