center aligned synchronized 3 Phase PWM

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

cross mob
lock attach
Attachments are accessible only for community members.
Curious
Level 2
Level 2
25 sign-ins First like received 5 replies posted

Hello Aurix Community,

 

i'm trying to synchronize my 3 Phase center aligned PWM.

I'm using the ATOM Unit.

For that i want to use the center of the first PWM (CH0) as trigger for the other PWM, as shown in AP32356.

For that i configured the CH0 with TRIGOUT=1 and the other two (CH1 and CH2) with RST_CCU0 = 1.

Unfortunatly my code isn't working. The Period of CH1 and CH2 is alternating and so every second the Signals are not synchron.

All three Phases should have the same Duty Cycle.

Can you see a mistake in my code? Did i miss a setting?

 

Sincerely,

Andreas

 

/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "GTM_ATOM_PWM.h"
#include "Ifx_Types.h"
#include "IfxGtm_Atom_Pwm.h"
#include "IfxGtm_Atom_Dtm_PwmHl.h"

/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_ATOM 20 /* Interrupt priority number */
#define PHASE0_Hi IfxGtm_ATOM0_0_TOUT0_P02_0_OUT //PWM der Phase 0 auf Port 2.0
#define PHASE1_Hi IfxGtm_ATOM0_1_TOUT1_P02_1_OUT //PWM der Phase 1 auf Port 2.1
#define PHASE2_Hi IfxGtm_ATOM0_2_TOUT2_P02_2_OUT
#define PHASE0_Lo IfxGtm_ATOM0_0N_TOUT7_P02_7_OUT
#define PHASE1_Lo IfxGtm_ATOM0_1N_TOUT4_P02_4_OUT
#define PHASE2_Lo IfxGtm_ATOM0_2N_TOUT5_P02_5_OUT

#define CLK_FREQ 100000000.0f /* CMU clock frequency, in Hertz */
#define PWM_PERIOD 0.0001*CLK_FREQ/2 /* PWM period for the ATOM, in ticks */
#define FADE_STEP PWM_PERIOD / 100 /* PWM duty cycle for the ATOM */

/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
IfxGtm_Atom_Pwm_Config g_atomConfig0; /* Timer configuration structure */
IfxGtm_Atom_Pwm_Driver g_atomDriver0; /* Timer Driver structure */
IfxGtm_Atom_Pwm_Config g_atomConfig1; /* Timer configuration structure */
IfxGtm_Atom_Pwm_Driver g_atomDriver1; /* Timer Driver structure */
IfxGtm_Atom_Pwm_Config g_atomConfig2; /* Timer configuration structure */
IfxGtm_Atom_Pwm_Driver g_atomDriver2; /* Timer Driver structure */

Ifx_GTM_ATOM *atomSFR; /* Pointer to ATOM-struct for Atom-Channel-Functions */

uint32 g_dc0 = PWM_PERIOD*0.25; /* Initialization of the fade value */
uint32 g_dc1 = PWM_PERIOD*0.50; /* Initialization of the fade value */
uint32 g_dc2 = PWM_PERIOD*0.75; /* Initialization of the fade value */
/*********************************************************************************************************************/
/*-----------------------------------------------Function Prototypes-------------------------------------------------*/
/*********************************************************************************************************************/
void setDutyCycle(uint32 dutyCycle, IfxGtm_Atom_Pwm_Config atomConfig, IfxGtm_Atom_Pwm_Driver atomDriver);

/*********************************************************************************************************************/
/*--------------------------------------------Function Implementations-----------------------------------------------*/
/*********************************************************************************************************************/
/* This function initializes the GTM */
void initGtm(void)
{
IfxGtm_enable(&MODULE_GTM); /* Enable GTM */

IfxGtm_Cmu_setClkFrequency(&MODULE_GTM, IfxGtm_Cmu_Clk_0, CLK_FREQ); /* Set the CMU clock 0 frequency */
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_CLK0); /* Enable the CMU clock 0 */
}

/* This function initializes the ATOM0_0 */
void initGtmATomPwm0(void)
{
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig0, &MODULE_GTM); /* Initialize default parameters */

g_atomConfig0.atom = PHASE0_Hi.atom; /* Select the ATOM depending on the LED */
g_atomConfig0.atomChannel = PHASE0_Hi.channel; /* Select the channel depending on the LED */
g_atomConfig0.period = PWM_PERIOD; /* Set timer period */
g_atomConfig0.pin.outputPin = &PHASE0_Hi; /* Set LED as output */
g_atomConfig0.synchronousUpdateEnabled = TRUE; /* Enable synchronous update */

atomSFR = &g_atomConfig0.gtm->ATOM[g_atomConfig0.atom]; /* variable for Atom-Channel-Functions */

