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

cross mob
Not applicable
Hi All,

I am wondering if there is an error in the "PWMSP002_SetPwmFreqAndDutyCycle" function when it calculates the timer value if concatenation is required. My PWMSP002 is configured for Edge Aligned Counting Mode and Symetric Compare Mode.

The function calculates the count to load into the CCU80_CC80.PRS and CCU80_CC81.PRS shadow registers for the required PWM period.

The calculation is actually performed by the "CCU8PWMLIB_lSetPwmFreqTimerConcat" function in the CCU8PWMLIB.c library (code snippet visible in screenshhots).

In the fist example below the MSB and LSB period counts are correct, the second example with a count greater than 65535 the counts seem wrong...

Example 1 (correct)
PwmTime = 65535
Call to CCU8PWMLIB_lSetPwmFreqTimerConcat

Result
MsbPeriodVal = 0x00
LsbPeriodVal = 0xFFFF

806.attach


Example 2 (incorrect ?)
PwmTime = 65536
Call to CCU8PWMLIB_lSetPwmFreqTimerConcat

Result
MsbPeriodVal = 0x3
LsbPeriodVal = 0x3FFF

807.attach


Am I missing something ?

Any help would be greatly appreciated.

Best regards
Aaron
0 Likes
8 Replies
Not applicable
I have also noticed a possible problem with the calculation of the duty cycle count which is done within the "CCU8PWMLIB_SetDutyEdgeAlignSymmetricTimerConcat" function when timers are concatenated to achieve the desired period time.

For example...

If the Period count in CCU80_CC80.PRS and CCU80_CC81.PRS is 65535 and a DutyCycle of 99.5 is requested the result is 327 (0.5 % of 65535 which is correct)

If the Period count in CCU80_CC80.PRS and CCU80_CC81.PRS is 65536 and a DutyCycle of 99.5 is requested the result is 655 (0.5 % of 65536 should be 327 still ?)


Best regards
Aaron
0 Likes
Not applicable
Hi Aaron,

Just to confirm:
1) Was the timer concatenation not set as per initial PWM frequency (eg. 1500Hz by default) in PWMSP002 GUI?
2) Did you try to call PWMSP002_SetPwmFreqAndDutyCycle() API to change the PWM frequency during run time which requires timer concatenation (eg. 500Hz)?

If the answers are "Yes" for both questions, then I regret to tell you that it will not work always due to the limitation of this App (eTicket 841909820).

Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia,

Thanks for your reply.

My PWMSP002 App is configured for 2Hz with concatenation before code generation and I am setting a frequency of 10Hz at run time.

813.attach


The "CCU8PWMLIB_lSetPwmFreqTimerConcat" library function code to calculate the high counter value looks a little strange...

  if(PwmTime > CCU8PWMLIB_MAX_VALUE)
{
do
{
PeriodVal = PeriodVal >> 1U;
Count++;
}while(PeriodVal >= CCU8PWMLIB_MAX_VALUE);
MsbPeriodVal = ((uint32_t)1 << Count) -1U;
LsbPeriodVal = PeriodVal;
}
else
{
LsbPeriodVal = PwmTime;
MsbPeriodVal = 0U;
}


I replaced this code with my own and concatenation appears to work correctly...

  if(PwmTime > CCU8PWMLIB_MAX_VALUE)
{
MsbPeriodVal = PwmTime >> 16;
LsbPeriodVal = PwmTime & 0x0000FFFF;
}
else
{
LsbPeriodVal = PwmTime;
MsbPeriodVal = 0U;
}





Is there something else I am doing wrong ?

Best regards
Aaron
0 Likes
Not applicable
Hi Aaron,

It has been forwarded further. Will update you once get reply.

Best regards,
Sophia
0 Likes
Not applicable
Hi Aaron,

I have no problem if using PWMSP002_SetPwmFreqAndDutyCycle() API to change the PWM frequency during run time unless using PWMSP002_SetPwmFreq() API only (eTicket 171922682).
Attached example for your reference.


Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia,

Thank you for your help. My mistake, I think I've worked out how the concatenated timers work !

Please can you confirm....

High Slice value____Low Slice value____Timer operation
0x0000____________ 0xFFFF___________Counts up to 0xFFFF
0x0001____________ 0x8000____________Counts up to 0x8000 x 2 which is 0x10000 (it does not count up to 0x18000)

Best regards
Aaron
0 Likes
Not applicable
Hi Aaron,

During the timer concatenation, whenever lower timer has exceeded the max period value, higher timer will count +1, and then lower timer will restart from zero.
This will go on unless higher timer reached the max period value.

Best regards,
Sophia
0 Likes
Not applicable
Hi All,

It seems the root cause of my problems with the PWMSP002 App were due to the "PWMSP002_SetTimerVal()" function so this post is now resolved.

http://www.infineonforums.com/threads/2198-PWMSP002_SetTimerVal-uses-a-different-method-to-PWMSP002_...

Best regards
Aaron
0 Likes