Synchronizing two PWM hardware elements for a constant phase shift

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

Greetings!

Using the PSOC 6 Pioneer kit (PSOC 62 processor).

I have two PWM blocks that share the same clock source.  Is there a way to create a phase shift, so that the two PWM outputs are synchronized, with a constant phase shift between them?

In other words, they are the exact same frequency and duty cycle, but one would be a delayed output of the other?

0 Likes
1 Solution
TrEn_4626211
Level 1
Level 1
First like received

Hi RiTa_288331

Cy_TCPWM_TriggerStart API is intended to trigger one or more TCPWMs at once.

So, to implement needed by you functionality, I used this API, but changed starting counter value for one of PWMs:

uint32_t PHASE_SHIFT = 20;

(void)Cy_TCPWM_PWM_Init(pwm_1_HW, pwm_1_NUM,  &pwm_1_config);

(void)Cy_TCPWM_PWM_Init(pwm_2_HW, pwm_2_NUM,  &pwm_2_config);

Cy_TCPWM_PWM_Enable(pwm_1_HW, pwm_1_NUM);

Cy_TCPWM_PWM_Enable(pwm_2_HW, pwm_2_NUM);

Cy_TCPWM_PWM_SetCounter(pwm_1_HW, pwm_1_NUM, PHASE_SHIFT);

/* pwm_1 and pwm_2 should belong to same TCPWM block group (TCPWM0 or TCPWM1) */

Cy_TCPWM_TriggerStart(pwm_1_HW, pwm_1_MASK | pwm_2_MASK);

Here is how it look like on logical analyzer for waveform with 25% duty cycle:

pastedImage_8.png

Good luck with development on PSoC!

View solution in original post

2 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

RiTa,

Consult the PWM datasheet.  It indicates how to link multiple PWMs together to be synchronized.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
TrEn_4626211
Level 1
Level 1
First like received

Hi RiTa_288331

Cy_TCPWM_TriggerStart API is intended to trigger one or more TCPWMs at once.

So, to implement needed by you functionality, I used this API, but changed starting counter value for one of PWMs:

uint32_t PHASE_SHIFT = 20;

(void)Cy_TCPWM_PWM_Init(pwm_1_HW, pwm_1_NUM,  &pwm_1_config);

(void)Cy_TCPWM_PWM_Init(pwm_2_HW, pwm_2_NUM,  &pwm_2_config);

Cy_TCPWM_PWM_Enable(pwm_1_HW, pwm_1_NUM);

Cy_TCPWM_PWM_Enable(pwm_2_HW, pwm_2_NUM);

Cy_TCPWM_PWM_SetCounter(pwm_1_HW, pwm_1_NUM, PHASE_SHIFT);

/* pwm_1 and pwm_2 should belong to same TCPWM block group (TCPWM0 or TCPWM1) */

Cy_TCPWM_TriggerStart(pwm_1_HW, pwm_1_MASK | pwm_2_MASK);

Here is how it look like on logical analyzer for waveform with 25% duty cycle:

pastedImage_8.png

Good luck with development on PSoC!