
How it works
This is ESP-IDF's mcpwm_servo_control example, unchanged. The MCPWM timer counts at 1 MHz with a period of 20,000 ticks, so the signal on GPIO0 repeats every 20 ms. A comparator sets the pulse width from the requested angle, and the program maps -90° to 500 µs and +90° to 2500 µs. Every 500 ms it logs Angle of rotation and moves 2° further, reversing at ±60°.
The servo on the bench has its own mapping, as real servos do: a 1 ms pulse is 0° and a 2 ms pulse is 180°. A programmed angle of 0 gives 1500 µs, the servo's centre at 90°. Because the program spreads its 180° over 2 ms of pulse width and the servo over 1 ms, the horn moves about twice the logged angle away from its 90° centre within that range, and programmed angles beyond ±45° ask for pulses outside 1 to 2 ms. For that part of the sweep the servo rests at its end stop. It takes power from the CoreBoard's 5V pin and shares its ground.
What to watch
Enable verbose in Serial to see each Angle of rotation line and the MCPWM setup messages. The horn swings while the programmed angle is between -45 and 45 and waits at an end stop beyond that. Open Scope on GPIO0 to see the pulse grow and shrink inside its fixed 20 ms frame.
What's on the bench
- ESP32-S31-Function-CoreBoard-1
- Servo
How it's wired
- ESP32-S31-Function-CoreBoard-1 · g0→Servo · sig
- ESP32-S31-Function-CoreBoard-1 · 5v→Servo · vcc
- ESP32-S31-Function-CoreBoard-1 · gnd→Servo · gnd
This project runs prebuilt firmware on the emulated board; open it in the simulator to watch it work and inspect every part live.
Try this
- Compare the horn with the log. A programmed angle of 30 puts the servo near 150°. At 46, the first logged step beyond 45, the horn reaches the 180° stop.
- In Scope, measure a pulse while the log reads 0. It is 1.5 ms wide, and the rising edges stay exactly 20 ms apart whatever the angle.
- Move the signal wire from GPIO0 to another pad. The servo stops following, because the bundled image only drives GPIO0.



