Menu

Linear

Anonymous

Linear speed profile for stepper motor

Let's consider a S=400 steps/rev stepper motor which we want to drive with a PIC18F452 microcontroller using linear speed profiles. We suppose that the PIC runs at its maximum frequency (FOSC=40Mhz), yielding in a minimal timer period of TP=TOSC=4/FOSC=100ns. The timer is controlled through a register TREG whose value directly determines the period P = TREG * TP. The angular speed V of the motor (in deg/s) is thus equal to V = (360/S) / P = (360/S) * (1 / (TREG * TP)). This equation is actually used to compute the value of TREG given a speed: TREG = (360/S) * (1 / (V * TP)). This equation, expressed in a continuous form, defines the function treg(t) as

-->

These figures show a simulation of running the microcontroller with the above equation starting with a minimal speed value (fixed as a maximal value for treg=65535). At each step the next treg value is computed using the above equation with a time value equal to the sum of the preceding treg values multiplied with the timer period TP. Here the computations are made using a floating point unit. The figure on the right shows the variation of treg and speed with respect to the step number s.

Direct implementation