Pulse density modulation is one alternative to Pulse Width Modulation,
with the advantage of being more easily lossless,
since presence or absense of fixed width pulses at fixed intervals is more robustly detected,
but for driving typical relatively slowly reponding loads,
PWM offers finer granularity at lower implementation cost, and consequently gets used for
- hobby servos
- illumination control
- motor control
- many think of PWM motor control in terms of speed, but PWM more directly controls DC motor torque.
- class D audio amplifiers
Many low cost microcontrollers implement PWM in firmware,
but both STM32 and ESP32 support PWM with full hardware control.
Consequently, instead of using the
generic Arduino PWM library,
this implementation will investigate so-called Fast PWM, which exploits that hardware.
As noted,
these libraries have similar functions, simplifying porting among platforms:
- ESP32_FastPWM
- STM32_PWM
- on GitHub
- It has an undocumented dependency on jfturcot/SimpleTimer,
.. which points to an Arduino Playground entry that is actually for another version by Marcello Romani,
from which it is derived. Marcello has a considerably updated (likely incompatible) version also on GitHub.
FWIW, both SimpleTimer in Arduino Library Manager seem totally different and incompatible; go figure..
16 Mar 2023: working STM32 hardware PWM_FullConfiguration
drives Blue Pill LED, lacks predistortion controls, should be ported to Blue_ASCII_PWM_LED