Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumWiring HardwareTroubleshooting › PWM problem in 13?

Pages: 1 2 3 
PWM problem in 13? (Read 27563 times)
Reply #15 - 12/08/07 at 12:30:22

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
I THINK I FOUND IT!!!

When you use PWM, you turn it on like this

analogWrite(1, 1000);
analogWrite(0, 1000);


In this case, only led 1 turns on...

I thought it was the processor that coudn't handle it. so i change it to this:

analogWrite(1, 1000);
delay(1);
analogWrite(0, 1000);


Guess what, both leds turned on!!


void setup() 

  // nothing for setup 
}

void loop() 

  analogWrite(1, 1000);
  delay(1);
  analogWrite(0, 1000);
  delay(200);
  analogWrite(1, 0);
  delay(1);
  analogWrite(0, 0);
  delay(200);



DAMN, i tried this code:


void setup() 

 
}

void loop() 

  analogWrite(0, 255);
  delay(1);
  analogWrite(1, 255);
  delay(1);
  analogWrite(2, 255);
  delay(1);
  analogWrite(3, 255);
  delay(1);
  analogWrite(4, 255);
  delay(1);
  analogWrite(5, 255);
  delay(1);
  delay(1000);
  analogWrite(0, 0);
  delay(1);
  analogWrite(1, 0);
  delay(1);
  analogWrite(2, 0);
  delay(1);
  analogWrite(3, 0);
  delay(1);
  analogWrite(4, 0);
  delay(1);
  analogWrite(5, 0);
  delay(1);
  delay(1000);



And it did not run like it should...
Led 0 stays on...
(actually, I ran that code with just 3 leds, on pin 0,1,3.

when i try the same code on the leds 1,2,4, it works aswell, just like 2,3,5)

It seems that only pin 0 stays on.)

It seems to me, that there is a little bug in the software, instead of the hardware,

Why would my first program work, and my second not.
But then again, why would only pin 0 stay on..?

I hope this helps.

Anyway, if you sacrefice PWM pin 0, you it will work. i think.

@Barragan, could you help us out?

Titus

@Eustace Don't give up!, we can do it!
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #16 - 12/08/07 at 17:06:59

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
Thanks, Titus!  It's a relief to find that I'm not seeing a problem unique to my particular board, that others are affected, too.  Hopefully we can get a fix into the next revision (although considering the persistence of PWM bugs this may be optimistic).  I posted a comment in the Bugs section of the forum.  I'm afraid that if Barragan looked in on this thread he may have stopped when he saw my confusion over the cross-connected pins.  After all, you guys straightened me out on that pretty well without his help.
Anyway, I can keep troubleshooting my bot, just by sacrificing one PWM.  But I'm worried that as my code becomes more complex that will prove to be a poor workaround!
 
IP Logged
 
Reply #17 - 12/08/07 at 19:05:17

Kars   Offline
YaBB Newbies
Team Vossius
Amsterdam

Posts: 19
*
 
Hi,

Maybe you could try the value '1' for your pwm command instead of '0'
So it would be like:

analogWrite(ledpin, 1);
 

Buildig the same as Titus ^^
IP Logged
 
Reply #18 - 12/09/07 at 19:36:05

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Please try this example on each individual PWM output pins 0-5 and let me know on the results. http://wiring.org.co/learning/examples/led_fade.html
 
IP Logged
 
Reply #19 - 12/09/07 at 21:00:13

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
I tried that example code for all the PWM pin's from 0 to 5

Although i tried it without the 200 ohm resistor, all the PWM ports worked

This is not the problem barragan,

It is something with the software, when analogwriting 2 PWM ports.

Hope this helps.

Titus
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #20 - 12/11/07 at 06:26:24

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
could you post the minimum code possible that replicates the problem?
 
IP Logged
 
Reply #21 - 12/11/07 at 15:49:08

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
I'll try (I tried twice last night but Firefox kept crashing when I tried to type in the reply window?!?).
The shortest piece of code that shows there is a problem would be this (a modification to your DC motor example code):

// Driving a DC Motor
// by BARRAGAN <http://barraganstudio.com>

int motorpin = 0;  // L293D Pin En1 connected to pin PWM 0

void setup()
{
  // nothing for setup
}

void loop() {
  analogWrite(motorpin, 125);  // turn ON the Motor at medium speed
  delay(1000);
  analogWrite(motorpin, 0);  // turn the Motor OFF
  delay(1000)    
}

If I run this, the PWM output never shuts off.

By the way, I posted some code examples to the Bugs forum, did you try those?
 
IP Logged
 
Reply #22 - 12/11/07 at 16:24:38

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
ok, I´ll try this, but i recall the motor I used before to do the test needed some time to fully stop, 1 second wasn't enough for it to stop completely.
 
IP Logged
 
Reply #23 - 12/11/07 at 16:52:56

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
Perhaps 0 isn't off.

I know someone, who had to use 127 as the 0 position....

@barragan, that won't explane why a led will not turn off, a led reacts way faster then a DC motor...
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #24 - 12/11/07 at 17:40:15

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
Titus - Regarding motors - "off" can just mean a PWM value low enough that the motor can't run at that voltage level, but that's not what I need.  I need OFF, no voltage - if I can't turn the PWM ouput pin all the way off, I have problems with bidirectional motor control (motor controller circuits can be explosively unhappy with both a forward and a reverse signal, even if one is very low).

