Pulse Width Modulator (TCPWM_PWM_PDL) PSoC 6, PSoC Creator 4.2

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

cross mob
Anonymous
Not applicable

How can I write period and compare values in multiple Pulse Width Modulator (TCPWM_PWM_PDL) blocks simultaneously or in sync manner?

0 Likes
1 Solution
MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

To add to rlos​'s points, you can also use "Cy_TCPWM_TriggerReloadOrIndex" API to synchronously reload all the counters of a TCPWM block after you have configured all the PWM's period/duty. Optionally you can use TriggerStop and TriggerStart APIs in conjunction to avoid running a PWM while you are updating others.

View solution in original post

0 Likes
13 Replies
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

I see a few options:

1. You can disable multiple instances of the TCPWM using the Disable_Multiple() API, then update the compare/period values of all instances, then enable them using the Enable_Multiple() API

2. You can use DMA to update them. There are two DMA Controllers, so you can update two instances of the TCPWM simultaneously.

MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

To add to rlos​'s points, you can also use "Cy_TCPWM_TriggerReloadOrIndex" API to synchronously reload all the counters of a TCPWM block after you have configured all the PWM's period/duty. Optionally you can use TriggerStop and TriggerStart APIs in conjunction to avoid running a PWM while you are updating others.

0 Likes
Anonymous
Not applicable

Many thanks for your replies.

Cy_TCPWM_Enable_Multiple(PWM_1_HW,PWM_S_CNT_MASK);

Cy_TCPWM_Enable_Multiple(PWM_2_HW,PWM_S_CNT_MASK);

Cy_TCPWM_Disable_Multiple(PWM_1_HW, PWM_S_CNT_MASK);

Cy_TCPWM_Disable_Multiple(PWM_2_HW,PWM_S_CNT_MASK);

Cy_TCPWM_Enable_Multiple(PWM_1_HW,PWM_S_CNT_MASK);

Cy_TCPWM_Enable_Multiple(PWM_2_HW,PWM_S_CNT_MASK);

But still, these APIs allowing me to enable/disable one TCPWM block at a time. Again, I have multiple TCPWM blocks, and I guess trigger and reload etc commands are for one particular TCPWM block.

0 Likes

muhammad.yaqoob_1490236​,

Just to clarify one thing, there are only 2 TCPWM blocks in PSoC 6.

>> TCPWM block 0 supports 8 32-bit counters/PWMs.

>> TCPWM block 1 supports 2416-bit counters/PWMs.

Thus PSoC 6 supports up to 32 TCPWM counters (not blocks).

So if you chose only 16-bit PWMs, then all the counters will be placed in TCPWM block 1. If you select 32-bit PWMs, then all gets placed in TCPWM block 0.

I believe by multiple TCPWM blocks, you are referring to multiple TCPWM counters. If that is the case, then all you need to do is make sure all the PWMs are of same resolution (16 or 32-bit) and then use the "Cy_TCPWM_Enable_Multiple(PWM_1_HW, MASK_OF_ALL_PWMS)" where MASK_OF_ALL_PWMS is a logical OR of all the CNT_MASK macros of your PWMs.

Same applies to Trigger APIs.

Let me if this helps.

Regards,

Meenakshi Sundaram R

Anonymous
Not applicable

This:

Cy_TCPWM_Disable_Multiple(PWM_1_HW, PWM_1_CNT_MASK || PWM_2_CNT_MASK );

?

with two TCPWM counters (16 bit), i.e., PWM_1 and PWM_2.

0 Likes

Yes, this should disable both the counters with a single write (as it is a single register which has the enable bit for all 16-bit counters).

0 Likes
Anonymous
Not applicable

Shouldn't it be a bitwise OR? e.g. Cy_TCPWM_Disable_Multiple(PWM_1_HW, PWM_1_CNT_MASK | PWM_2_CNT_MASK );

A logical OR will return true (1).

0 Likes

Ohh yeah missed to see the ORing in the line. It should '|' and not '||'.

0 Likes
Anonymous
Not applicable

PWM_1_Start();

PWM_2_Start();

Cy_TCPWM_Disable_Multiple(PWM_1_HW,PWM_1_CNT_MASK|PWM_2_CNT_MASK);

Cy_TCPWM_Enable_Multiple(PWM_1_HW, PWM_1_CNT_MASK|PWM_2_CNT_MASK);

I have used above mentioned code. However, I can disable but enable back doesn't work, not even with below-mentioned code:

PWM_1_Start();

PWM_2_Start();

PWM_1_Disable();
PWM_2_Disable();

PWM_1_Enable();

PWM_2_Enable();

0 Likes

I think I missed one another thing.

Disabling and re-enabling the PWM does not start it. You need to trigger a start signal as well from either software or hardware.

Cy_TCPWM_TriggerStart(PWM_1_HW, PWM_1_CNT_MASK|PWM_2_CNT_MASK);

As I mentioned earlier, you can use this API Cy_TCPWM_TriggerReloadOrIndex(PWM_1_HW, PWM_1_CNT_MASK|PWM_2_CNT_MASK); This API will reload the counters at the same. Equivalent to starting them all at the same time.

Anonymous
Not applicable

Reload works outside of for (;;) loop but inside it doesn't. Moreover, period and compare values of counters are coming from an equation being solved within a for(;;) loop.

0 Likes
Anonymous
Not applicable

Would this be a right approach?

for(;;)

{

Cy_TCPWM_TriggerCaptureOrSwap(PWM_1_HW, PWM_1_CNT_MASK|PWM_2_CNT_MASK);

f='an equation involving floating point calculations and few variables';

x='an equation involving floating point calculations and few variables';

PWM_1_SetPeriod0(f);

PWM_2_SetPeriod0(f);

PWM_1_SetCompare0(x);

PWM_2_SetCompare0(x);

Cy_TCPWM_TriggerCaptureOrSwap(PWM_1_HW, PWM_1_CNT_MASK|PWM_2_CNT_MASK);     

f='an equation involving floating point calculations and few variables';

x='an equation involving floating point calculations and few variables';

PWM_1_SetPeriod1(f);

PWM_2_SetPeriod1(f);

PWM_1_SetCompare1(x);

PWM_2_SetCompare1(x);

I did a swap between 0 and 1 reg of periods and compare.

0 Likes
Leonard_Xiao
Employee
Employee
5 questions asked 50 sign-ins 5 likes given

For TCPWM version 2, the function Cy_TCPWM_Enable_Multiple() is not supported.

0 Likes