Constant voltage in a PWM pin (pin 6)

Hello,

I'm currently developing a small project thats using pretty much every pin on the output side. Therefore, I don't have the possibility to change pins.

Anyway, I'm getting a constant output voltage (~2V) from a PWM pin (pin 6), even when it's output value in the code is 0 (zero).

For example, let's say I have something like this:

const int Pin1 = 5;
const int Pin2 = 6;

void setup()
{
  Serial.begin(9600);
  pinMode(Pin1, OUTPUT);
  pinMode(Pin2, OUTPUT);
}

void loop()
{
  for(int i = 0; i < 256; i++)
  {
     analogWrite(Pin1, i);
     analogWrite(Pin2, i);
     delay(10);
  }

  for(int i = 255; i > 0; i--)
  {
     analogWrite(Pin1, i);
     analogWrite(Pin2, i);
     delay(10);
  }
}

Now, while this is running, I can measure the output voltage on each pin (while driving a 3.3V led) and get between (0 - 3.3V) on Pin 5, and between (~2 - 3.3V) on Pin 6.

I've changed arduino boards, while maintaining the ATMEGA328 chip, and get the same result.
I haven't been able to test with another chip because I have no other one that can be programmed (the other one I have keeps giving an upload error - but thats for another post).

I'm guessing that there might be a problem with the pin on the ATMEGA chip corresponding to pin 6 on the board.

Is this right? is There something else I can do? I really need to use that pin to control LEDs, and it won't look properly if one of them doesnt turn off when it's supposed to...

Any thoughts?

Take PWM out of the picture. What happens if you connect a resistor divider (or LED + resistor)? (BTW, there is a typo in the code you used above. Have you run this actual code yet?)

Just by coincidence I've just suffered the same problem with a PWM pin, but pin 3 for me - it was damaged when testing a high power LED driver (MOSFET controlling several amps at 24V). The pin won't get better by itself alas, a new 328 chip is required (once you've double checked for shorts etc).

I believe I also damaged mine while driving a BJT to 12V, 1.1A... Hadn't properly secured a ground (and I also believe it was this that burned my macbook logic board :S )...

I also guessed that I would eventually have to replace the chip, I was just wondering if it was possible to do something (in terms of code, or using extra resistors), to attenuate this effect...

@James: that isn't the code I used, I just typed that by heart to show how I tested the voltage. What is the typo? I'm looking at it and can't find it...

pinMode(Pin2; OUTPUT);

It leaps off the screen!

This one is more subtle:

for(int i = 255; i > 0; i--)

Ok, I've edited the first one (it doesn't really leap of the screen, it just kinda surreptitiously stays there, lurking, waiting to crash the compiler and laugh an evil laugh...) :smiley:

Now the second one I don't see what the problem is. I want i to start at 255, and decrease by 1 while it's bigger than 0. What's wrong with that?

What's wrong with that?

Nothing wrong, per se, but the "up" loop goes 0...255, whilst the "down" goes 255...1

I guess I like symmetry (and I'm a pedant)

it's like these two lines in the servo sweep example

for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  • my blood-pressure rockets every time I see them cut-and-'pasted somewhere.
    Grrr.

Fair enough. But since that wasn't the software used, I just wanted to demonstrate that the LED would get an up-n-down motion, it wasn't really important if it would go to 0 or 1 (the voltage with 1 is pretty much the same as with 0)...