led Fade problem - got me puzzled!

Hi all.

Not sure if this is a general problem, or just some weirdness with my ATmega328 / Arduino duemilanove:

I was trying to use an analogue output (pwm) to fade a led in a project I'm working on.

One led connected to pin 11 will fade as expected, one led connected to pin 10 will NOT fade, and acts like the PWM clock on the pin is really slow (slow as in waiting 10 seconds then turn on to full brightness for a short while, then off again).

To chase down the problem, I have loaded the Fading sketch, to see if I could recreate the problem.

changing the ledPin, I tested all the PWM outputs on the Duemilanove board:

  • 3: works fine
  • 5: works fine
  • 6: works fine
  • 9: does not work
  • 10: does not work
  • 11: works fine
    so it seems like there are 2 of the PWM pins that are behaving strangely.

Can any of you prove or disprove this? (in other words, tell me if I'm mad or not ;D )

My arduino is loaded with the Optiboot bootloader.

Pins 9 and 10 use a different timer, if I remember correctly.

Does the board behave correctly with the standard bootloader?

Hi Paul.

Sounds like it could be the case of a different timer.

I'll let you know, when I have tested with the standard bootloader

(slow as in waiting 10 seconds then turn on to full brightness for a short while, then off again).

The change rhythm is controlled by delay(30) in the Fading example. This looks a little bit as if someone else keeps changing the timer register setting in an active interrupt routine. This is most unlikely a bootloader... Hardware defect?

aha.. setting an interrupt routine you say.

Could it have anything to do with the fact that i'm using the watchdog in the 328P ?

Kind of an obvious question, but I feel it needs to be asked:

Are you using current limiting resistors with the LEDs? Maybe you damaged the chip.

Not likely... You generally damage the LED first :slight_smile:

Not likely... You generally damage the LED first

I can assure you that it's quite easy to damage both the chip and the LED this way. Severe damage? Not too likely. But possible nonetheless.

I may be too short in my words. I do not deny that you can also damage the output port. I just wanted to say that the OP (most likely) has used resistors, otherwise he would have reported dead LEDs...

otherwise he would have reported dead LEDs...

But if he'd knackered the port too, how would he know? :smiley:

Good point!
A general symptom of groggy output transistors is that they do not fully close any longer.

One conseuence is that the chip becomes hot by this constant internal current. Another consequence is that the output voltage is no longer (close to) zero and five volts, but 1 and 4 (or something)...

Hi all.

I can see there has been some chattering in this thread since i was in here last.
apologies for the late reply

Yes, I always use current limiting resistors (apart from the times I don't ::slight_smile: )
-but thats not the case here.

I have now tried with the standard bootloader for the 328, and the PWM on pins 9 and 10 works just fine.

Loading the Optiboot bootloader onto the chip again, and the PWM on the 2 pins goes out the window.

At this point it seems like it is an issue with the optiboot bootloader - I think i'll contact the developer (Mr Knight).

But if he'd knackered the port too, how would he know? :smiley:

thanks for the humorous input ;D

Now the Optiboot is official bootloader of Arduino Uno, but still has the 9, 10 pin pwm problem.

And there was already bug issue about it on optiboot project page.

Hi mrkiss

Have you had problems with pwm on pins 9 and 10 as well? Have you tested it with/without optiboot?

It would be nice to get some feedback from others as well :-?

:slight_smile:

Yes I have the same pin 9, 10 PWM problem And I tested it with Optiboot and without Optiboot.
Only with Optiboot, I can see the problem

It's relief that there is someone who meet the same problem

That is optiboot's bug.
Optiboot sets TCCR1B - CS12 bit but not reset that bit.

WORKAROUND.
Put following code to setup() routine.

TCCR1B &= ~_BV(CS12);

I think all Arduino UNO users will got same problem and this workaround helps.

Forgive my ignorance, i have no idea how to test without opitboot but as i have an Arduino Uno im guessing i am running optiboot if as one of the previous posters mentioned this is default on my unit.

All pins 0 through to 13 work fine on a simple blink

As expected, running fade causes a correct fade on pins 3, 5, 6 and 11 and replicates a blink effect on pins 0,1,2,4,7,8,12 and 13

Fade running on 9 and 10 does nothing. Not even a slow fade effect. Somewhat disappointed when i am just learning the basics and already run into this issue. Until i found this thread id assumed i had a duff unit.

Not even had a chance to look round the rest of the forums yet.

Edit: Bah in the time it takes me to look up this issue, mull what im going to say and finally send someone posts a fix, trying it now :-/

Edit: Working fine on all analogue pins now, thank for the help.

I have this issue on my new Arduino Uno and the workaround work fine for me!! ;D

Thanks folks!!

Thanks tsq, the workaround works for me!

Putting:

void setup(){ 
  // WORKAROUND when using Optiboot - PWM on pins 9 and 10 will work again
  TCCR1B &= ~_BV(CS12);
}

in the fading example, and all is good again :slight_smile:

More details here:
http://code.google.com/p/arduino/issues/detail?id=364&start=200
and PWM on pins 9 and 10 not working (optiboot) - adafruit industries

It's too bad this thread didn't get more attention back before Uno was released. I guess not enough people were using (or expected to be using) optiboot...