Calculating Driving Stepper motor signal


There are so many accomplished and electrically inclined people here… I have a question. Linux CnC ask for a frequency of driving a stepper motor.

Information on questioned variable to be calculated.

This is my motor.

This is my driver.

This is my board

I consider the motor to be a power source, resistor and inductor in series. This forums a first order circuit. I then look at the first orders time constant to determine upper limiting driving signal.

R=1.4 ohms
time constant= L/R = 3mH/1.4ohm= 0.002143s
The inversion of the time constant is my frequency.
Frequency=1/time constant=1/0.002143s= 466.67Hz

Upper limit of 466.67Hz. Which seems reasonable given the base value in the program. I set the frequency to 300.hz

I have only done the initial calculation. How would you calculate this number?


Certainly no expert here, so I’ll be interested to hear what any others with more experience offer, but I’ll provide some additional input from my side.

LinuxCNC will be sending pulses to the driver, which has a micro-stepping function. So you need to consider how many pulses need to be sent to the driver to equate a full step on the motor. If 1/32 microstepping, multiply your desired motor full step frequency by 32 to get the LinuxCNC PWM rate. (The driver appears to support up to 250kHz input.)

I found a torque curve for your motor at I would interpret this chart as indicating your motor can operate at a much higher full step rate than you have calculated. The “sweet spot” for torque seems to be 1 - 3.5 kHz, but the motor will of course operate at much lower pulse rates as well. With a 0.9 degree per step rotation (400 full steps per revolution), you also need to consider the motor output speed you want to achieve and what speed that will produce on your machine.

So, I guess what I’m getting at is that I wouldn’t calculate the frequency that the motor can handle (the torque curve appears to show up to 5kHz is within range), but rather the desired speed of movement given your gearing/timing belt, etc. Assuming, for example, to produce 4" per second (240 inch per min.) with a 2" circumference drive gear, you need 2 rev per sec (120 RPM), which requires 2*400=800 full steps per sec (800 Hz) Multiply that by your desired micro-step rate to get the required PWM pulse rate from LinuxCNC.

Hoping someone else can educate me otherwise… :slight_smile:


But now looking at your link more closely, the PWM Rate appears to be on the SPINDLE configuration, not the axis drive… and I know NOTHING about using a stepper motor as a CNC spindle. Everything I’ve said above is more applicable to the axis configuration at

So, apologies if nothing seems to make sense in your context.


Disclaimer: my experience with stepper motors consists solely of configuring floppy disk drives on vintage computers.

Many floppy disk drives use a stepper motor to position the read/write head. Older drives cannot handle as high a step rate as newer drives. However, configuring a newer drive to use a slower step rate usually results in an unpleasant noise and I presume more wear on the mechanicals.

Therefore, you do not want to drive them too slowly.


This is more about the characterization of the stepper motor. We have two whinedings I am looking for a good manual on stepper motor control. Possibly a book, with calculus equations.

Is this a good reference?

Could anyone review an excel document used to calculate my answers?


Nevermind, the parameter I’m referring to as PWM carrier is set by the DRV8825 at 30kHz.

The PWM carrier frequency should not be very sensitive. It probably should be in the KHz though. The tradeoff is generally:

Higher frequency = more switches = more power dissipation in the H-bridge transistors
Higher frequency = less audible noise, especially beyond 18kHz
Higher frequency can mean more EMC output, although that is probably not a huge factor.

Generally it’s a tradeoff of noise vs efficiency.

[quote=“ceramicCAP, post:1, topic:48074”]
This forums a first order circuit. I then look at the first orders time constant to determine upper limiting driving signal.

That’s a good shot but since it’s working like a sort of DC-DC switching converter, you’re looking at the overall trend (duty cycle) rather than the cycle-to-cycle performance. The winding parameters (and operating conditions) will determine how quickly that overall trend can ramp up and down, but you can switch MUCH faster than the motor di/dt limit.


Please ignore this post if it demoralizes or overwhelms you. I feel like you’re the curious type that might want to dig deeper on this type of stuff, and it will possibly inspire you a bit. This post is probably overkill, but if you’re going to engineer it you might as well over engineer it. This is strictly about the signal generation portion. Full disclosure, I had to take Dynamics twice in college (the only class I had to do that) :laughing:

