Skip to content

Using the different modes

Michael Mayer edited this page Feb 2, 2019 · 2 revisions

Using the different modes

Mode 0: PWM command

The S-value is directly used as the PWM value and output to the motor driver.

The value is clipped to [-240;+240] to ensure a minimum duty ratio of 16/256 = 1/16 at all times to allow for the use of bootstraped drivers.

The clipped value is divided by two and centered around 120, for the high and the low driver side:

  • PWM_a = (val/2) + 120
  • PWM_b = 120 - (val/2)

For Zero the very same pulse pattern is output to both PWM channels resulting in zero motor voltage but keeping the bootstrap capacitors always charged (if a bootstraped driver module is used).

Mode 1: Torque control loop

This loop is not really a control loop but more of a forward compensation loop. The idea is that the torque of a motor (not the speed) depends only on the current. So in order to set a torque you want to set a current.

Usually, the current is measured directly and a simple control loop takes care of it. SMC passes on this input and calculates the current based on known motor properties and the current speed.

The idea is that every motor always acts as a generator. Always, not only when you connect a light bulb to it. When the motor turns, it generates a voltage that is propotional to the rotation speed. It doesn't matter if the motor is driven by external forces or if it rotates itself because it is driven by a voltage.

This generated voltage has the opposite polarity of the driving voltage. This fact is the reason why a motor has a set speed for every input voltage. It accelerates further and further, up to the point where the self-generated voltage exacty counter-acts the driving voltage.

External load slows the rotation down which reduces the self-generated counter-voltage, leaving more voltage for the internal resistance Ri, resulting in a higher current consumption - that's where the energy for driving the load comes from.

Calculating the back-EMF

The idea of the torque control loop is to take the self-generated counter voltage out of the equation. It measures the speed, calculates the voltage the motor is generating for this speed and increases the input voltage by exactly this amount to compensate for the Back-EMF.

Of cause, this is not a stable state. Without a load, the motor speed would run away until the driver maxes out. But that is correct, the goal is to set a constant torque which must result in a constant acceleration.

The voltage is not calculated in Volts but as a fraction of the maximum motor voltage - which is pretty much the definition of a PWM value. This fraction is represented as a 8:8 fixed-point value, meaning it is multiplied by 256 to map the range [0.0;1.0] into [0;256] - which happens to be a perfect match for the PWM value range.

The speed is in pulses/ms. The motor parameter P5 is the fraction of Vmax the motor generates per speed-puls as a 8:8 fixed-point value, meaning the fraction is multiplied by 256. So all that's required to compensate for the back-EMF voltage is:

    val += P5 * speed;

The result can be fed into the PWM output function tap_voltage. Now the input value does not refer to the total motor voltage anymore but to the voltage across Ri. Because Ri is constant, this is propotional to the current through the motor.

So by one simple calculation the PWM value does not set the motor voltage anymore, but the current - which sets the torque. Slick, isn't it?

More on the idea behind back-EMF compensation for sensorless speed control of brushed DC motors in the application note [AB-026: Sensorless Speed Stabiliser for a DC Motor](https://www.precisionmicrodrives.com/content/ab-026-sensorless-speed-stab by Precision Microdrives.