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 27494 times)
12/05/07 at 07:05:27

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
I'm a Wiring noob, this is my first post; please excuse me if its a bit long.

I am building a small, tracked robot with a Wiring board for a brain.  At the moment it has 2 motors, for which I would like to use PWM outputs 0-3, a pot on Analog Out 0, and 8 LEDs on pins 24 through 31.

I was having problems getting PWM out while building the bot; I read some posts from August where CSMotion added an initialization  line to the setup() section that allowed output, so I tried that and it seemed to work (I still didn't have really usable hardware at that time so I moved on).

Now I have the bot built and wired and I have a problem.  When my program turns pins 29 thru 31 on, PWM comes on (29 turns on PWM 5, 30 is 4, and 31 is 3).  This despite the fact that there is no initialization line in setup(), and no analogWrite() in loop().

Can someone explain this?  I am appending the code:

// pot motor and leds

int val;                    // used to hold pot value

void setup()
{
  pinMode(24, OUTPUT);            // set the digital pins for LEDs as output
  pinMode(25, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(30, OUTPUT);
  pinMode(31, OUTPUT);
  Serial.begin(9600);             // sets the serial port to 9600
}

void loop()
{
  int i;
  for(i=24; i<32; i=i+1) {        // loop to cycle through LEDs
    digitalWrite(i, HIGH);        // sets the LED on
    val = analogRead(0);          // read analog input pin 0
    Serial.print(val, DEC);       // prints the value read
    Serial.print(" ");            // prints a space betwen the numbers
    Serial.print(i, DEC);         // prints the LED number
    Serial.print(" ");            // prints a space betwen the numbers 
    delay(500);                   // wait 100ms for next trip thru loop
    digitalWrite(i, LOW);         // turns LED off
  }
}
 
IP Logged
 
Reply #1 - 12/05/07 at 09:27:23

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
So your problem is that when you run that program, you PWM ports automaticly turn HIGH aswell

That's because the PWM ports are shot circuited to certain I/O pins.

Why not use pins 0 till 7, Those will not interfere with the PWM.

Good luck

Titus

What is the purpose of the analog in?
Are measuring something and just printing it? or are you processing that data?
Where are the motors in you program?
« Last Edit: 12/05/07 at 12:39:38 by Titus »  

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #2 - 12/05/07 at 18:19:28

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello All!

                  Here are the Pins shared with the PWM port.

Wiring Pin 29 and PWM 1
Wiring Pin 30 and PWM 2
Wiring Pin 31 and PWM 3
Wiring Pin 36 and PWM 4
Wiring Pin 37 and PWM 5
Wiring Pin 38 and PWM 6

                    I have a excel spreadsheet I made that has all the Pins and what functions they use and share.

                    I not sure how to post it.  I'll E-mail it to Hernando Barragán, He can double check it and post it if he alright with it.

Rich
 
IP Logged
 
Reply #3 - 12/05/07 at 18:56:15

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
That's a great idea actually. Making a spreadsheet.

I hope these awnsers solve your problem!

Titus
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #4 - 12/06/07 at 05:35:28

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
You've answered my question. Thanks!  I consulted the schematic today after reading the first post (at work, where I couldn't reply).
The example code was just to exercise my robot's IO devices (currently just 8 LEDs and a pot, besides the motors).
 
IP Logged
 
Reply #5 - 12/06/07 at 06:04:39

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
...but that doesn't mean I'm out of questions.  Does anyone know why the DC motor example code on the website works (it turns a motor on), but this slightly modified code doesn't?  It should turn the motor off again.  Motor keeps going.  Hmmm.

// Driving a DC Motor

int fwdpin = 0;  // forward is pin PWM 0

void setup()
{
  // nothing for setup
}

void loop() {
  analogWrite(fwdpin, 127);  // turn ON the Motor at half speed
  delay(1000);
  analogWrite(fwdpin, 0);  // turn OFF the Motor
  delay(1000);
}

 
IP Logged
 
Reply #6 - 12/06/07 at 07:28:15

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
Last post before bed.

I wanted to eliminate the motor control pcb as a possible culprit, so I put my LED bank on the PWM pins and ran this code:

// Driving DC Motors

int xfwdpin = 0;
int xrevpin = 1;
int yfwdpin = 2;
int yrevpin = 3;
int zfwdpin = 4;
int zrevpin = 5;

void setup()
{
  // nothing for setup
}

void loop()
{
  analogWrite(xfwdpin, 255);
  analogWrite(xrevpin, 255);
  delay(1000);
  analogWrite(xfwdpin, 0);
  analogWrite(xrevpin, 0);
  delay(1000);
  analogWrite(yfwdpin, 255);
  analogWrite(yrevpin, 255);
  delay(1000);
  analogWrite(yfwdpin, 0);
  analogWrite(yrevpin, 0);
  delay(1000);
  analogWrite(zfwdpin, 255);
  analogWrite(zrevpin, 255);
  delay(1000);
  analogWrite(zfwdpin, 0);
  analogWrite(zrevpin, 0);
  delay(4000);
}

The expected outcome: pairs of LEDS turning on, then off, down the bank.
The actual outcome: PWM0 will turn on, but not off.  PWM1 and PWM3 behave as expected.  PWM2 and PWM4 never light up.
So maybe I just have bad outputs.  But I make this change to the int assignments:

int xfwdpin = 1;
int xrevpin = 0;
int yfwdpin = 3;
int yrevpin = 2;
int zfwdpin = 5;
int zrevpin = 4;

...and now it's PWM1 that won't shut off, PWM0 and PWM2 that behave as expected, and PWM3 and PWM5 that won't light.  The problem didn't follow the hardware outputs, it followed the order in which they were activated by the code.

Any suggestions?
 
IP Logged
 
Reply #7 - 12/06/07 at 08:15:09

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
That's is very odd?

Are you sure that you didn't short circuit any wires?
Perhaps you can post a picture of you LED bank(im interessted)

@Barragan, all PWM port can be used at one time, can they?

I'll try my own PWM ports.

TItus
 

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

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello everyone!
         If you turn on the port anything connect will turn on.  you can not attach a motor pwm 1 and a LED to pin 29.   If you you make Pin 29 High The motor and the LED will recieve that signal.   If you look at the Board Schematic you see they are connected.  They are connected to the same pin on the processor chip.  That is why I made the spreadsheet.  I e-mailed it to Hernando yesterday.  I hope he got it. 
         If you remove all power from the wiring board and using an ohm meter you can see that pwm 1 and pin 29 have zero resistance.  Therefore they are the same connection. 
         I hope this helps.  I know that some of the wiring board users are new to electronics.  But most of the fun is in the learning process.  I have been playing around with the stuff for many years and I'm still learning. 

Rich
 
IP Logged
 
Reply #9 - 12/06/07 at 18:11:28

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello Again.
           The PWM pins?   Are they 0 through 5  or 1 through 6?   On the schematic they are listed as 1 through 6 and on the label on the board they are list as 0 through 5.   So when we use them in the software we should use 0 through 5?

  Eustace,
             are you using  MOSFETs to run your motors?  If you are what type and what type of motors are you using.  It could be that the MOSFETs are not turn off do to the current your drawing through them.  Not sure this is the answer but it may be something to look into.

Rich
 
IP Logged
 
Reply #10 - 12/07/07 at 02:59:02

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
Titus - I made the LED bank to help troubleshoot the board.  Since I consider it test equipment, I check it when I use it.  It helps in this case that I can just shift it two places and see if the pattern repeats (the bank has 8 LEDs, the PWM header has 6 pins).  I made it by soldering the anodes of the LEDs to the connector pin of an 8-position header socket, soldering a resistor to the other lead, and connecting all the resistor leads to a ground wire which connects to ground on the 4 pin power header.  I would send you a pic but a) my camera makes lousy closeups of small things and b) I haven't figured out how to post pics yet!  Have you tried your PWM outputs yet?