The first video seems to imply he’s using trapezoidal profiles for velocity. If you want “extra credit”, don’t use trapezoidal velocity profiles (constant acceleration from zero up to maximum speed, hold maximum speed, constant deceleration back to 0) and go down the “S-Curves rabbit hole” :smile:. The S-Curves minimize “jerk” (the first derivative of acceleration) and possibly “jounce” (the next derivative) depending on the order of your S-Curve equation. In a trapezoidal profile, your “jerk” is infinite when it starts to move (acceleration graph points straight up, infinite slope). The derivatives past acceleration are also sometimes called “snap, crackle, and pop” (apologies to Kellog’s).

To see what effect this has, watch this video a few times:

This seems to be where the S-Curve equations come from: Obviously you would have to scale them by maximum velocity and scale time to move the 0 to 1 value over 0 to 1 time to match your situation (maximum velocity and acceleration/deceleration).

For what I’m working on, I’m currently trying to break down the “smoother step” function (6x^5 - 15x^4 +10x^3) into linear chunks because it’s being used in a configuration that is sometimes called a “polar bot” (like the DMS member made “Gocupi” ( If my velocity chunks remain linear, then I can solve quartic equations for position ( as opposed to using higher order equations requiring solution by something like Netwon’s method or super sampling (increment time by very small amounts to find the solution I want).


Thanks for looking into this. I am trying to mathematically model the limiting factors in my 3dprinter. I am trying to simulated motor to see what signal it would accept. I might be looking at this in the wrong way. the stepper motor might be current controlled device and not a voltage controlled device.if the stepper motor is a current controlled device then the power supply really represents steps of current. Should the two coils of the motor be looked at as if it is current controlled device?

Also i found this in googling.


There are a few different layers of things going on. Some of that is being fully handled by the TI driver doing current control.

The maximum step frequency is related to the maximum torque you need. The motor generally works like any other brushed DC motor in that the faster it rotates the higher the reverse voltage will be. This limits the current you can push through the motor and thus limits the torque.


So are the drivers using an H bridge?

Maybe this would be a good book for the motor.

For the driver the data sheet says the step frequency is 250 Khz. So looking at the motor and at driver i would take the lesser of the two frequencies. Is this correct?


Yes, but all of that is wrapped up inside the driver IC you’re using, so there’s a lot there you’re not having to deal with.

This is just the maximum possible step frequency that the driver can handle. It is almost completely irrelevant. Your maximum step frequency is going to be much, much lower than that.


See, beer can solve almost any problem!


You are correct I should have said maximum step frequency is 250 Khz. I had made a guess a 300hz. I have listed a book. I am not just looking for a number. I am looking for equations. I do not want to google my search for the equation because it is prone to error. I am looking for a mathematical model of a stepper motor. I am also looking for encouragement. If nothing else i guess that i will buy the book and post my findings. which i hope will be a better understanding of stepper motors. Thank you for your interest.


You are kindof in an interesting realm here. You want equations because doing it experimentally or by the profiles listed with your motor isn’t “good enough”, but you don’t want to derive the equations yourself (from the magnetic and electrical interactions in the motor) and don’t trust what you can find on google.

If you really want to get into the equations I would look at physics textbooks not in the “For Makers” or even “For Engineers” type books because they tend to lean more towards the quick and dirty get it done and less with the really pointed math behind it.

This part is easy, I can do this. Good Luck! Hope you find what you are looking for!


Always check MIT for inspiration and ideas! :slight_smile:

They’ve got a bunch of stuff for building robots, which also applies to interfacing to the outside world for any generic control project.


This is a waste of time, and I don’t throw that around lightly. There is a torque/velocity curve in the motor datasheet somewhere, and you can estimate the torque you’ll need from friction and motion equations which will give you an estimate of maximum velocity, but the real way is to experiment and find ideal values.

There are lots of potential models, but thinking of it as analogous to a brushed DC motor with back-emf limiting the input voltage and torque proportional to current is about as good as any if you’re not getting a PhD in motors.

(Unlike brushed DC, speed is not proportional to voltage, but the MAXIMUM speed at any particular loading is proportional to the maximum input voltage. This follows from the previous statements about torque and back-emf though.)