Go Down

Topic: Motor Shield Capable of Driving 5 DC motors? (Read 1 time) previous topic - next topic

Jeffro



Guessing - I haven't used one, but I'd assume that the current sensing pin gives you the opportunity to measure the current the motor is pulling, on the arduino by using analogread and doing a little math. This would let you detect when your motors are stalled.


Yes, that is typically what it is used for. It is also used for torque feedback, which some applications require.


Ok, sweet. Thanks a lot guys!

Retroplayer

The short answer is that if you don't need it, don't use it. But it may be required to terminate it. Check the datasheet for that.

Jeffro

#12
Feb 22, 2013, 04:16 pm Last Edit: Feb 22, 2013, 04:19 pm by Jeffro Reason: 1

The short answer is that if you don't need it, don't use it. But it may be required to terminate it. Check the datasheet for that.


RetroPlayer,

I got my H-Bridge in and got it all wired up to the arduino, motor and external supply. I decided not to use the current sense pin (pin 8) or the thermal flag ouput (pin 9), as I have no use for them in this project. Since I'm not going to use it, I first tried my test program with pin 8 & 9 NOT connnected to anything. The program compiled with no errors, but I got no movement with the motor. I then tried connecting the current sense output pin to ground with a 2.7kΩ resistor between the connection and ground (see pg 6 on the datasheet, as it shows a test circuit example schematic), still nothing. I have yet to try to connect the thermal flag output to anything, as I figured it really shouldn't affect the program working properly. I've checked over my circuit to make sure all the connections are correct multiple times. Is something wrong with my code that it's not running properly? (Keep in mind that the only coding that I ever really mess with is assembly for one of my classes and ladder logic for PLC's, so I'm not the best with this C++ based stuff). My code is as follows:

Code: [Select]
int pwmPin=4;//defines PWM input to LM18200
int dirPin=5;//defines direction input to LM18200
int brkPin=6;//defines break input to LM18200
int speed=127;//defines the speed of the motor (half speed)

void setup()

{

pinMode(pwmPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(brkPin,OUTPUT);

}

void forward()

//Necessary conditions to drive the motor in the forward direction
{

analogWrite(pwmPin,speed); //Sets speed of motor by PWM
digitalWrite(dirPin,HIGH); //Direction pin goes HIGH
digitalWrite(brkPin,LOW); //Brake pin is disabled

}

void reverse()

//Necessary conditions to drive the motor in the reverse direction

{

analogWrite(pwmPin,speed); //sets speed of motor by PWM
digitalWrite(dirPin,LOW); //Direction pin goes LOW, causing motor to turn opposite direciton
digitalWrite(brkPin,LOW); //Brake pin is disabled

}


void brake()
//Necessary conditions to short the motor terminals and "brake" the motor

{
analogWrite(pwmPin,speed);
digitalWrite(dirPin,HIGH);
digitalWrite(brkPin,HIGH);
}

void loop()

{
forward();
delay(4000);
brake(); //Brakes inbetween directions to avoid immediate direction chnge
delay(500);
reverse();
delay(4000);
brake();
delay(500);
}






Any suggestions?
Oh and here's the datasheet again to keep from having to hunt it down in previous posts:
http://www.datasheetcatalog.org/datasheet/nationalsemiconductor/DS010568.PDF

Thank you,
-Jeff F.

Retroplayer

Which Arduino are you using? I ask because pin 4 is not a PWM pin on any Arduino that I have used. An analogWrite to that pin will do nothing.

Code looks fine, but just one thing...

Code: [Select]

void brake()
//Necessary conditions to short the motor terminals and "brake" the motor

{
analogWrite(pwmPin,speed);
digitalWrite(dirPin,HIGH);
digitalWrite(brkPin,HIGH);
}



You should probably make that analogWrite(pwmPin,0) since you are shutting off the motor. Or just leave it out. Since you are braking, it really shouldn't matter, but it is just pointless to leave it like that.

Jeffro


It's the Uno (Soon to have a Mega 2560 subbed in for it for more pins). I'm sure that's exactly what my problem is though. I just overlooked the pin with the "~" symbol on it in my haste. I'm not at home right now, but I'll give it a whirl when I get back. And thanks for the advice on the (pwmPin, 0) portion! I've saved the adjustment. 

Thank you,
-Jeff F.

Go Up