Because I built a functioning ESC, from scratch! Here it is!
An electronic speed controller (ESC) is a device used to control BLDC motors.
A brushless direct-current motor (BLDC motor) is a motor that does not contain physical brushes between the bell/core and stator, which are the rotating/stationary portions of a motor respectively. However, the name is a misnomer. These motors are not DC; far from it. The name comes from the fact that ESCs take DC current. The motors themselves operate on 3-phase alternating current.
The name is a little scary. But it's really not that complicated. Let's break it down into 3 fundamental concepts.
When current flows through a wire, it creates a magnetic field. And when combined with something ferromagnetic, like an iron nail, the field strength can be significantly increased. Inside a brushless motor stator, you'll find several electromagnets just like this.
The diagram to the left depicts an electromagnet getting energized in 2 distinct ways. On the left, current flows through the magnet right-to-left. On the right, current flows through the magnet left-to-right.
The direction that current flows through the copper coil alters the electromagnet's pole. This means a permanent magnet on one end can either be attracted or repelled. In this instance, the left magnet attracts the small gray magnet, while the right magnet repells it.
Notice how we switch the direction of current here; another way to say this is we alternate the current.
By alternating the current in several electromagnets oriented circumferentially, we can drag a magnet around in a cirlce. The GIF on the right illustrates this beautifully. The 3 electromagnets, or 3 phases are turning on and off to pull the magnet around.
Look closely at one of the phases; notice how sometimes, red is inward, and sometimes, blue is? This is alternating current at work. We're getting double usage out of those electromagnetic phases. Sometimes, they're pulling the permanent magnet. Sometimes, they're pushing it. But in both cases, they're applying torque to the magnet to spin it around.
Let's review.
You can make a magnet that turns on and off with electricity.
You can change that magnet's poles by changing which direction electricity flows; pushing or pulling a permanent magnet.
If you mount those electromagnets in a circle with a permanent magnet in the center, you can push or pull on that magnet to make it spin by alternating the current in the coils.
Ok - so what is 3-phase alternating current?
It's a fancy way of saying we're alternating the current in 3 electromagnets. Or, in modern brushless motors, 3 groups of electromagnets. Even though some motors have more than 3 electromagnets - they always have multiples of 3, because they are always tied together into 3 "phases" or groups of magnets.
Fundamentally, energizing these coils one way or another at the right time is all an ESC needs to do. That is literally it.
With some clever wiring, we can make a circuit comprised of 6 on-off switches that can push current through those 3 phases in either direction. Let's take a look at it.
Let the 3 colored loops, Phase A, Phase B, and Phase C represent the electromagnetic coils in the motor.
Let the 6 switches, 1,2,3,4,5,6 represent... switches.
Finally, note that the top of the circuit is positive and the bottom is negative.
Let's see what happens to the phases when we turn on and off some of these switches.
Here's what you definitey DON'T want to do. Close switches 1 & 2 at the same time, or 3 & 4, or 5 & 6. Why? Because if you do, you're creating a direct short from + to - ! Your battery will EXPLODE!
Phase B, Current Left-to-Right
Here's what you DO want to do! If you close switch 1 and switch 4, current will flow through phase B, left-to-right.
Alternatively (pun absolutely intended), if you close switch 2 and 3, current will flow through phase B, right-to-left.
Phase B, current Right-to-Left
This is fundamentally what an ESC is. 6 on-off switches. In the most basic case, they toggle like so, which steps a brushed motor through one rotation. The speed at which you toggle them corresponds to your motor speed.
They are N-Channel Mosfets 99% of the time. Sometimes, the switches closer to positive, or the high-side switches, are P-Channel Mosfets. Mosfets are basically solid-state relays. They are beefy on-off switches that can be triggered with a lower voltage signal, very quickly. If you want to learn more about N channel and P channel mosfets, this is a good resource, but the basic thing you need to know here is that it is challenging to use N channel mosfets for the high-side switches, and using P channel mosfets, while easier, results in a significantly worse ESC.
This explanation pertains only to N-Channel mosfets. P-Channel mosfets are a little different.
Mosfets have 3 terminals, and here's what they do.
Source: beefy switch input/output
Gate: use this to turn on/off the beefy switch.
Drain: beefy switch input/output
If you google mosfet, you'll see a lot of people talking about VGS. This stands for voltage from gate to source. On an N channel mosfet, VGS must be beyond a certain threshold for the mosfet to "activate" or "turn on" (allow current to flow through source and drain).
Shawty got Low Low Low
On the low side this is a piece of cake. Stick the source pin on ground, and as long as the gate is sufficiently higher than ground, the mosfet opens. On logic level mosfets, VGS can be quite low; 5 volts sometimes. So, a standard arduino can turn the mosfet on and off no problem.
Shawty got High High High (Which is bad - because drugs, are bad.)
On the high side this is difficult. That's because you have no choice but to wire the source pin to vbat. And that means that to turn the mosfet on, you need the gate voltage to be HIGHER than the source voltage; which is vbat. So, uh, how the heck do you even do that??? Well... you're gonna need a gate driver. They're kinda complex; and I won't explain them here. But... just think of them as relatively complicated additions to your circuit.
Remember above how I told you what not to do? Well, you really don't want to do that. And if you're spinning a motor really quickly, your switches are turning on and off thousands of times per second. And if for even one god damn microsecond you close the wrong switch, your ESC instantly explodes and probably also your battery.
To avoid this shoot through, you need dead time. This is time where both the high and low side switch of a given phase are off so you don't accidentally make a short circuit. Inserting this dead time, as well as switching the switches quickly in the first place, very quickly becomes nontrivial at high motor speeds. This means you need extremely advanced microprocessors, like the STM32G4, which has hardware timers that are designed specifically to solve this problem.
Sometimes, gate-driver ICs have programmable deadtime as well, which is how my only working ESC works. It uses a teensy 4.0, which is not nearly as good as an STM32 for this purpose, but gets its deadtime from gate driver IC's that control both the low and high side switches per-phase.
Like most engineering, ESCs are simple in principal but hard in practice. In essence, they are 6 on-off switches. In practice, they're a masterclass in precision hardware timing, EMI reduction, mosfet feathering, BEMF detection, and so much more.
Don't let this disuade you though! They are a very fun learning exercise. Just know - making a good one will not be easy. Ask me how I know :)