Stepper Speed limitations with MotorShield v2?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Yes it does.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

So the gearing is correct.

In the code you posted, you are using AccelStepper to drive the motor. As I mentioned earlier, AccelStepper adds some overhead of its own which we do not control. It also (as the name suggests) uses acceleration to produce smooth motion. If you set a speed and tell it to move a motor, it will gradually accelerate to the specified speed, so it will take longer to reach the programmed RPM.

mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Have you figured out the stepper-rate limits by any chance? Was hoping to find out this before moving onto a different strategy.

mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Also, judging by your prior remarks, a stepper with a 7.5 degree step vs 1.8 degree step (assuming V, Amps, etc are equivalent) will be able to achieve a higher RPM on this shield since the PPS (Pulse Per Second) would be the same? And from what I understand, the Motor Shield delivers a constant voltage and applies a variable amount of current to turn the stepper one step? And the current delivered to the device, is that "automatically" determined when we issue the command oneStep()?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

Have you figured out the stepper-rate limits by any chance?
I have a couple of other projects on the bench that I need to finish up before I can get to it. Possibly sometime this week.
a stepper with a 7.5 degree step vs 1.8 degree step (assuming V, Amps, etc are equivalent) will be able to achieve a higher RPM on this shield
That is true of any shield or driver. Whether limited by communication bandwidth or phase inductance, all driver/motor systems have a step-rate limit. All else being equal, a low-step count motor can be driven to higher RPMs.
from what I understand, the Motor Shield delivers a constant voltage and applies a variable amount of current to turn the stepper one step? And the current delivered to the device, is that "automatically" determined when we issue the command oneStep()?
That is true for microstepping mode. The shield generates a pseudo sine-wave microstep profile via PWM. In all other stepping modes, the shield applies a constant voltage. The actual current draw is a function of the phase impedence and will be lower at higher step-rates.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

OK. Some preliminary numbers:

Based on the default i2c clock-rate, the maximum step-rate in DOUBLE step mode is ~263 steps/second.

mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Huh - that seems to be pretty close to what I get. Do you plan on modifying the bus speed to see the performance step difference?

Thanks again for your time with this.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

With the i2c bus speed increase, I get 773 steps/sec. I think there is still room for improvement by eliminating the microstep overhead.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

And some more numbers:

With the microstepping PWM overhead stripped out, the max step rate is 1161 steps/second.
I was not able to get the #324 200-step motor to run at that speed : https://www.adafruit.com/products/324
I had to slow the step rate down to about 830 steps/second. (Any faster and it would start missing steps) That translates into about 250 RM.

Mind you, that is right at the limit for this particular motor powered by a good stiff bench supply @12v. Your mileage may vary.

To replicate this, you need to hack the library a bit.

Add this function prototype to the Adafruit_StepperMotor class in Adafruit_MotorShield.h

Code: Select all

  uint8_t quickstep(uint8_t dir);
Then add this function to the end of Adafruit_MotorShield.cpp

Code: Select all


