Skip to content

output hardware

doomke edited this page Sep 28, 2023 · 4 revisions

PWM frequency restrictions

When using pulse width modulation to control the power of an output, restrictions of the output system must be considered. While the ESP32 is capable of producing PWM signals in the range of several $\mathrm{kHz}$, and passive components like resistors are able to follow those with ease, active components like transistors, MOSFETs or optocouplers are more limited.

Two parameters are typically used to characterize a such output components:

  1. The time $t_\mathrm{ON}$ between activation of a control signal and full activation of the corresponding output.
  2. The time $t_\mathrm{OFF}$ between deactivation of a contral signal and full deactivation of the corresponding output.

For most optocouplers and solid state relays those are in the range of $t_\mathrm{ON} + t_\mathrm{OFF} \approx 1 \, \mathrm{ms}$, which corresponds to the maximum frequency

$$f_\mathrm{max} = \frac{1}{t_\mathrm{ON} + t_\mathrm{OFF}} \approx 1 \, \mathrm{kHz}.$$

However, when the output power is to be controled by PWM, the range of usable frequencies is even more restricted. Using an $8$ bit control value and a PWM frequency of $f$, this results in $255$ different power output levels (excluding $0$ or "off"). To use the full range, a full on/off cycle of the output component must therefore be smaller than $\frac{1}{255}$ of the control signal period or $f_\mathrm{max} \leq 255 f$.

Whenever the output is unable to follow this higher frequency, a reduced number of effective output states $n_\mathrm{eff}$ is the result. Before a minimum control value $n_\mathrm{min}$ is chosen, the output is unable to fully switch on before the control signal is turned off again:

$$n_\mathrm{min} = 255 \cdot f \cdot \left( t_\mathrm{ON} + t_\mathrm{OFF} \right)$$

On the other hand, whenever the the control value is higher than $n_\mathrm{max}$, the output will be unable to turn off completely:

$$n_\mathrm{max} = 255 - n_\mathrm{min}.$$

In both cases the actual power output might be nonlinear and the control value does not accurately represent it. The following table shows the approximate control value ranges for an optocoupler with $f_\mathrm{max} = 1 \, \mathrm{kHz}$.

$f / (\mathrm{Hz})$ $n_\mathrm{eff}$ $n_\mathrm{min}$ $n_\mathrm{max}$
0.5 255 0 255
10 250 3 252
20 245 5 250
30 240 8 247
40 235 10 245
50 230 13 242
100 204 26 230
150 179 38 217
200 153 51 204
250 128 64 191
300 102 77 179
350 77 89 166
400 51 102 153
450 26 115 140
500 0 128 128

General

Guides

Principle of Operation

Modules

Software Hardware
camera camera
infoLED infoLED
input input
macro macro
output output
servo servo
socket socket
stepper stepper
WiFi wifi

Clone this wiki locally