52.6.3.3 Changing the Duty Cycle or the Period

It is possible to modulate the output waveform duty cycle or period.

To prevent unexpected output waveform, the user must use PWM_CUPDx to change waveform parameters while the channel is still enabled. The user can write a new period value or duty cycle value in PWM_CUPDx. This register holds the new value until the end of the current cycle and updates the value for the next cycle. Depending on the PWM_CMRx.CPD field, PWM_CUPDx either updates PWM_CPRDx or PWM_CDTYx. Note that even if the update register is used, the period must not be smaller than the duty cycle.

Figure 52-6. Synchronized Period or Duty Cycle Update

To prevent overwriting the PWM_CUPDx by software, the user can use status events in order to synchronize his software. Two methods are possible. In both, the user must enable the dedicated interrupt in PWM_IER at PWM controller level.

The first method (polling method) consists of reading the relevant status bit in the Interrupt Status register (PWM_ISR) according to the enabled channel(s). See the figure below.

The second method uses an Interrupt Service Routine associated with the PWM channel.

Note: Reading PWM_ISR automatically clears the CHIDx flags.
Figure 52-7. Polling Method
Note: Polarity and alignment can be modified only when the channel is disabled.