Skip to main content

Subsection 11.1.1 How a DC Motor Works

Figure 11.1.1. A short animation of how a brushed DC motor works. Watch it before reading on, since the moving picture makes the link between the current, the magnetic field, and the rotation much easier to follow than words alone.
Inside a DC permanent-magnet motor, current flows through coils wound around a rotating armature. That current sets up a magnetic field, and the permanent magnets in the motor’s housing push against it. The push is a force on the armature, so the armature turns. A commutator keeps switching the direction of the current in the coils as the shaft rotates, so the push always drives the rotation the same way.
Two relationships describe how the motor behaves. The first is that the torque, the turning force, is proportional to the current through the coils: the more current we push through, the harder the motor turns. The second is that a spinning motor also generates a voltage. A coil moving through a magnetic field generates a voltage of its own, and a spinning motor is exactly that: it acts as a small generator, producing a voltage that opposes the supply and is proportional to speed. We call this the back-EMF (back electromotive force). At steady speed the supply voltage, the back-EMF, and the resistance of the coils balance out, and so the steady speed is roughly proportional to the voltage across the motor’s terminals.
Direction is set by polarity. Reverse the voltage across the terminals and the current reverses, the force reverses, and the motor turns the other way. So to control a motor from the STM32C031C6 we have two things to arrange: a way to reverse the polarity of the motor’s voltage, which sets its direction, and a way to vary the average value of that voltage, which sets its speed. The rest of this reading is about why neither one is something a GPIO pin can do on its own.