AURIX _CCU6_PWM_Generation error in some frequency

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

cross mob
User18517
Level 1
Level 1
First reply posted First question asked
Hello

I use aurix development studio to learn AURIX tc297.

when I used the demo "CCU6_PWM_Generation" to generate the PWMs with a lower frequency, for example 5000Hz (modify the marco "#define PWM_FREQUENCY 5000"), I cannot get a valid pwm signal.

I check the code some time, and not find any reason, can any one can help me?

Thank you.
0 Likes
2 Replies
teoBits
Employee
Employee
5 sign-ins 100 replies posted 50 replies posted
Hello,

When you modify the macro for the frequency of the PWM signals, all the calculations made for the compare values are not necessarily correct anymore because the CCU6_BASE_FREQUENCY is divided internally in order to be able to generate the needed frequency for the PWM signals.

You can overcome this problem by replacing the instructions where the compare values are set to obtain the desired duty cycles during initialization of the CCU6 (inside initCCU6())
    Ifx_TimerValue cmpValues[NUMBER_OF_CHANNELS];
cmpValues[0] = CHANNEL1_COMPARE_VALUE; /* Set the compare value for channel 1 */
cmpValues[1] = CHANNEL2_COMPARE_VALUE; /* Set the compare value for channel 2 */
cmpValues[2] = CHANNEL3_COMPARE_VALUE; /* Set the compare value for channel 3 */


with the following:
    Ifx_TimerValue cmpValues[NUMBER_OF_CHANNELS];
cmpValues[0] = g_timer.base.period * (1 - DUTY_CYCLE_CH1); /* Set the compare value for channel 1 */
cmpValues[1] = g_timer.base.period * (1 - DUTY_CYCLE_CH2); /* Set the compare value for channel 2 */
cmpValues[2] = g_timer.base.period * (1 - DUTY_CYCLE_CH3); /* Set the compare value for channel 3 */


where DUTY_CYCLE_CH1, DUTY_CYCLE_CH2, DUTY_CYCLE_CH3 are the duty cycles of each signal (which can be a value from 0 to 1) and can be defined as following:

#define DUTY_CYCLE_CH1 0.25
#define DUTY_CYCLE_CH2 0.50
#define DUTY_CYCLE_CH3 0.75


hope it helps,
teoBits
0 Likes
User18517
Level 1
Level 1
First reply posted First question asked
Thank you.
0 Likes