Vacuumdiode2 - The pins are numbered 0-5 on the board, and the example code on the site always starts with analogWrite(0, something), so that's what I've been going by:)

Everyone - some good news!  I just ran this code:

// Driving two DC Motors

int xfwdpin = 0;
int xrevpin = 1;
int yfwdpin = 2;
int yrevpin = 3;
int zfwdpin = 4;
int zrevpin = 5;

void setup()
{
  // nothing for setup
}

void loop()
{
  analogWrite(xfwdpin, 255);
  analogWrite(xrevpin, 255);
  analogWrite(yfwdpin, 255);
  analogWrite(yrevpin, 255);
  analogWrite(zfwdpin, 255);
  analogWrite(zrevpin, 255);
  delay(1000);
  analogWrite(xfwdpin, 0);
  analogWrite(xrevpin, 0);
  analogWrite(yfwdpin, 0);
  analogWrite(yrevpin, 0);
  analogWrite(zfwdpin, 0);
  analogWrite(zrevpin, 0);
  delay(1000);
}

Now all six diodes light up, then PWM1 thru PWM5 start blinking, but PWM0 stays lit.  I needed 4 PWM outputs, it looks like I have 5!
 
IP Logged
 
Reply #11 - 12/07/07 at 03:23:33

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
I celebrated too soon.   But first - Vacuumdiode2, you asked about MOSFETS and I forgot to answer.  After some experiments with L293Ds, and trying to build my own H-bridge out of a MAX620 and whatever MOSFETS I could find, I broke down and bought a Solarbotics motor driver board.  Which I disconnected once I began having problems (I've been using LEDs to troubleshoot).

I just ran this code:

// Driving two DC Motors

int sacrifice = 0;
int xfwdpin = 1;
int xrevpin = 2;
int yfwdpin = 3;
int yrevpin = 4;


void setup()
{
  // nothing for setup
}

void loop()
{
  analogWrite(sacrifice, 255);
  analogWrite(xfwdpin, 255);
  analogWrite(yrevpin, 255);
  delay(1000);
  analogWrite(xfwdpin, 0);
  analogWrite(yrevpin, 0);
  delay(1000);
}

...and I set the board up with the PWM pins 1 thru 4 going to my motor controller, and PWM 0 to an LED.  When I run the code not only does the LED go on and stay on (of course, I'm not telling it to turn off) but so does PWM 1.  Aaaargh!

So I added this line "analogWrite(sacrifice, 255);", just after the first delay.  I MEANT to add analogWrite(sacrifice, 0), and at first I thought I had, because when I ran the code the motors both started and stopped, and only the LED (PWM 0) stayed on.

So what does this mean?  Will I be able to write code for the other 4 PWM outputs if I throw in an occasional analogWrite(sacrifice, 255)?  This is just wrong.  I'm thinking of getting an Arduino, just so I can finish my bot.  Sheeesh.
 
IP Logged
 
Reply #12 - 12/07/07 at 09:24:12

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
I think arduino will not solve your problem.
Try cutting all power and start measuring if some PWM pin's are shot circuited.

Ill try my PWM pins this weekend.

Titus
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #13 - 12/07/07 at 16:16:49

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello,
           Did you Try put a scope on the PWM pins.  The LED on PWM 0 may be Pulsing at very High rate, looking like it is on all the time.  Try puting a delay between your writes and see if it helps.  I had found a kit that has a dual H-Bridge QUASAR CODE 3166 - Bidirectional DC Motor Speed Controller.  I pulled the POT off and had to make a Digital to analog converter to get a true analog out put.  I found that using different delay times I got different voltage changes.  Try puting 2 or 3 delays that add up to the total delay your looking for.  For some reason the voltage did not want to drop to zero volts and bounce between two voltage seemly never hitting zero.  I had to use both an analog meter and a digital meter.  Hope this gives some more insite.

Rich
 
IP Logged
 
Reply #14 - 12/08/07 at 09:50:19

eustace   Offline
YaBB Newbies
Building our robotic overlords
Los Angeles

Posts: 17
*
 
Titus - I really look forward to your PWM test result - this might tell me whether I have a bad board or not.

Rich - There already is a delay in the code, this is why the LEDs blink.  I haven't scoped the output yet, mostly because I've been concentrating on finishing the hardware (I haven't actually turned it on at all tonight, but I did build, install, and wire the four bumpers!  It's almost a robot!).  The question I need to settle is whether my board is bad, or alternatively, whether the PWM firmware problems mentioned in the forums from Wiring 11 & 12 still haven't been fixed.  When Titus tries my code on his board I will know this.  The problem I have is that the different ports behave differently from each other; some can turn on and off using code like the examples from the website, but others can't.  The pattern of can/can't doesn't stay fixed to the particular hardware ports, so I must surmise that either my firmware is corrupt or Wiring 13 still has a PWM problem.
And I hope you weren't suggesting that I generate "PWM"-like intervals using code!  I believe that one of the posters I was referring to did that, but like him, I don't consider that a solution.  I need PWM that runs without that kind of caretaking, or I'll never be able to develop fast enough code to implement my ideas.

Once again, thanks for your help, both of you.
 
IP Logged
 
Pages: 1 2 3