Well, I made some testing and gathered statistics with TWI_FREQ=500000L. Here is the sketch:

- Code: Select all
`#include <limits.h>`

#include <Wire.h>

#include <Adafruit_MotorShield.h>

#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);

void setup()

{

AFMS.begin();

Serial.begin(9600);

delay(2000);

}

unsigned long prev = 0;

#define STEP_TIME 2500

// statistics

unsigned long t_max = 0, t_min = ULONG_MAX, t_sum = 0;

int cnt = 0;

#define MAX_CNT 3000

void add_statistics(unsigned long t)

{

if(t_min > t)

t_min = t;

if(t_max < t)

t_max = t;

t_sum += t;

if(++cnt == MAX_CNT)

{

Serial.print("cnt=");

Serial.print(cnt);

Serial.print(" t_min=");

Serial.print(t_min);

Serial.print(" t_max=");

Serial.print(t_max);

Serial.print(" t_ave=");

Serial.println(double(t_sum)/cnt);

t_max = 0;

t_min = ULONG_MAX;

t_sum = 0;

cnt = 0;

}

}

void loop()

{

unsigned long ms = micros(), diff = ms - prev;

if(diff > STEP_TIME)

{

myMotor->onestep(BACKWARD, DOUBLE);

unsigned long ms2 = micros();

add_statistics(ms2 - ms);

prev = ms;

}

}

Results:

- Code: Select all
`cnt=3000 t_min=988 t_max=1012 t_ave=997.81`

cnt=3000 t_min=988 t_max=1008 t_ave=999.59

cnt=3000 t_min=992 t_max=1008 t_ave=1001.02

cnt=3000 t_min=996 t_max=1008 t_ave=1001.72

cnt=3000 t_min=996 t_max=1012 t_ave=1002.33

cnt=3000 t_min=996 t_max=1012 t_ave=1002.54

cnt=3000 t_min=996 t_max=1012 t_ave=1002.73

cnt=3000 t_min=996 t_max=1012 t_ave=1003.05

cnt=3000 t_min=996 t_max=1012 t_ave=1002.99

cnt=3000 t_min=992 t_max=1012 t_ave=998.68

cnt=3000 t_min=988 t_max=1008 t_ave=997.55

cnt=3000 t_min=992 t_max=1008 t_ave=1001.78

cnt=3000 t_min=996 t_max=1012 t_ave=1003.12

So the maximum "onestep" duration is about 1012 microseconds, which theoretically should allow to rotate at (1000000/1012)/( 360/1.8 ) = 4.94 RPS = 296 RPM.

It would be more than enough for me. However practically I still can't rotate motor faster than 120 RPM. It is exactly STEP_TIME=2500 microseconds in the code above which is much more than 1012.

Besides, it works only if I use DOUBLE stepping and connect motor in the bipolar mode. If I use the unipolar mode or SINGLE style the motor stalls, I can't even make 120 RPM.

So it seems the cause of the problem is not in "onestep" anymore.

It is a huge progress, and I will use it this way if it is not possible to enhance results. However the motor is unstable on 120 RPM and skips steps.

What could be the cause now? Does anybody have any idea? I have no experience with steppers.

P.S. This is the spec of the motor I use.

http://www.robotshop.com/media/files/pd ... -specs.pdfIs it possible that it is too big and powerful for the shield?