Go Down

Topic: Good PWM Pins (Read 767 times) previous topic - next topic

retrolefty

But I thought analogWrite(pin#,0) and analogWrite(pin#,255) are two 'special cases' in that the analogWrite library does a true digitalWrite(pin#,LOW) and digitalWrite(pin#,HIGH) for those two specific values respectably. Therefore the warning about possible variations in actual duty for small values used on pins 5 & 6 should probably be changed to:

Quote
This will be noticed mostly on low duty-cycle settings (e.g 1 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.


Or am I all wet?

Lefty

FardinB

Yessss... you are right about the note and that is the thing that bothers me. I wanna know if there is any other pins like 5 and 6 that have weird outputs?

Has anybody tested this with an oscilloscope?

Thanks

retrolefty


Yessss... you are right about the note and that is the thing that bothers me. I wanna know if there is any other pins like 5 and 6 that have weird outputs?

Has anybody tested this with an oscilloscope?

Thanks


Well there is always a possibility of different software libraries you try to include in your sketch trying to utilize the same timers used by analogWrite commands, thereby setting up a conflict with the analogWrite commands. The default arduino sketch startup code only uses timer0 to support the millis() functions so I wouldn't expect any other 'weird outputs' on other pwm pins driven by the other timers, but hey I didn't even know about the possible 'weirdness' for pins 4 and 5.

Anyway here is a code fragment from the analogWrite core function showing that any and all pwm output pins will be forced to a true LOW or HIGH when used with values 0 and 255 respectively:

Code: [Select]

void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them.  Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
else
{
switch(digitalPinToTimer(pin))
{



Lefty

FardinB

Thanks for the research.

Is there a page that shows what timers are used for each PWM pin on the Arduino Mega 2560?

I am using timer 1 in my code as a software interrupt.

Thanks

retrolefty


Thanks for the research.

Is there a page that shows what timers are used for each PWM pin on the Arduino Mega 2560?

I am using timer 1 in my code as a software interrupt.

Thanks



The below might be useful. The far left column is the 'abstracted' arduino pin number and the other columns show the AVR port and bit number of the corresponding pin and descriptions of secondary functions for some of the pins for both the 328p and mega1280/2560 boards.

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

Go Up