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 Motor Control Issue

Page Index Toggle Pages: 1
PWM Motor Control Issue (Read 9987 times)
01/23/07 at 07:54:15

CSMotionControl   Offline
YaBB Newbies
Hey, did you get any mail
for Willie Nelson?

Posts: 16
*
 
All,

I'm having a heck of a time here, and thought I'd see if you have any suggestions.   Grin

So.  I am attempting to drive a 754410 ti motor controller chip with the Wiring board.  There are two direction pins (one high one low, or vice versa) and an Enable pin, which I should be able to just transmit a PWM signal to.  I have checked the board and run with the enable connected to a digital pin that I arbitrarily flip high and low, so I know the circuit works, yet when I try to run the following code:

int PWMLEFT = 5;
int POSLEFT1 = 39;
int POSLEFT2 = 38;

void setup() {
 pinMode(POSLEFT1, OUTPUT);
 pinMode(POSLEFT2, OUTPUT);
}

void loop() {
 //Forward?
 digitalWrite(POSLEFT1, LOW);
 digitalWrite(POSLEFT2, HIGH);
 analogWrite(PWMLEFT, 50);
}

I get this really inconsistant behavior.  Sometimes the controller runs full out, sometimes nothing.  Any ideas?

Thanks!
 
IP Logged
 
Reply #1 - 01/24/07 at 03:32:16

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
I didn't look too closely, but try putting a 1-second delay in your loop()
 
IP Logged
 
Reply #2 - 01/24/07 at 04:07:10

CSMotionControl   Offline
YaBB Newbies
Hey, did you get any mail
for Willie Nelson?

Posts: 16
*
 
Alan,

I tried implementing the delay with the following:

int PWMLEFT = 5;
int POSLEFT1 = 39;
int POSLEFT2 = 38;

void setup() {
 pinMode(POSLEFT1, OUTPUT);
 pinMode(POSLEFT2, OUTPUT);
}

void loop() {
 //Forward?
 digitalWrite(POSLEFT1, LOW);
 digitalWrite(POSLEFT2, HIGH);
 analogWrite(PWMLEFT, 0);
 delay(1000);
 
 digitalWrite(POSLEFT1, HIGH);
 digitalWrite(POSLEFT2, LOW);
 analogWrite(PWMLEFT, 255);
 delay(1000);
}

