How I Developed the Scout Flight Controller, Part 5: Controlling Brushless Motors with ESC’s and PWM

Tim Hanewich
5 min readAug 21, 2023

--

This article is part of a series documenting the development of a custom quadcopter flight controller from scratch. For a list of the other related articles, please refer to the introductory article found here.

In the previous chapters, we learned that a quadcopter flight controller achieves stable flight by continuously comparing its actual attitude against its desired attitude. This discrepancy, known as the error, is then passed to a crucial component called the PID Controller. The primary responsibility of the PID controller is to determine the precise level of thrust needed for each of the four motors in order to attain the desired attitude or attitude rate of change mentioned earlier.

Now that we have the recommended thrust (throttle) for each motor from the PID controller (refer to the code snippet in the previous chapter), the question arises: How do we effectively apply this throttle to the corresponding motor?

How a Brushless Motor Rotates

A brushless motor operates through the interaction of electric currents and magnetic fields to generate rotational motion. More specifically, brushless motors rely on the principle of magnetic attraction and repulsion.

The above image depicts the basic components of a brushless motor. It consists of two main parts: the stator and the rotor. The stator remains stationary and houses coils of wire, while the rotor, which rotates around the stator, is composed of magnets arranged in a specific pattern.

To achieve rotational motion, the stator’s coils must rapidly alter the magnetic force in each coil shown above. This causes the rotor, which is magnetically attracted and repelled by different poles within the stator, to initiate motion gradually. By rapidly changing the magnetic force in each coil according to a specific sequence, the rotor begins to rotate.

The speed at which these magnetic fields are switched within the motor directly affects the rotation rate of the rotor, thereby generating thrust. To attain the necessary revolutions per minute (RPM) for lifting the quadcopter off the ground, this magnetic field must be switched at an extremely rapid pace — approximately 21,600 times per second, or every 0.00004 seconds! That’s fast!

However, microcontrollers such as the Raspberry Pi Pico used in the Scout Flight Controller, as well as other microcontrollers, lack the capability to switch at such high speeds. As a result, quadcopters rely on a crucial piece of hardware called an electronic speed controller (ESC).

The Role of the ESC

The ESC acts as an intermediary between the microcontroller and the brushless motor. It receives the desired throttle level (RPM speed) specific to each motor from the flight controller and performs the necessary conversion to switch the magnetic fields within the motor at the appropriate rate, achieving the desired throttle level.

The ESC is capable of providing the brushless motor with the required power in the form of three-phase power. The motor’s three wires are soldered directly to the ESC, which converts the desired throttle input from the microcontroller into three-phase power and supplies it to the motor, thus generating rotational force.

Now, the question remains: How does the microcontroller transmit the desired input throttle to the ESC? The ESC employs a communication format known as pulse width modulation (PWM) as the input signal.

Pulse Width Modulation

Pulse Width Modulation, abbreviated as PWM, is a modulation technique commonly used in electronics to control the average power delivered to a device or component. It achieves this by varying the width of pulses in a digital signal. Consider the following graphic:

A PWM signal consists of two essential components: the frequency and the duty cycle.

The frequency of the PWM signal determines the duration of each period within the signal. For instance, if our PWM signal operates at a frequency of 50 Hz, this means each period lasts for 0.02 seconds (1/50 = 0.02).

The duty cycle of the PWM signal defines the duration for which the signal remains at a high voltage level during the frequency period, with the remaining time being at a low voltage level.

For example, at a frequency of 50 Hz, a 50% duty cycle implies that the voltage of the signal remains high for 50% of the time, which is 0.01 seconds, while it remains low for the remaining 50% of the time, also 0.01 seconds. This signal is repeatedly transmitted via the PWM signal wire: high for 0.01 seconds, low for 0.01 seconds, high for 0.01 seconds, low for 0.01 seconds, and so on.

If the frequency remains at 50 Hz but the duty cycle is set to 75%, the voltage will be high for 0.015 seconds and low for 0.005 seconds. This cycle continues to repeat.

Controlling Motor Speed from the Microcontroller

Visually, this is the system implemented to control each of the quadcopter’s four motors:

  • The microcontroller conveys the desired throttle level to the ESC using a PWM signal.
  • The ESC receives the input throttle level, converts it to the appropriate three-phase speed, and switches the magnetic field within the motor’s stator accordingly.
  • Simultaneously, the magnets in the rotor attract and repel against the various coils in the stator, resulting in rotation.

Each of the quadcopter’s four motors will be equipped with an ESC, and the microcontroller will have one PWM signal wire for each motor, enabling precise speed control for each individual motor.

What’s next?

At this stage in the series, we understand that a quadcopter achieves stable flight by continuously comparing its actual rate of attitude change with the desired rate of attitude change. This disparity, known as the error, is subsequently provided to a PID controller, which determines the necessary adjustments in motor thrust to achieve the desired rate of attitude change.

Finally, the PID controller’s recommended thrust level is transmitted to the corresponding motors via a PWM signal into an electronic speed controller (ESC).

In the next chapter, we will explore the hardware side — specifically, how everything is wired together to create a functioning quadcopter.

--

--