Pages: [1]   Go Down
Author Topic: Constant voltage in a PWM pin (pin 6)  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Porto, Portugal
Offline Offline
Newbie
*
Karma: 1
Posts: 38
JoATMoN - Jack of All Trades, Master of None
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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?

« Last Edit: May 19, 2011, 09:22:59 am by DPontes11 » Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?)
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10438
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

[ I won't respond to messages, use the forum please ]

Porto, Portugal
Offline Offline
Newbie
*
Karma: 1
Posts: 38
JoATMoN - Jack of All Trades, Master of None
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24351
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
pinMode(Pin2; OUTPUT);
It leaps off the screen!

This one is more subtle:
Code:
for(int i = 255; i > 0; i--)
« Last Edit: May 19, 2011, 09:18:37 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Porto, Portugal
Offline Offline
Newbie
*
Karma: 1
Posts: 38
JoATMoN - Jack of All Trades, Master of None
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24351
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Code:
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Porto, Portugal
Offline Offline
Newbie
*
Karma: 1
Posts: 38
JoATMoN - Jack of All Trades, Master of None
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)...
Logged

Pages: [1]   Go Up
Jump to: