Menu

Speed

Anonymous

Introduction

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.

Details

Expression of speed as a function of time

In the following, t denotes the time, v(t) denotes the speed as a function of time.

  • Let first express the speed in a normalized way where time and speed lie in the [0,1] interval.

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).

  • Initial and final speeds:

We will consider the same profile for both acceleration and deceleration, yielding in symmetrical speed profiles. The speed can then be expressed as
* ##

* ##
  • Acceleration and deceleration time:

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:

Implementations

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.

  • Fixed timer period: this approach consists in computing and accumulating a fractionnal step increment at each timer period and generates a step pulse when the overall increment exceeds 1. A new value of the speed is computed at each timer period. The timer period should be shorter than the minimal stepper period (which determines the maximum speed). The approximation made here is that the speed is supposed to be constant during the fixed timer period.
  • Variable timer period: the timer period is simply equal to the stepper period (which is proportionnal to the inverse of the angular speed). A new timer period is computed at each step. The approximation made here is that the speed is supposed to be constant during a stepper period, being less accurate at low speeds.