Steps per min not equal to 60 * setSpeed() steps per sec

114 views
Skip to first unread message

DOPPLERDAVE

unread,
Aug 22, 2018, 11:40:38 AM8/22/18
to accelstepper
I'm reposting my question because I have simplified the code in an attempt to isolate the problem.

I am using an Arduino Uno and Adafruit Motorshield V2, but this code runs without the Motorshield attached. I am using setSpeed then taking the difference between the currentPosition() at the start and end of a 60 second timer.


Obviously the I2C is limiting the speed above 350 steps per second, but why the errors at lower speeds? If I connect a motor and count revs over a minute, I see the same problem.

Code is attached. What is wrong?
MyAccel_ConstantSpeed.ino

gregor

unread,
Aug 22, 2018, 3:37:42 PM8/22/18
to accelstepper
Hi, 

can you repeat your tests with 400kHz I2C frequency? add this line
Wire.setClock(400000L);
to your setup() function. This will also raise the maximum stepper speed of the AFMSv2 to ~1000 steps / second. 

DOPPLERDAVE

unread,
Aug 22, 2018, 7:03:23 PM8/22/18
to accelstepper
Hi Gregor.

It made no difference!
I was sure that this change would effect the results at 350 and 400. What could this mean?

Dave

gregor

unread,
Aug 23, 2018, 3:04:12 AM8/23/18
to accelstepper
Curious. I'll ty the code later on my Mega2560 + AFMSv2, maybe I can find something.

gregor

unread,
Aug 23, 2018, 3:10:05 AM8/23/18
to accelstepper
can you share your latest code? I wonder how you can achieve speeds greater than 1 step / second at all, seeing that you do not call setMaxSpeed() to change the maximum speed from the default of 1 step / second.

DOPPLERDAVE

unread,
Aug 23, 2018, 9:38:04 AM8/23/18
to accelstepper
Here it is.
MyAccel_ConstantSpeed.ino

gregor

unread,
Aug 23, 2018, 9:46:35 AM8/23/18
to accelstepper
Hi,

add
  Astepper1.setMaxSpeed(1000.0f);    
before
  Astepper1.setSpeed(stepsPerSec);    
in the setup() function and see if it makes a difference.

DOPPLERDAVE

unread,
Aug 23, 2018, 9:54:18 AM8/23/18
to accelstepper
It made no difference.


On Wednesday, August 22, 2018 at 10:40:38 AM UTC-5, DOPPLERDAVE wrote:

gregor

unread,
Aug 23, 2018, 2:16:04 PM8/23/18
to accelstepper
Hi, 

I just tested your code with my Mega2560 and AFMSv2.
Your code from your previous post:
Stepper constant speed test
SetClock at 400000
Speed cmd = 50 steps per sec. Steps per min = 3000. Steps taken in 1 min = 60
Speed cmd = 100 steps per sec. Steps per min = 6000. Steps taken in 1 min = 60
Speed cmd = 150 steps per sec. Steps per min = 9000. Steps taken in 1 min = 60
Speed cmd = 200 steps per sec. Steps per min = 12000. Steps taken in 1 min = 60
Speed cmd = 250 steps per sec. Steps per min = 15000. Steps taken in 1 min = 60
Speed cmd = 300 steps per sec. Steps per min = 18000. Steps taken in 1 min = 60
Speed cmd = 350 steps per sec. Steps per min = 21000. Steps taken in 1 min = 60
Speed cmd = 400 steps per sec. Steps per min = 24000. Steps taken in 1 min = 60
which is expected, since the maximum speed is at its default value of 1 step / second. 

With the line 
Astepper1.setMaxSpeed(1000.0f);
added to the setup() function:
Stepper constant speed test
setClock at 400000
Speed cmd = 50 steps per sec. Steps per min = 3000. Steps taken in 1 min = 3000
Speed cmd = 100 steps per sec. Steps per min = 6000. Steps taken in 1 min = 5997
Speed cmd = 150 steps per sec. Steps per min = 9000. Steps taken in 1 min = 8992
Speed cmd = 200 steps per sec. Steps per min = 12000. Steps taken in 1 min = 11990
Speed cmd = 250 steps per sec. Steps per min = 15000. Steps taken in 1 min = 14984
Speed cmd = 300 steps per sec. Steps per min = 18000. Steps taken in 1 min = 17960
Speed cmd = 350 steps per sec. Steps per min = 21000. Steps taken in 1 min = 20920
Speed cmd = 400 steps per sec. Steps per min = 24000. Steps taken in 1 min = 23963


which version of AccelStepper are you using? You can find the latest version here: http://www.airspayce.com/mikem/arduino/AccelStepper/ 

regards,

David Cunningham

unread,
Aug 23, 2018, 10:21:25 PM8/23/18
to accels...@googlegroups.com

Thanks Gregor,
I am traveling so cannot do anything for a few days. It sounds like my libraries are messed up. I thought I had the latest version but ???
Will advise as soon as I check it out.

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DOPPLERDAVE

unread,
Aug 29, 2018, 1:47:19 PM8/29/18
to accelstepper
 Hi Gregor,

That fixed it! Thank you very much.

For what it is worth, the version of AccelStepper that I was running, and which gave the bad speed results, was V1.2 (as indicated near the top of the cpp file). The one that worked is V1.3

What threw me off is that in order to get the latest version I had searched for AccelStepper on github and gotten a listing at github.com/Adafruit/AccelStepper that said "A small fork of AccelStepperV1.3 with AF_motor support". But that download is actually V1.2 which does not work correctly. I will post this result to my original topic at Adafruit as well.

Finding the version number of these files seems a bit obscure to me. The library you pointed me to was a zip marked 1.59 but the only way to find out the version of the AccelStepper included is to extract the files from the zip, then open the cpp file with a text editor. Maybe there is a more direct way, but I could not find it.

Thanks again for your help.

Mike McCauley

unread,
Aug 29, 2018, 5:01:30 PM8/29/18
to accels...@googlegroups.com
Hello,

The version number at the top of the file is just the file version. The
version of AccelStepper as a whole is given by the name of the zip file, the
zip file name embedded in the AccelStepper.h file and in the Makefile (which
should all be the same).

The canonical source is
http://www.airspayce.com/mikem/arduino/AccelStepper/

Cheers.
--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Reply all
Reply to author
Forward
0 new messages