Stepper speed misbehaving. Dspin Microstepping.

I am powering a stepper motor using a Dspin driver. I have a pushbutton to toggle - speed and/or direction. Even if I program the 2 speeds the same, when I toggle between the 2 speeds, one is 5x slower than it should be. If I comment out either of the if statements, the remaining speed runs correctly.

Turntable_dSPIN_5.ino (10.1 KB)

Your code looks like you got it from somewhere - perhaps from dSpin ?

If so, have you modified it in ANY way?

If so please identify every one of your changes.

Please post a link to the dSpin website and documentation.

Is it really necessary to use the dSpin driver?

...R

I'm believe I downloaded code from GitHub - neirons/dSPin_Autodriver_BOB: My first run of Sparkfun BOB-11611. Original code from 12/12/2011- Mike Hord, SparkFun Electronics
I really must take note of such details.

Project is for a Hi-Fi turntable. Speeds will be set for 33/45 turntable speed.
I will incorporate feedback from an opto-sensor to prevent speed drift - one step (excuse the pun) at a time!
Microstepping runs quiet & smooth - certainly less vibration than the mains synchronous motor it's replacing.

The bit I've written is the pushbutton toggles for stop/start & speed selection & associated LED's.

How can - dSPIN_Run(REV, SpdCalc(200)); run at correct speed in one if statement but not in the other, yet if I comment out EITHER if statement, the other runs at correct speed? If I remove the stop/start pushbutton code leaving only speed selection still the same happens, one runs at correct speed, the other not.

Datasheet - http://www.st.com/web/en/resource/technical/document/datasheet/CD00255075.pdf

Is this the device you are using

It is an interesting device because it apparently can control a motor that requires up to 3 amps - however it is expensive.

I suspect the answer to your question is somewhere in all the various links but nobody seems to have taken the trouble to write a user manual and I don't have the patience to read it all - especially as Github insists on using grey type that is almost unreadable.

...R

Programming error. if - if - else should be if - else if - else - sorted now.

I've got a 700 page cookbook that doesn't tell how to program multiple if statements.
I also have a thin C++ book that is very useful at solving such issues. Unfortunately, C++ is not same as Arduino-ese so I have to translate it.
I would love a slim easy reference Arduino programming book rather than wading through multiple example programs that "nearly" do what I want. I don't program enough to become fluent.

Yes, a similar device L6470 Stepper Driver Breakout - BOB-10859 - SparkFun Electronics - without holes for big block connectors.