Skip to content

Commit b195061

Browse files
jsbatchkartben
authored andcommitted
driver: pwm: infineon: Use PWM buffer updates
Change PWM to use buffers registers instead of writing period and compare directly. This addressses an issue when updating period to a value less than current counter, as demonstrated in the blinky_pwm sample running on the CYW920829M2EVK_02 board. Signed-off-by: John Batch <[email protected]>
1 parent 2702192 commit b195061

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/pwm/pwm_ifx_cat1.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static int ifx_cat1_pwm_init(const struct device *dev)
5454
.runMode = CY_TCPWM_PWM_CONTINUOUS,
5555
.countInputMode = CY_TCPWM_INPUT_LEVEL,
5656
.countInput = CY_TCPWM_INPUT_1,
57+
.enableCompareSwap = true,
58+
.enablePeriodSwap = true,
5759
};
5860

5961
/* Configure PWM clock */
@@ -110,8 +112,14 @@ static int ifx_cat1_pwm_set_cycles(const struct device *dev, uint32_t channel,
110112
if ((period_cycles == 0) || (pulse_cycles == 0)) {
111113
Cy_TCPWM_PWM_Disable(PWM_REG_BASE, data->pwm_num);
112114
} else {
113-
Cy_TCPWM_PWM_SetPeriod0(PWM_REG_BASE, data->pwm_num, period_cycles);
114-
Cy_TCPWM_PWM_SetCompare0Val(PWM_REG_BASE, data->pwm_num, pulse_cycles);
115+
/* Update period and compare values using buffer registers so the new values
116+
* take effect on the next TC event
117+
*/
118+
Cy_TCPWM_PWM_SetPeriod1(PWM_REG_BASE, data->pwm_num, period_cycles);
119+
Cy_TCPWM_PWM_SetCompare0BufVal(PWM_REG_BASE, data->pwm_num, pulse_cycles);
120+
121+
/* Trigger the swap by writing to the SW trigger command register. */
122+
Cy_TCPWM_TriggerCaptureOrSwap_Single(PWM_REG_BASE, data->pwm_num);
115123

116124
if ((flags & PWM_POLARITY_MASK) == PWM_POLARITY_INVERTED) {
117125
config->reg_addr->CTRL &= ~TCPWM_GRP_CNT_V2_CTRL_QUAD_ENCODING_MODE_Msk;

0 commit comments

Comments
 (0)