difference between Digital IO Pin 3 and Pin 6, with respect to PWM
Here are my observations based on arduino-0021 and -0022:
PWM pins 5 and 6 are controlled by Timer 0, which is used for lots of Arduino timing stuff, and are not as reliable (in my experience) for use as PWM outputs (unless you disable interrupts, which I really, really, really don't recommend in general).
When they are working, the PWM frequency on pins 5 and 6 is about 976 Hz.
On the other hand...
The other PWM pins are controlled by Timer 1 (pins 3 and 9) and Timer 2 (pins 10 and 11), and are more useful. The frequency on those pins is about 488 Hz. Once you do the analogWrite thing to one of these pins, the output remains at the given duty cycle until you do something else with that pin.
I'm thinking that I read (somewhere) that PWM operation in some older versions may have been different, but I don't have the means, the motivation, or the stamina to attempt other testing.
Bottom line: I, personally, wouldn't try analogWrite PWM output on pins 5 or 6, but you may be able to figure out something that works better than what I observed. See Footnote.
Here's the simplest test that I could come up with:
void setup()
{
//
// When I comment out the cli() line, pins 5 and 6 go high after a brief burst
// right after reset. The burst lasts about 32 milliseconds and during that
// time they show a 50% duty cycle square wave with frequency about 976 Hz.
// After that time, pins 5 and 6 go to a high logic state and remain there.
// When I uncomment it (so that interrupts are disabled), there is a continuous
// square wave with 50% duty cycle and a frequency about 976 Hz.
//
// The other pins work the same with or without the cli() statement: Continuous
// 50% duty cycle square waves with frequency about 488 Hz.
//
// Tested on a Duemilanove with arduino-0022.
//
// davekw7x
//
//cli();
analogWrite(3, 127);
analogWrite(5, 127);
analogWrite(6, 127);
analogWrite(9, 127);
analogWrite(10,127);
analogWrite(11,127);
}
void loop() {}
Regards,
Dave
Footnote:
I would be really, really interested to know whether anyone else has actually tested this stuff with recent Arduino releases. I mean, I am reporting the results of my actual experiments, and not something that I just deduced/divined from the code or from something I think I may have read somewhere, but maybe I overlooked something. (It wouldn't be the first time. Not even the first time today.)