Figure shown below illustrates a Pulse Width Modulation (PWM) signal.
The PWM signal is defined by the following variables
– length of the pulse – period of the PWM signal. – maximal (voltage) value of the PWM signal.
The frequency of the PWM signal is
(1)
The duty cycle is defined by
(2)
In the STM32 development environment, we select the frequency of the PWM signal by using the three parameters
(3)
where
is the frequency of a timer clock of an STM32 microcontroller. is the prescaler value.-
is the period value.
The frequency the time clock
In the STM32CubeIDE development environment:
- The period
is called “Auto Reload Register” which is abbreviated by ARR. That is, .
In the STM32CubeIDE environment, the duty cycle is determined by
(4)
where
Let us illustrate this with an example. Let us suppose that we want to generate a PWM signal with the frequency of
(5)