Generating speed profiles with microcontrollers is not as easy as when using powerful processors. I consider here the general case of speed control and present generic implementations using microcontrollers.
In the following, t
denotes the time, v(t)
denotes the speed as a function of time.
with t in [0, 1]
and f(t) in [0,1]
. The following figure shows the normalized forms of two speed profiles (linear and S-shape).
We will consider the same profile for both acceleration and deceleration, yielding in symmetrical speed profiles. The speed can then be expressed as
* ##
* ##
With these definitions, a general expression for the speed is then
The following figure shows the two preceding speed profiles with an initial speed of 140 deg/s, final speed of 1440 deg/s (240rpm) and a total acceleration time of 2 seconds.
Their respective equations are:
The way speed is actually controlled depends on the type of the motor. For DC motors, speed depends on the voltage applied to the winding. This voltage is generally controlled through an H-bridge with some PWM applied to its MOSFETs. For stepper motors, speed depends directly on step pulses. In both cases, genrating a speed profile amounts to periodically perform an action (PWM change for a DC motor, step pulse for a stepper). On microcontrollers, timers are used to periodically run specific code (in the timer interrupt handler). This actually yields in a discretization of time. For DC motors, a constant timer period is used to handle the PWM voltage control. For stepper motors, there are two ways in using timers for generating speed profiles.