Stepper Motor Super Speed Control

As the title says, I'm trying to figure out how to control a bipolar stepper motor's speed using a potentiometer. There is already a specified number of steps the stepper motor must take but how quickly it reaches those number of steps depends on the potentiometer and the new defined speed. Are there any examples of this I can find? What does the coding look like for controlling speed of a stepper motor with a potentiometer? I saw the Motor Knob example on Stepper Motors but that just controls number of steps with a potentiometer as you turn it. I am thinking of using the stepper library to aid in this but am not really sure what the best approach is to my problem.

If the number of steps per unit of time is known (and the potentiometer is controlling the unit of time), what is necessary is to figure out how long between steps.

Then, after each of those intervals of time has occurred, step again.

Look at the Blink Without Delay example for how to properly do this.

So if I used the stepper library, could I constantly redefine a new stepper rpm speed after each step when it reads the potentiometer?

Also, where can I find how fast the arduino processes a program? (i.e. the time of each definition and code sequence within the program)

Yes, you could call setSpeed with new speed value, and then call step with the fixed number of steps. The setSpeed() method records a speed that step() uses to figure out the pause between steps.

Also, where can I find how fast the arduino processes a program?

A 16MHz Arduino processes each instruction in 62.5 nanoseconds. High level programming languages insulate you from knowing how many machine instructions a given statement will translate into, because various optimization levels will change how many machine instructions will be generated (or, more accurately, how many will be optimized out).

Why do you think this is important to know?

Also, where can I find how fast the arduino processes a program?

In the most informative ATmegaX8 data-sheet. You have it all described how many clock cycles each instruction takes. How long a clock cycle is can be calculated from the frequency on the crystal of your Arduino (usually 16MHz fro 5V version, 8MHz for 3.3V). At the maximum 16 or 8 instructions per ┬Ás, less depending on your use of instructions taking more than one clock cycle.

But why do you care about such things at the level you are? Those kind of things only become relevant once you have a solid grasp of assembler code. Before worrying about such things, check how fast your motor is able to turn at maximum and what impulse rate you need for maximum speed.

Korman

Nema 23 Step Motor

Bi-Polar Specs: 200 step (1.8 deg) Voltage: 7.8 Current (per phase): 0.7A -I believe I just bought the wrong kind of driver for this motor (SN754410NE). I did a little searching around and a Interinar Electronics recommended drivers to be BSD-013G, BSD-01P, BSD-02 or BSD-02LH. But those are pricey for me. I'm just looking for a couple of quadruple H-bridge drivers that can have a max current that handles the motors.

To answer both of your guys' question: I just wanted to know the speed of the processing because I thought that maybe doing an analog read of the potentiometer and calculating the speed after each step would cause a noticeable lag or worse when the program tells the motor what to do causing a longer delay between steps then what I specified.

I just checked the speed with SN754410NE and 7.5v and 9v. The max speed I achieved was 150rpm and the H-bridge was getting quite warm.

The max speed I achieved was 150rpm and the H-bridge was getting quite warm.

That's 2.5 turns per second or, assuming 200 steps per turn, 500 steps per second or 2ms per step. So you aren't coming even close to worry about instruction execution time.

Korman

Thanks Korman.

Got a couple more questions for anyone who's reading this thread. What would be the best way (way that saves memory and most efficient analog reading to conversion of motor movement) to control two stepper motors simultaneously with 2 potentiometers (joystick controller with x and y axis) at the same time for the programming part? I was thinking of using if/else statements or do/while loops with embedded if/else statements so it counts how many steps are being executed while an analog input is being read. i.e. an if/else statement for reading only one analog input, the other analog input and then both analog inputs at the same time for the motor controls...

Also, I saw an EasyDriver Stepper Motor Driver on Sparkfun which supposedly makes controlling a stepper motor easier. It does not seem simpler, to me, however. Would this aid in my first question? If so, how?

Thanks, guys.

Don't worry about compact code for such a simple application, write it in a way that is easy to understand to you.

Korman