uint8_t Adafruit_StepperMotor::quickstep(uint8_t dir) {
  uint8_t a, b, c, d;
  uint8_t ocrb, ocra;

  ocra = ocrb = 255;

  // DOUBLE step only

    if (! (currentstep/(MICROSTEPS/2) % 2)) { // we're at an even step, weird
      if (dir == FORWARD) {
	currentstep += MICROSTEPS/2;
      } else {
	currentstep -= MICROSTEPS/2;
      }
    } else {           // go to the next odd step
      if (dir == FORWARD) {
	currentstep += MICROSTEPS;
      } else {
	currentstep -= MICROSTEPS;
      }
    }
  
  currentstep += MICROSTEPS*4;
  currentstep %= MICROSTEPS*4;

#ifdef MOTORDEBUG
  Serial.print("current step: "); Serial.println(currentstep, DEC);
  Serial.print(" pwmA = "); Serial.print(ocra, DEC); 
  Serial.print(" pwmB = "); Serial.println(ocrb, DEC); 
#endif

  // release all
  uint8_t latch_state = 0; // all motor pins to 0


    switch (currentstep/(MICROSTEPS/2)) {
    case 0:
      latch_state |= 0x1; // energize coil 1 only
      break;
    case 1:
      latch_state |= 0x3; // energize coil 1+2
      break;
    case 2:
      latch_state |= 0x2; // energize coil 2 only
      break;
    case 3:
      latch_state |= 0x6; // energize coil 2+3
      break;
    case 4:
      latch_state |= 0x4; // energize coil 3 only
      break; 
    case 5:
      latch_state |= 0xC; // energize coil 3+4
      break;
    case 6:
      latch_state |= 0x8; // energize coil 4 only
      break;
    case 7:
      latch_state |= 0x9; // energize coil 1+4
      break;
    }

#ifdef MOTORDEBUG
  Serial.print("Latch: 0x"); Serial.println(latch_state, HEX);
#endif

  if (latch_state & 0x1) {
   // Serial.println(AIN2pin);
    MC->setPin(AIN2pin, HIGH);
  } else {
    MC->setPin(AIN2pin, LOW);
  }
  if (latch_state & 0x2) {
    MC->setPin(BIN1pin, HIGH);
   // Serial.println(BIN1pin);
  } else {
    MC->setPin(BIN1pin, LOW);
  }
  if (latch_state & 0x4) {
    MC->setPin(AIN1pin, HIGH);
   // Serial.println(AIN1pin);
  } else {
    MC->setPin(AIN1pin, LOW);
  }
  if (latch_state & 0x8) {
    MC->setPin(BIN2pin, HIGH);
   // Serial.println(BIN2pin);
  } else {
    MC->setPin(BIN2pin, LOW);
  }

  return currentstep;
}

Call "onestep(FORWARD, DOUBLE);" once in your setup function to initialize the PWM to 100%. Then call "quickstep(FORWARD);" in your loop. You can adjust the delayMicroseconds to control the speed.

Code: Select all

void loop() 
{
  long start = millis();
  for (int i = 0; i < 10000; i++)
  {
    myMotor2->quickstep(FORWARD);
    delayMicroseconds(325);
  }
  Serial.println(millis() - start);
}

mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Bill - you rock. I'll be playing with this very soon. Thanks again for your support.

BTW - kudos to the person who came up with the resistor form submission catcher. Great metaphor and pun, and just cool all around.

karpukhin
 
Posts: 7
Joined: Sun Jul 06, 2014 11:50 am

Re: Stepper Speed limitations with MotorShield v2?

Post by karpukhin »

Bill, thank you. Could you also post the code and instruction for the i2c bus clock speed increase, please?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

https://learn.adafruit.com/adafruit-mot ... rduino/faq
The default bus speed is 100KHz and can be increased to 400KHz by editing the library file in your Arduino installation folder. The file can be found in hardware/libraries/wire/utility/twi.h.

Find the line with: "#define TWI_FREQ 100000L"
and change it to "#define TWI_FREQ 400000L"

Or, you can add the following code to your setup() function:

TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz

mccarthybergeron
 
Posts: 20
Joined: Thu Jun 19, 2014 9:35 am

Re: Stepper Speed limitations with MotorShield v2?

Post by mccarthybergeron »

Gotta say, you rock. I played with the code and even created a slightly different class using what you had and the Accelerator code and the motors spun much, much faster. Huge improvement and I just completed the project I was working on for a client. Thanks a ton!

User avatar
wergor
 
Posts: 24
Joined: Sun Aug 31, 2014 4:38 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by wergor »

adafruit_support_bill wrote:https://learn.adafruit.com/adafruit-mot ... rduino/faq
TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz
adding this line to my setup() does not increase the maximum stepper speed, i have to set TWI_FREQ to 400000L in the twi.h. i'm using a mega2560.
adafruit_support_bill wrote:And some more numbers:

With the microstepping PWM overhead stripped out, the max step rate is 1161 steps/second.
I was not able to get the #324 200-step motor to run at that speed : https://www.adafruit.com/products/324
I had to slow the step rate down to about 830 steps/second. (Any faster and it would start missing steps) That translates into about 250 RM.

Mind you, that is right at the limit for this particular motor powered by a good stiff bench supply @12v. Your mileage may vary.

To replicate this, you need to hack the library a bit.

Add this function prototype to the Adafruit_StepperMotor class in Adafruit_MotorShield.h
....
will this be added to the official library?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

adding this line to my setup() does not increase the maximum stepper speed,
Add it after the call to 'begin()'. Otherwise it gets reset to the default speed.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”