Ifx_GTM_ATOM_CH *atomCh = IfxGtm_Atom_Ch_getChannelPointer(atomSFR, g_atomConfig0.atomChannel); /* Pointer to Channel address & Control-Register */
atomCh->CTRL.B.UDMODE = 1; /* enabling Up-Down-Counter-Mode, bitwise access to register */
/* Up/down counter mode
Note: This mode is only applicable in SOMP mode.
00B Up/down counter mode disabled: CN0 counts always up
01B Up/down counter mode enabled: CN0 counts up and down, CM0,CM1 are updated if CN0 reaches 0 (i.e. changes from down to up)
10B Up/down counter mode enabled: CN0 counts up and down, CM0,CM1 are updated if CN0 reaches CM0 (i.e. changes from up to down)
11B Up/down counter mode enabled: CN0 counts up and down, CM0,CM1 are updated if CN0 reaches 0 or CM0 (i.e. changes direction)*/

//atomCh->SOMP.B.UDMODE = 3; //anscheinend ist auch ->SOMP Register nutzbar


atomCh->CTRL.B.TRIGOUT = 1; /* enabling Master-Trigger for slaves*/

IfxGtm_Atom_Pwm_init(&g_atomDriver0, &g_atomConfig0); /* Initialize the PWM */
IfxGtm_Atom_Pwm_start(&g_atomDriver0, TRUE); /* Start the PWM */
}

/* This function initializes the ATOM0_1 */
void initGtmATomPwm1(void)
{
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig1, &MODULE_GTM); // Initialize default parameters

g_atomConfig1.atom = PHASE1_Hi.atom; // Select the ATOM depending on the LED
g_atomConfig1.atomChannel = PHASE1_Hi.channel; // Select the channel depending on the LED
g_atomConfig1.period = PWM_PERIOD; // Set timer period
g_atomConfig1.pin.outputPin = &PHASE1_Hi; // Set LED as output
g_atomConfig1.synchronousUpdateEnabled = TRUE; // Enable synchronous update

atomSFR = &g_atomConfig1.gtm->ATOM[g_atomConfig1.atom]; /* variable for Atom-Channel-Functions */

Ifx_GTM_ATOM_CH *atomCh = IfxGtm_Atom_Ch_getChannelPointer(atomSFR, g_atomConfig1.atomChannel); /* Pointer to Channel address & Control-Register */
atomCh->CTRL.B.UDMODE = 1; /* enabling Up-Down-Counter-Mode, bitwise access to register */
atomCh->CTRL.B.RST_CCU0 = 1;


IfxGtm_Atom_Pwm_init(&g_atomDriver1, &g_atomConfig1); // Initialize the PWM
IfxGtm_Atom_Pwm_start(&g_atomDriver1, TRUE); //Start the PWM
}

/* This function initializes the ATOM0_2 */
void initGtmATomPwm2(void)
{
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig2, &MODULE_GTM); // Initialize default parameters

g_atomConfig2.atom = PHASE2_Hi.atom; // Select the ATOM depending on the LED
g_atomConfig2.atomChannel = PHASE2_Hi.channel; // Select the channel depending on the LED
g_atomConfig2.period = PWM_PERIOD; // Set timer period
g_atomConfig2.pin.outputPin = &PHASE2_Hi; // Set LED as output
g_atomConfig2.synchronousUpdateEnabled = TRUE; // Enable synchronous update

atomSFR = &g_atomConfig2.gtm->ATOM[g_atomConfig2.atom]; /* variable for Atom-Channel-Functions */

Ifx_GTM_ATOM_CH *atomCh = IfxGtm_Atom_Ch_getChannelPointer(atomSFR, g_atomConfig2.atomChannel); /* Pointer to Channel address & Control-Register */
atomCh->CTRL.B.UDMODE = 1; /* enabling Up-Down-Counter-Mode, bitwise access to register */
atomCh->CTRL.B.RST_CCU0 = 1;


IfxGtm_Atom_Pwm_init(&g_atomDriver2, &g_atomConfig2); // Initialize the PWM
IfxGtm_Atom_Pwm_start(&g_atomDriver2, TRUE); //Start the PWM
}

void staticDutyCycle()
{
g_atomConfig0.dutyCycle = 1000; /* Set duty cycle */
IfxGtm_Atom_Pwm_init(&g_atomDriver0, &g_atomConfig0); /* Re-initialize the PWM */

g_atomConfig1.dutyCycle = 1000; /* Set duty cycle */
IfxGtm_Atom_Pwm_init(&g_atomDriver1, &g_atomConfig1); /* Re-initialize the PWM */

g_atomConfig2.dutyCycle = 1000; /* Set duty cycle */
IfxGtm_Atom_Pwm_init(&g_atomDriver2, &g_atomConfig2); /* Re-initialize the PWM */
}

 

0 Likes
1 Solution
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi User,

Please set all ATOM channels to SOMP continues counting up mode.

 

 

View solution in original post

0 Likes
1 Reply
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi User,

Please set all ATOM channels to SOMP continues counting up mode.

 

 

0 Likes