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.
User avatar
wergor
 
Posts: 24
Joined: Sun Aug 31, 2014 4:38 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by wergor »

worked, thanks!

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:Call "onestep(FORWARD, DOUBLE);Call "onestep(FORWARD, DOUBLE);" once in your setup function to initialize the PWM to 100%. Then call "quickstep(FORWARD);" in your loop.
the quickstep code works very well, my maximum speed increased by about 40%.
is it possible to initialize the PWM to 100% without making a step? i want to keep track of my position as accurately as possible, making 1 step forward and 1 step backward is not the best solution in my opinion.

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

You can try adding this function to the library and calling it at the start: (fair warning - I haven't tested this)

Code: Select all

void quickStepInit()
{
  MC->setPWM(PWMApin, 4095);
  MC->setPWM(PWMBpin, 4095);
}

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:You can try adding this function to the library and calling it at the start: (fair warning - I haven't tested this)

Code: Select all

void quickStepInit()
{
  MC->setPWM(PWMApin, 4095);
  MC->setPWM(PWMBpin, 4095);
}
works like a charm! thanks a lot!

Code: Select all

void Adafruit_StepperMotor::quickstepInit()
{
  MC->setPWM(PWMApin, 4095);
  MC->setPWM(PWMBpin, 4095);
}

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

Great! Happy to help.

User avatar
UP
 
Posts: 32
Joined: Fri Nov 21, 2014 3:05 am

Re: Stepper Speed limitations with MotorShield v2?

Post by UP »

Hi there, I' running four Adafruit Nema 17 steppers using two Adafruit motorshields on a Arduino Mega 2560. I found out that excluding two of the motors from source code speeds up the running two motors a lot. I'm using accel stepper. I'm not sure if any change in code or not using Accel stepper library will be much faster on four motors. I have stopped early expirements because nothing happens on speed running four motors. Maybe the Arduino board is the problem. Are there faster boards?

As it goes for the motorshield...what is it worth to connect 10 motorshields using their stack capability if the 20steppers connected to it won't move any longer? =;c)

Regards

UPO

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

There are several speedup methods discussed in the thread, have you implemented the i2c bus speed increase or the 'quickstep' hack?
A faster processor won't help, since the limitation is the i2c bus speed. Customers have had success increasing the Arduino bus speed to as much as 500KHz.
what is it worth to connect 10 motorshields using their stack capability if the 20steppers connected to it won't move any longer?
Not all motors are stepper motors and not all stepper motors are 1.8 degree stepper motors. It may not be the perfect solution for your application, but we have seen successful projects using up to 16 stacked motor shields.

For a higher aggregate step rate capability, you might want to look at the stepper control modules from Pololu. They require 2 pins per stepper, but do not have any i2c overhead.

User avatar
UP
 
Posts: 32
Joined: Fri Nov 21, 2014 3:05 am

Re: Stepper Speed limitations with MotorShield v2?

Post by UP »

Hi Bill, I will go for 4x easydriver as it is available for less than $2 and chipKIT Max32 as a lot of Pins are required. Not sure about netduino. I like the idea to use the net framework, but there's not much Information about specific hardware configurations (steppers).

=8c) xmas

User avatar
UP
 
Posts: 32
Joined: Fri Nov 21, 2014 3:05 am

Re: Stepper Speed limitations with MotorShield v2?

Post by UP »

Hi there,

the Chinese Easystepper board on ebay is fake, what else, performs very bad. So what...

Bought a few original EasyStepper boards for testing purposes along with the chipKit 32max, put the Adafruit motors on it, run my Mega2560 setup with two Adafruit motorshields parallel. Put four unipolar Lin steppers on it. Possible speed of motors on chipkit setup is much higher, as expected, but Arduino/Adafruit setup works, but ...there is an issue when it comes to connect the quad numeric display for the counted revs of one or more mothers (planed to switch between the motors) to the Arduino/Adafruit setup. If the Quad is active (code) no motor spins. Connected the Adafruit steppers back, no motor spins, eleminating the code for the Quad all motors spin as they should. The problems seems to be the quad display

Setup:

Bipolar hall sensor on Pin 0 (counts the rev by using a diametrically magnetized neodymium magnet, works great), Potentiometer on A0 (regulates speed for one of the steppers) , Adafruit LED on Pin 13, Quad connected as desribed for a Mega2560 setup.

I like the Quad display and I would like to use one for the other setup, but I do not like to buy another one if it makes me run into problems. Any idea how to solve this? Could it be a problem with the wire library?!

Thank you, UP

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

The default i2c address for that display is 0x70. That is the same as the 'all call' address for the PCA9865 chip on the motor shield. If you re-address the display, you will avoid the address conflict.

User avatar
UP
 
Posts: 32
Joined: Fri Nov 21, 2014 3:05 am

Re: Stepper Speed limitations with MotorShield v2?

Post by UP »

Hi Bill,

yes, did it in the setup, alpha4.begin(0x70); and then AFMSbot.begin(); // Start the bottom shield, AFMStop.begin(); // Start the top shield...hmm, will try something else...

Using another program sometimes the motors or the shields hang too (no quad display). I have to replug the USB a few times and then it works, but not in the setup with the quad display. We'll see...

Thank you, UP

UP

User avatar
robbobfrh84
 
Posts: 7
Joined: Wed Jun 11, 2014 12:44 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by robbobfrh84 »

Thanks for all the info from your hard work!

I followed all the steps and added the code to the Adafruit_Motorshield files and got my #324 up to 199 RPMS, or 2.52 ms per step.

So far I've...

1) I changed the i2c up, which helped!

2) I used Bill's code to disable microstep, which also helped.

But, I'd love to get to the 200 RPM mark. Is there anything else I could mess with in the Adafruit_Motorshiled.ccp file that might open things up a bit?

what's strange is that I can't get the motors to skip. (wouldn't want that) But, as I turn down the delay's or up the rpms, it just gets to a point where the speed just doesn't change, regardless of my tinkering. Strange. I used to have the v2.1 shield and when I'd ramp things up, the motors would skip. Now, I have he v2.3.... wondering if there's something different with this version.

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

what's strange is that I can't get the motors to skip. (wouldn't want that) But, as I turn down the delay's or up the rpms, it just gets to a point where the speed just doesn't change
You are probably running into the point where the i2c overhead completely dominates the timing. Some folks have had success increasing the i2c bus rate to 500KHz or more. That might be enough to get you to the speed you need.

User avatar
brian33433
 
Posts: 36
Joined: Tue Jul 22, 2014 9:49 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by brian33433 »

Will this hack work with the accel multistepper directory?
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

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);
}

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

Re: Stepper Speed limitations with MotorShield v2?

Post by wergor »

yes

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

Return to “Arduino Shields from Adafruit”