- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I write period and compare values in multiple Pulse Width Modulator (TCPWM_PWM_PDL) blocks simultaneously or in sync manner?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ohh yeah missed to see the ORing in the line. It should '|' and not '||'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For TCPWM version 2, the function Cy_TCPWM_Enable_Multiple() is not supported.