Go Down

Topic: (Sorted) L298N Speed Control Issue (Read 17972 times) previous topic - next topic

CyberBob

Aug 01, 2013, 12:38 pm Last Edit: Aug 02, 2013, 05:01 pm by CyberBob Reason: 1
I have a L298N Dual H Bridge DC Stepper Motor Board and I've successfully connected a Meccano 6V reversable motor to it. Using the code below, the motor spins one way and then the other (so far, so good):

Code: [Select]

void setup()
{  
 pinMode(13, OUTPUT);    // Set Pin 13 as output, this is the direction control
 delay(3000);            // Wait 3 seconds before we start
}

void loop()
{
 digitalWrite(13, HIGH); // Set direction as forward
 analogWrite(9, 255);    // Set the speed as full
 delay(1000);            // Wait a second

 analogWrite(9, 0);      // Set the speed to stop
 delay(1000);            // Wait a second

 digitalWrite(13, LOW ); // Set direction as reverse
 analogWrite(9, 127);    // Set the speed as half speed
 delay(1000);            // Wait a second

 analogWrite(9, 0);      // Set the speed to stop
 delay(1000);            // Wait a second
}


When I alter the speed to say 70 (from 255) in the first part of the void loop (),

Code: [Select]
 digitalWrite(13, HIGH); // Set direction as forward
 analogWrite(9, 70);    // Set the speed as full
 delay(1000);            // Wait a second


the motor still runs at a very high speed. I need the motor to run at low speeds in either direction.

Any help would be appreciated greatly.



jack wp

try smaller numbers.

analogWrite(9, 10);
analogWrite(9, 5);
analogWrite(9, 1);
analogWrite(9, 0);
Do they slow it down, or make it stop?

CyberBob

Thanks for getting back to me.

When I change the analogWrite(); to lower numbers, there is no noticeable difference in the speed of the motor. Only when I change the delay(1000); to a lower figure do I notice a slower rotation. My understanding is that the motor should spin at the pre-determined speed, irrespective of the delay; the delay being there to determine the length of time the motor turns at the analogWrite(); speed.

jack wp

so, analogWrite(9, 0); did not stop the motor?
Sounds like then you can only control the direction. You can't turn it off?

What pins on the L298N do you connect arduinos pin 9 ? I would look at it again, as I sometimes get my wires crossed. LOL

Infact if you can easily show the schematic would be good.

CyberBob

If I run the following code, the motor runs at what I think is near full speed in one direction and then slower (half speed?) in the other direction (very strange as the first part should stop the motor)

Code: [Select]
void setup()

  pinMode(13, OUTPUT);    // Set Pin 13 as output, this is the direction control
  delay(3000);            // Wait 3 seconds before we start
}

void loop()
{
  digitalWrite(13, HIGH); // Set direction as forward
  analogWrite(9, 0);    // Set the speed as full
  delay(1000);            // Wait a second

  analogWrite(9, 0);      // Set the speed to stop
  delay(1000);            // Wait a second

  digitalWrite(13, LOW ); // Set direction as reverse
  analogWrite(9, 127);    // Set the speed as half speed
  delay(1000);            // Wait a second

  analogWrite(9, 0);      // Set the speed to stop
  delay(1000);            // Wait a second
}




jack wp

So sounds like you do have speed control.
Maybe the speed is inverted from what we think.
Your last code did not send a high number, just a low number, so try sending a high number at one point.

No schematic easily available?

CyberBob

Hi

I have tried low and high numbers in the first part of the code (forward) with no discernable difference in the speed of the motor.

When I put in smaller numbers for the second part (reverse) this does reduce the speed.

Sorry, I don't have a means of posting a diagram, though the board that I have is the same as this one:

http://www.ebay.co.uk/itm/Dual-H-Bridge-DC-Stepper-Motor-Drive-Controller-Board-Module-Arduino-L298N-236-/200902260723?pt=UK_BOI_Industrial_Automation_Control_ET&hash=item2ec6b537f3#ht_6339wt_958






jack wp

What is pin 9 connected to?

CyberBob

Pin 9 to   IN 2
Pin 13 to IN 1

jack wp

Pin 9 should go to Enable (speed can be changed by PWM the enable)
The L298N looks for two signals to determine direction (status)

As follows


EnA   IN 1   IN 2   Status
1   1   0   Forward
1   0   1   Reverse
1   0   0   Brake
0   X   X   Stop

CyberBob

The ENA 1 (A Enable) enables the IN 1 and IN 2 to be enabled i.e Motor 1. My motor only has 2 wires and they are attached to OUT 1 and OUT 2 (output A) so that the current can run one way or the other (H Bridge board does this).

jack wp

Just talking about side A


IN1 and IN2 combined will control the direction.
Enable, can be pulsed (PWM) to control the speed.

Does your board have two enables, one for side A, and one for side B ?
Does it have IN1, IN2 for side A?
Does it have IN3, IN4 for side B?

You are just using side A now, right?

CyberBob

Yes, just talking about side A

The board has two enables, one for side A, and one for side B
It has IN1, IN2 for side A
and it has IN3, IN4 for side B

Yes, I am just using side A now

jack wp

Great, we are getting close now.

You need to use 3 outputs from the arduino.
How about:
D9   to enable A  (use PWM to adjust speed here)
D12 to IN 1  ( look at the chart below to set D12 (IN 1), and D13( IN 2) to get the Status you want )
D13 to IN 2   "

EnA   IN 1   IN 2   Status
1       1        0   Forward
1       0        1   Reverse
1       0        0   Brake
0       X        X   Stop

CyberBob

On the board. the Enable has (for the want of a better phrase) a plastic jumper. I thought this has to be in place to enable the outputs to the motor.

There are 2 of these jumpers, one for IN2, IN2 (for motor A) and one for IN2, IN4 (for motor B). Can you see these on the images on the link that I posted?

Go Up