0

Stepper Speed limitations with MotorShield v2?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Wed Jul 16, 2014 1:53 pm

Hello Adafruit folks,

I'm working on a project to run two different stepper motors off the MotorShield v2. The setup currently is very simple:

    the MotorShield v2 is placed ontop of an Arduino Uno v3
    AC/DC Switching Adaptor into the power jack of the Arduino board, rated for 12V/5.0Amps

I went into the twi.h library and changed the

#define TWI_FREQ 100000L
to
#define TWI_FREQ 400000L

The code I wrote looks like this:

Code: Select all | TOGGLE FULL SIZE
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

// Connect two steppers
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(513, 2);

// wrappers for the first motor
void forwardstep1() { 
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  myStepper1->onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor
void forwardstep2() { 
  myStepper2->onestep(FORWARD, SINGLE);
}
void backwardstep2() { 
  myStepper2->onestep(BACKWARD, SINGLE);
}

AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()

  AFMS.begin(); // Start the shield
 
  stepper1.setSpeed(250);
  stepper2.setSpeed(500);
}

void loop()
{
  stepper1.runSpeed();
  stepper2.runSpeed();
}



The problems I'm having:

    The motors cannot seem to get to 60RPM at all... At most, it seems like 50RPM is the limit?
    The motors cannot go above stepper1.setSpeed(250) & stepper1.setSpeed(500) without odd skipping rotation behavior?
    How did Adafruit MAX at 80RPM out of their 12VDC 32-Step 1/16 Gearing (http://www.adafruit.com/product/918) motor? What was the code and wiring setup?
    I was hoping to use "TWBR = ((F_CPU /400000l) - 16) / 2;" in setup() instead of editing the twi.h file, but it doesn't seem to work, am I missing something?

Help would be greatly appreciated.
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Wed Jul 16, 2014 1:58 pm

Also, if it helps, the wiring of the Adafruit stepper (http://www.adafruit.com/product/918) to the M3 and M4 ports looks like this (left to right):

Code: Select all | TOGGLE FULL SIZE
        M3            GND            M4
[ Blue ] [ Yellow ] [ RED ] [ Orange ] [ Pink ]


Does it matter where, for example, the Blue & Yellow wires go in M3 (order)?
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Wed Jul 16, 2014 3:48 pm

There is an upper limit to the step rate on the shield. Either method of changing the clock rate should work.
I will be running some tests later this week to figure out what the actual step-rate limits are.

AccelStepper adds some overhead and slows things down further. And running two steppers simultaneously forces them to share the available i2c bandwidth. At some point, they will start to interfere with each other.

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 9:43 am

Hi Bill, were you able to figure out actual step-rate limits?

Would optimizing Adafruit's code (by removing microsteps for example) help to increase the steps-per-second?

Also was curious how Adafruit got 80RPM on the 12V 32-Step 1/16 Gearing (http://www.adafruit.com/product/918)?
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Mon Jul 21, 2014 10:11 am

Not finished testing just yet.

You can increase the max step rate by removing the microstepping PWM code. Obviously, you lose microstepping when you do that.

As for the 80RPM. I suspect that the testers observed that it worked at the 80 RPM setting. They probably did not measure the actual output RPM.

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 10:25 am

Thank you Bill!

Is there code you/they could share that would help me understand if I'm getting the same results for 80RPM? Somehow, it seems with no added code other than the sketch example, I cannot get more than a constant 50RPM.

I appreciate your help!
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Mon Jul 21, 2014 11:52 am

When you specify 80 RPM, does the motor turn?

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 12:46 pm

Bill - could you share with me the code that you'd use to turn it at 80RPM if that be the case? Right now, this is the code example I pulled from Adafruits library (ConstantSpeed.pde):

Code: Select all | TOGGLE FULL SIZE
// ConstantSpeed.pde

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(513, 2);

void forwardstep1() { 
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  myStepper1->onestep(BACKWARD, SINGLE);
}

AccelStepper Astepper1(forwardstep1, backwardstep1); // use functions to step

void setup()

   Serial.begin(9600);           // set up Serial library at 9600 bps
   Serial.println("Stepper test!");
 
  AFMS.begin();  // create with the default frequency 1.6KHz

  Astepper1.setSpeed(50);   
}

void loop()

   Astepper1.runSpeed();
}


If I set the function to Astepper1.setSpeed(80), it turns really really slow, taking about 7 seconds to turn.
If I set the function to Astepper1.setSpeed(513), it turns slow than anticipated, taking about 1.5 seconds to turn.
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 12:50 pm

Also, for the test above, I had the "#define TWI_FREQ " = 100000L.
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Mon Jul 21, 2014 12:55 pm

could you share with me the code that you'd use to turn it at 80RPM

I have never confirmed that test.

If the motor turns at 80 RPM, then you have most likely reproduced the original tester's results:
I suspect that the testers observed that it worked at the 80 RPM setting. They probably did not measure the actual output RPM.

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 1:00 pm

Okay, I guess the question is if the library that Adafruit provides (ConstantSpeed.pde - as noted above) interprets speed as RPM when using the function "setSpeed()"?
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Mon Jul 21, 2014 1:07 pm

It does. However, the actual speed achievable is limited by the i2c bandwidth.

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 1:13 pm

I guess ultimately, I've been looking at the code on your website where the DC Motor has been advertised (https://www.adafruit.com/product/918):

"Then just use the example code that comes with the Adafruit Motor Shield library and set the constructor to Adafruit_StepperMotor *myMotor = AFMS.getStepper(513,motornum) and the speed at 5 RPM by calling motor->setSpeed(5)."

As a result, I don't get anywhere near 5 RPM. I get one rotation within 1 minute and 45 seconds. I'm just trying to figure out what I'm doing wrong or if this is misleading.
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by mccarthybergeron on Mon Jul 21, 2014 1:17 pm

Again, my setup is straight forward,

Arduino Uno
Motor Shield v2
Small Reduction Stepper Motor - 12VDC 32-Step 1/16 Gearing
Power coming from a 12V 5AMP adapter
Wires leading from stepper motor to M3 and M4 ports on motor shield that are no longer than 6 inches.

And the code used is default ConstantSpeed.pde with the only modification being "Astepper1.setSpeed(5)" instead of "Astepper1.setSpeed(50)".

Code: Select all | TOGGLE FULL SIZE
// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
// Requires the Adafruit_Motorshield v2 library
//   https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
// And AccelStepper with AFMotor support
//   https://github.com/adafruit/AccelStepper

// This tutorial is for Adafruit Motorshield v2 only!
// Will not work with v1 shields

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep1() { 
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  myStepper1->onestep(BACKWARD, SINGLE);
}

AccelStepper Astepper1(forwardstep1, backwardstep1); // use functions to step

void setup()

   Serial.begin(9600);           // set up Serial library at 9600 bps
   Serial.println("Stepper test!");
 
  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz

  Astepper1.setSpeed(5);   
}

void loop()

   Astepper1.runSpeed();
}
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

by adafruit_support_bill on Mon Jul 21, 2014 1:27 pm

If you call oneStep() 513 times, does it make a complete rotation?

adafruit_support_bill
 
Posts: 72790
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.