Barragan - As for the speed with which a motor reacts - once I realized I had a problem I stopped running my examples with the motor controller hooked up, and started running them with a bank of LEDs on those pins instead (so I didn't have to worry about blowing up my motor controller by accidently sending both FWD and REV signals).  The LEDs turn on and off instantly, so motor momentum doesn't really play a part in the troubleshooting I've been doing.  If you are using motors to run the code example I sent, just bump the delay(1000) up to delay(10000).  The result should be the same, assuming you can duplicate my problem.

 
IP Logged
 
Reply #25 - 12/22/07 at 18:19:49

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
Hi - late to this discussion but I've had similar problems using PWM to control a DC motor through an h-bridge (posted @ this in another section of the forum).

What I found was that in order to have an analogWrite() command take effect on a PWM pin, I had to make the call twice -

analogWrite(pinNum, 0)
analogWrite(pinNum, valueDesired)

Didn't fill me with great confidence but it seemed to work. Perhaps this has already been discovered/discussed. (this was with v13 btw)

--Roy
 
IP Logged
 
Reply #26 - 12/23/07 at 10:01:18

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
that could be a solution.
then the " analogWrite(pinNum, 0); " command would be the "sacrifice pin"

Im gonna try this with the programs that bug.

by the way, this is actually a wiring 0012 bug:
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1185988954/2#2

Thanks!

Titus


EDIT!

Yep, something strange is going on:

void setup() 

   
}

void loop() 

  analogWrite(0, 0);
  analogWrite(0, 255);
  analogWrite(1, 255);
  analogWrite(2, 255);
  delay(1000);
  analogWrite(0, 0);
  analogWrite(0, 0);
  analogWrite(1, 0);
  analogWrite(2, 0);
  delay(1000);
}   


Works fine.
same as this program:

void setup() 

   
}

void loop() 

  analogWrite(0, 0);
  analogWrite(0, 255);
  analogWrite(1, 0);
  analogWrite(1, 255);
  analogWrite(2, 0);
  analogWrite(2, 255);
  delay(1000);
  analogWrite(0, 0);
  analogWrite(0, 0);
  analogWrite(1, 0);
  analogWrite(1, 0);
  analogWrite(2, 0);
  analogWrite(2, 0);
  delay(1000);
}   


I think, Barragan:
Could you modify the analogWrite command as following:

when you use the analogWrite command,  it writes a value(from 0 to 255) to the pin.
in stead of doing that,
it should first write 0 to that pin, and than the value named in the program.

I hope this workes, it seems to work for me.
actually it is the same, but in stead of doing it in a program like this:
  analogWrite(0, 0);
  analogWrite(0, 255);

you only type:
  analogWrite(0, 255);
and it actually sets that pin to 0 first.

Not the best way to do this, but a temporary way.

 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #27 - 12/23/07 at 18:50:48

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
Definitely there is a bug there and seems to be related to PWM pin 0 specifically, it will be out of there for 0014 thanks you all for the help. I´ll post more as soon as I have more information on the fix. For those experts remember the source code for the PWM is here: http://wiring.uniandes.edu.co/source/trunk/wiring/core/WTimer.c?revision=394&view=markup
 
IP Logged
 
Reply #28 - 12/24/07 at 00:34:19

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi guys, ok got it out, nasty bug, now seems to be working fine, I tried the code you post and now the led blinks on PWM output 0. I´d also like to introduce here another theme which is the resolution of the PWM, right now it is 8 bit resolution, which means you could use values between 0 and 255, for a long time I´ve been thinking of making it 10 bit resolution to equals the analogRead command which will means values between 0-1023, I´d like to hear your thoughts on this.
Additionally I´ve been thinking of enabling the use of the real pin numbers using analogWrite, right now the pins are separated as a port called PWM on the board with pins numbered from 0 to 5, this to make things easier and comprehensible for novices but those pins are just pins 37, 36, 35, 31, 30 and 29 of the digital I/O pins in that order,
but, Wiring mini si coming soon, perhaps in late January and it doesn´t have (because of space) a special PWM section, so PWM is expected to be available on those digital I/O pins directly. (Any thoughts on this?)
Thank you all for the help.
(btw I have updated the svn repository with the fix)
 
IP Logged
 
Reply #29 - 12/24/07 at 11:22:10

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
-The problem
How did you fix it? what was wrong?

-PWM, a 10 bits resolution
Since I'm used to use values from 0-1023 as PWM output, i think it is a great idea!

-Just the digital I/O pin's as the PWM, in stead of a seperated PWM port
That would not envolve the owner's of the latest wiring board, would it.
In case it would, it would only affact the software, you won't be able to analogWrite(//value from 0 to 5);? or you can add a
"select your wiring board version"menu, and let the software/compiler automaticly change the 0-5 to the matching digital port
In case of a new Wiring board version, i like what arduino did, when numbering the digital I/O pin's they put a little P 
(I thought) under the I/O pins matching the PWM pins


-Wiring mini
COOL STUFF!, we want more information about the mini!

-wiring 0014
software version update? or just a libery update?


yeah, 40 posts!
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Pages: 1 2 3