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
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by Kushal11 »

Another question...
Mine is a 200 steps/rev motor.

These are the settings for Double mode. Speed is in steps per second.

Code: Select all

stepper2.setMaxSpeed(500.0);
  stepper2.setAcceleration(500.0);
  stepper2.moveTo(200);  
This takes around 7 seconds to compete 5 revs.

Now these are the same settings but for Microstep mode (1/16th of full step). Again, speed is in microsteps per second.

Code: Select all

stepper2.setMaxSpeed(500.0);
  stepper2.setAcceleration(500.0);
  stepper2.moveTo(3200);  //for microstep, it's 3200 steps/rev 
This takes around 37 seconds to compete 5 revs. (which is around 5 times slower than double step mode )

Now, if my microstep mode uses 1/16th of a full step, shouldn't my speed in microstep mode be 16 times slower than the speed in double step mode?

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

That is probably a question for the AccelStepper folks. I don't know much about their internals and how they calculate timing for microstepping.

User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by Kushal11 »

Ok, thanks Bill.

And after reaching to desired position, what if I want to power off the stepper to save power? My stepper has enough detent torque to hold the load w/o power.

I tried enable/disableOutputs() in this way...

Code: Select all

void setup()
{ 
  Serial.begin(9600); 

  while (Serial.available() == 0)
  {
  }
  if (Serial.available() > 0)
  {
    i = Serial.read();
    stepper2.enableOutputs ();
  } 

  AFMStop.begin(); // Start the top shield

  TWBR = ((F_CPU /800000l) - 16) / 2; // Change the i2c clock to 800KHz
 
  stepper2.setMaxSpeed(500.0);
  stepper2.setAcceleration(500.0);
  stepper2.moveTo(difference*200); 
}

void loop()
{
   if (stepper2.distanceToGo() == 0)
    {
    stepper2.disableOutputs (); 
    }
    
    stepper2.run();
}
But not working :( Definitely I am missing something (probably many things!), what's that?

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

The AcclStepper disableOutputs() function doesn't work with the motor shield. But you can call 'release()' on the underlying Adafruit stepper object.

User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by Kushal11 »

Thanks Bill. It worked!

User avatar
Kushal11
 
Posts: 46
Joined: Mon Mar 28, 2016 6:59 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by Kushal11 »

Bill, so why do we need to increase the i2c bus speed?

If the shield's PCA9685 is really a free running driver, then we only need to set it's parameters (PWM freq, duty cycle, etc) by i2c once and then it can run the stepper on its own. I2C speed shouldn't need to be more than the speed at which the user changes the commands. PWM frequency of the PCA9685 should be the one who can help us achieve higher RPMs.

Am I missing something here?

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

PWM frequency of the PCA9685 should be the one who can help us achieve higher RPMs.
No. That is not how things work.
It takes more than just a PWM pulse to control a stepper motor. You need 2 signals per bridge to create the bipolar signal for each phase. You also need a PWM signal to control the duty cycle on each phase (for microstepping). Each step potentially involves changing all 6 signals per motor. The "quickStep()" optimization above reduces that traffic somewhat by eliminating the PWM control. This also effectively eliminates microstepping capability..

User avatar
citfta
 
Posts: 3
Joined: Fri Jul 29, 2016 4:46 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by citfta »

I have the Nema 17 motor and the Adafruit Feather MotorShield V2 board. I have it working with the sample test code. Now I want to speed up the motor and have read all of this thread a couple of times until I was pretty sure I understood what I needed to do. When I get to the library and open the MotorShield sketch I can add the new code using copy and paste from this thread. But when I try to save it I get an error that says access denied. I am using WordPad (Windows 7) and I have administrative privileges for anything else I want to do. Do I need some other program to edit the sketches in the library? Thanks for any help you can give.

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

The file probably has read-only attributes. If you right-clck and select Properties, you should be able to un-check the Read Only box.

User avatar
citfta
 
Posts: 3
Joined: Fri Jul 29, 2016 4:46 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by citfta »

Thank you for your very quick reply. I did right click on the files and neither the .h file or the .cpp file were write protected. The properties box said they might be blocked and gave me an option to unblock them. I tried that but am still not able to save the files after I add the needed code to speed up my stepper motor. I am copying and pasting from this thread.

User avatar
citfta
 
Posts: 3
Joined: Fri Jul 29, 2016 4:46 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by citfta »

Ok I found a way to edit the library files. I had to install a C++ editor and that let me add the new lines from this thread and save the edited files. The editor I used is called Dev C++. It seemed very easy to use for just editing a file. Thanks for the suggestions.

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

Good to hear that you found a solution. Not sure why WordPad would not do it.

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by jbc »

I amended the files Bill mentioned here;
viewtopic.php?f=31&t=57041&start=15

I got lost with this step;
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.
I am using my own sketch and tried to place the above in it in different places including the top/beginning of the sketch (right after the motor shield libraries are called.

I am trying to get more power from the stepper motors connected to the motor shields V2.
Right now they are too weak. I found this thread but need help progressing.
jbc

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

Re: Stepper Speed limitations with MotorShield v2?

Post by adafruit_support_bill »

I am trying to get more power from the stepper motors connected to the motor shields V2.
This thread is about increasing speed. With stepper motors, torque will decrease with speed. Better to start a new thread for this topic.

posting.php?mode=post&f=31

User avatar
scottferg
 
Posts: 15
Joined: Tue Apr 05, 2016 6:29 pm

Re: Stepper Speed limitations with MotorShield v2?

Post by scottferg »

Bill pointed me to this thread and I thought I'd share my experiences here as well.

I've hacked the Adafruit_StepperMotor class to cache the 'latch' and 'pwm' values in the 'onestep' function so that they are transmitted by i2c only when they change. This eliminates a significant number of 12c transmissions rather than just speeding them up. This is essentially the contribution of the 'quickstep' hack, but caching makes the optimization available to ALL stepping styles, not just DOUBLE, and without a separate function. This caching resulted, for my case, in about a 25% improvement in calls/sec to loop(), yielding higher possible stepping frequencies. I tried increasing i2c speed to 400kHz and even 500kHz (verified by printing TWBR within loop()) but did not notice any further significant improvements.

I also applied a trivial hack to the AccelStepper library to use microsecond timing rather than millisecond timing, which significantly improved it's calculations and thus the correlation between it's report of stepper speed with the values I see empirically. I.e. without this hack I was observing actual speeds less than those being requested!

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

Return to “Arduino Shields from Adafruit”