It still results in basically full speed operation in each direction for 1 second.  (Yah, I know the 0 PWM should result in nothing, I just wanted to illustrate the bizarre behavior I am getting.

I'm a little bummed about this, and hoping to find a solution where I don't have to implement any delay (I'm trying to develop a control loop that I can run faster than 1khz).

I don't think I'm overwriting active pins, but I'm not 100% sure on that.

Any ideas?
 
IP Logged
 
Reply #3 - 01/24/07 at 04:30:48

CSMotionControl   Offline
YaBB Newbies
Hey, did you get any mail
for Willie Nelson?

Posts: 16
*
 
All,

In an attempt to work around this problem I came up with this.  Still not so happy about this solution as it hacks up about 10ms of my control loop time (not cool), but I came up with this:

int PWMLEFT = 7;
int POSLEFT1 = 39;
int POSLEFT2 = 38;

void setup() {
  pinMode(POSLEFT1, OUTPUT);
  pinMode(POSLEFT2, OUTPUT);
  pinMode(PWMLEFT, OUTPUT);
}

void loop() {
  //Forward?
  digitalWrite(POSLEFT1, LOW);
  digitalWrite(POSLEFT2, HIGH);
 
  digitalWrite(PWMLEFT,LOW);
  delay(7);
  digitalWrite(PWMLEFT, HIGH);
  delay(3);
}

Doing this works.  So I am stumped as to why the PWM won't work.  My next steps will be to run the delay on a delayMicroseconds() level...
 
IP Logged
 
Reply #4 - 01/26/07 at 00:41:30

CSMotionControl   Offline
YaBB Newbies
Hey, did you get any mail
for Willie Nelson?

Posts: 16
*
 
All,

I scoped the analog output of my Wiring board, and the output is just a crazy noisy signal centered about 0volts.  No change to the PWM value modifies the signal.  I'm stumped.

I've got my ground connected to the ground of the board, and it is just driving me nuts.  This is probably why I couldn't drive the Hbridge.

Any thoughts?
 
IP Logged
 
Reply #5 - 01/27/07 at 05:55:40

CSMotionControl   Offline
YaBB Newbies
Hey, did you get any mail
for Willie Nelson?

Posts: 16
*
 
All,

A new update on the issue.  Powering the board off of external supply, I get a analog signal out, powering the board off of USB, nothing.  The new problem is this.  I use this code:
int MOTOROUTPUT = 50;

int ENABLELEFT = 2;
int POSLEFT1 = 39;
int POSLEFT2 = 38;

int ENABLERIGHT = 3;
int POSRIGHT1 = 37;
int POSRIGHT2 = 36;

void setup() {
  pinMode(POSLEFT1, OUTPUT);
  pinMode(POSLEFT2, OUTPUT);
  pinMode(POSRIGHT1, OUTPUT);
  pinMode(POSRIGHT2, OUTPUT);
}

void loop() {

  digitalWrite(POSLEFT1, HIGH);
  digitalWrite(POSLEFT2, LOW);
  digitalWrite(POSRIGHT1, HIGH);
  digitalWrite(POSRIGHT2, LOW);
 
  analogWrite(ENABLELEFT, MOTOROUTPUT);
  analogWrite(ENABLERIGHT, MOTOROUTPUT);
  delay(250);
}

and I get an analog signal out on analog pin 3, but nothing on 2, any ideas?
 
IP Logged
 
Reply #6 - 01/27/07 at 06:20:40

Alan_Kilian   Offline
Full Member
Wiring? It looks like
Java to me.

Posts: 118
***
 
There's definately something VERY broken in wiring-0011

When I take the fading led example sketch and add a single line in setup
to set an output pin, the PWM output stops running.

I think Hernando needs to take a look at this.

If you uncomment out the line in setup, the PWM stops.

// Fading LED
// by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>

// Demonstrates the use of analog output pins (PWM) by dimming
// a light (LED) from off to maximum intensity and back.

// Created 5 February 2004

int value = 0;                            // variable to keep the actual value
int ledpin = 0;                           // light connected to analog pin 0

void setup()
{
  // nothing for setup
  // pinMode(1,OUTPUT);
}

void loop()
{
  for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
  {
    analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
    delay(30);                            // waits for 30 milli seconds to see the dimming effect
  }
  for(value = 255; value >=0; value-=5)   // fade out (from max to min)
  {
    analogWrite(ledpin, value);
    delay(30);
  } 
}
 
IP Logged
 
Reply #7 - 01/27/07 at 22:53:02

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
I've checked on the example, yes there is something odd there, but it's not just 0011 it comes from long ago. In the meantime, here there is a workaround to this problem, make a call to analogWrite with any value in the setup method before calling any other function. We'll get this bug out for 0012.

int ledpin = 0;                           // light connected to analog pin 0

void setup()
{
 //
 // nothing for setup
 analogWrite(ledpin, 255);
 pinMode(48, OUTPUT);
 digitalWrite(48, HIGH);
}

void loop()
{
 for(int value = 0 ; value <= 255; value+=5) // fade in (from min to max)
 {
   analogWrite(ledpin, value);           // sets the value (range from 0 to 255)
   delay(30);                            // waits for 30 milli seconds to see the dimming effect
 }
 for(int value = 255; value >=0; value-=5)   // fade out (from max to min)
 {
   analogWrite(ledpin, value);
   delay(30);
 }  
« Last Edit: 01/28/07 at 10:17:16 by barragan »  
IP Logged
 
Page Index Toggle Pages: 1