Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

Hi I need to set two PWMs and so two counters for up down mode and with different CNO initial value.

Firstly I prove for aligned signals (so CN0 initial value 0 for both) but they are not aligned and I don't know why. It seems it depends on which line of code I set the new PWMs, as they can't be created equal to each others.

I set in the right way CN0 e up down counting mode??? Maybe there is a smarter way to do it??

 

IfxGtm_enable(&MODULE_GTM); /* Enable GTM */
gtm_ptr->CTRL.B.RF_PROT=0;
gtm_ptr->CLS_CLK_CFG.B.CLS0_CLK_DIV=01;

 

IfxGtm_Cmu_setClkFrequency(&MODULE_GTM, clkIdx, CLK_F); /* Set the CMU clock 0 frequency */
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_CLK0); /* Enable the CMU clock 0 */

 


//Configuration of the first PWM signal
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig[i], &MODULE_GTM); /* Initialize default parameters */
g_atomConfig[i].atom = OUT.atom; /* Select the ATOM cluster */
g_atomConfig[i].atomChannel = OUT.channel; /* Select the channel */
g_atomConfig[i].period = PWM_PER; /* Set timer period */
g_atomConfig[i].dutyCycle = dutyC; /* Set duty cycle */
g_atomConfig[i].signalLevel = Ifx_ActiveState_low;
g_atomConfig[i].mode = IfxGtm_Atom_Mode_outputPwm;
g_atomConfig[i].synchronousUpdateEnabled = TRUE; /* Enable synchronous update */
g_atomConfig[i].pin.outputPin = &OUT; /* Set a PIN as output */
g_atomConfig[i].pin.outputMode = IfxPort_OutputMode_pushPull;
g_atomConfig[i].immediateStartEnabled=FALSE;

IfxGtm_Atom_Pwm_init(&g_atomDriver[i], &g_atomConfig[i]); /* Initialize the PWM */


atomSFR = &g_atomConfig[i].gtm->ATOM[g_atomConfig[i].atom]; /* variable for Atom-Channel-Functions */
Ifx_GTM_ATOM_CH *atomCh = IfxGtm_Atom_Ch_getChannelPointer(atomSFR, g_atomConfig[i].atomChannel); /* Pointer to Channel address & Control-Register */
atomCh->CN0.B.CN0=0;

atomCh->CTRL.B.UDMODE=0x3;//FOR UP DOWN COUNTING


IfxGtm_Atom_Pwm_start(&g_atomDriver[i], TRUE); /* Start the PWM */

 

 

//Initialization of a second channel with the PWM output inverse

IfxGtm_Atom_Pwm_initConfig(&g_atomConfig_inverse[i], &MODULE_GTM); // Initialize default parameters
g_atomConfig_inverse[i].atom = OUT_INVERSE.atom; // Select the ATOM cluster
g_atomConfig_inverse[i].atomChannel = OUT_INVERSE.channel; // Select the channel
g_atomConfig_inverse[i].period = PWM_PER; // Set timer period
g_atomConfig_inverse[i].dutyCycle =dutyC; //prova con 40 % di duty cycle 40*1000/100;
// Set duty cycle
g_atomConfig_inverse[i].signalLevel = Ifx_ActiveState_low; // Set the SL bit= 0 so to have an inverse signal
g_atomConfig_inverse[i].mode = IfxGtm_Atom_Mode_outputPwm;
g_atomConfig_inverse[i].synchronousUpdateEnabled = TRUE; // Enable synchronous update
g_atomConfig_inverse[i].pin.outputPin = &OUT_INVERSE; // Set a PIN as output
g_atomConfig_inverse[i].pin.outputMode = IfxPort_OutputMode_pushPull;
g_atomConfig_inverse[i].immediateStartEnabled=FALSE;


IfxGtm_Atom_Pwm_init(&g_atomDriver_inverse[i], &g_atomConfig_inverse[i]); // Initialize the PWM
atomSFR_inv = &g_atomConfig_inverse[i].gtm->ATOM[g_atomConfig_inverse[i].atom]; /* variable for Atom-Channel-Functions */
Ifx_GTM_ATOM_CH *atomCh_inv = IfxGtm_Atom_Ch_getChannelPointer(atomSFR_inv, g_atomConfig_inverse[i].atomChannel); /* Pointer to Channel address & Control-Register */
atomCh_inv->CN0.B.CN0=0;


atomCh_inv->CTRL.B.UDMODE=0x3;

IfxGtm_Atom_Pwm_start(&g_atomDriver_inverse[i], TRUE); // Start the PWM

 

 

 

0 Likes
2 Replies
Yuva
Moderator
Moderator
Moderator
250 replies posted 250 sign-ins 100 solutions authored

Hello,

Is this for ATOM channel synchronization? You may need to use the trigger from the preceding channel for this purpose.

Thanks.

robs1
Level 4
Level 4
100 sign-ins 50 replies posted First solution authored

Hi! thank you for your reply yes it is to have channel synchronization but it doesn't work adding this lines to the code:

MODULE_GTM.ATOM[0].CH0.CTRL.B.TRIGOUT = 1; // use compare match as TRIG_[x] so CCU0
MODULE_GTM.ATOM[0].CH1.CTRL.B.TRIGOUT = 0; // TRIG_[x] = TRIG_[x-1]
 MODULE_GTM.ATOM[0].CH1.CTRL.B.RST_CCU0 = 1; // !!! important: CN0 reset by TRIG[x-1], period match of previous channel

Where am I wrong?

Result:

robs1_0-1688374697286.jpeg

 

Thank you for your help

0 Likes