SDAA032 July 2025 TDA4VE-Q1
To change PWM duty rate, write a new value into CMPA register is necessary. There is difficulty for software to update very deterministically, so CMPA register can be updated at incorrect instance and this can cause unintended PWM duty cycle, consequently results in incorrect brightness in LED control or incorrect motor speed and torque control within a short period. To prevent unpredictable update, shadow register update is used instead of immediate register update. Let us try to understand how immediate register update can cause this issue with up-count mode by changing PWM duty rate from 20% to 80%.
Consider an up-count mode PWM configured to go HIGH at TBCNT = 0 and LOW at TBCNT = CMPA. If the CMPA register is updated during the middle of a period, the PWM output can switch to LOW earlier or later than intended in the current cycle, depending on the new CMPA value. This causes a duty cycle distortion lasting for one or more PWM periods.
The following registers configuration can be used to generate 20% of PWM duty cycle in up count mode.
EPWM_TBPRD = 62500
EPWM_TBCTL.CTRMODE = 0 → Up count mode
EPWM_CMPA = 12500 (= 62500 x 20%)
EPWM_CMPCTL.SHDWAMODE = 1 → Immediate modeMake 80% of PWM duty cycle by updating CMPA register as shown in the following.
EPWM_CMPA = 50000 (= 62500 × 80%)Figure 3-1 is PWM signal probed through logic analyzer.
Figure 3-1 Probe PWM Changes During Updating CMPA Register in Up Count ModeThe expectation is that the duty cycle becomes from 20% to 80% directly but there are 25% duty and 83% duty which are not intended.
Figure 3-2 Analyze PWM Duty Cycle Change From 20% to 80% in Up Count ModeThis is analyzed in the following.
The root cause of this behavior lies in the immediate update mode of the CMPA register. In this mode, any new value written to CMPA is used immediately — even if this occurs mid-cycle. Since the PWM logic uses the current CMPA value for compare events, a mid-period change leads to incorrect output timing. This is not a hardware bug but rather a configuration oversight. Immediate updates are valid in some cases, but for dynamic duty cycle adjustment during operation, updates are not safe.