Stepper Motor nonlinear speed and velocity control - Speed profile

Hello Community,

I'm looking for input on the following problem.

In short:
I want to drive a stepper motor with a non-linear speed curve to individually determine speed and acceleration up to a specific position like a speed profile.

In detail:
I've programmed many projects with NEMA stepper motors that drove at a constant speed with a certain acceleration to a position and back using the AccelStepper.h library. So far, so good.

For the new project, I've acquired significantly larger components:

Characteristics of the Stepper Motor (JMC Servo Motor operates like a stepper motor):

  • The stepper motor is controlled by a pulse signal (PUL) and has a direction signal (DIR), similar to the connection of a motor driver (like DRV8825).
  • Max PUL frequency = 200 kHz
  • Min pulse spacing 2µs
  • TTL Logic
  • Fixed microsteps 800-40000 steps per revolution

Motor Control:
The motor should be controlled with a non-linear/non-constant speed curve or speed profile over time to drive a linear actuator. The speed profile should resemble a type of sinusoidal curve. However, the speed profile should be freely definable and can deviate from a sine wave, allowing for desired linear, square wave, ramp function, and all freely definable non-linear profiles in between - essentially a freely definable speed profile.

Here's a graphical example and video for illustration:

I've tried using the AccelStepper library, but I can't find anything beyond constant speed with a defined acceleration. The forum and research also didn't yield a relatively simple method or library.

In essence, I need to change the number of pulses or the time interval in which the pulse is sent within a relatively short time interval.

Are there any suggestions, libraries, or sample code for this?

Of course, the journey will be documented here, and I will share my code. Sharing is caring.

Cheers and thank you !

I would use AccelStepper, and call the motor control functions periodically, using a lookup table with maximum speed and acceleration values.

Or, a function could calculate the speed and acceleration values on the fly using specified formulas.

If the intended speed profile is a slowly changing function of time, there is probably no need to worry about the acceleration term.

3 Likes

But the stepper only works with integers, not floating point variables.

1 Like

It’s only the variable step rate that’s needed here.

The manually calculated pulse interval algorithm is the winner here - a canned library is convenient, but not flexible enough for this requirement,

You van make that ouse rate and duration anything you like, as long as the mechanism can keep up

1 Like

@jremington thx for reply!

i will try a lookup table for the maximum speed with AccelStepper and post my results later :wink:

@lastchancename thx for reply!

Can you describe your approach in more detail?

I would divide one revolution, for example 800 steps, into equally sized step intervals, for example 50 steps. Then I would define a separate speed with AccelStepper in a lookuptable for each interval. After reaching a step interval with 50 steps, a new speed is called up again and again.

Is your approach to be understood in this way?

Rather than using AccelStepper or other library, use a millis delay , and inside loop(), toggle the step bit.

You can vary the pulse ‘delay value’ at any time - in any way you like.

Of course, everything else must be non-blocking code.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.