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
User19757
Level 1
Level 1
Hi,

I would like to expand on the sample code below.
How can I make each of the 4 LEDs on the board glow with a different Duty?


# AURIX TC3xx Expert Trainings - GTM_ATOM_PWM_1_KIT_TC397_TFT
 https://www.infineon.com/dgdl/Infineon-AURIX_GTM_ATOM_PWM_1_KIT_TC397_TFT-Training-v01_00-EN.pdf?fil...
# GitHub
 https://github.com/Infineon/AURIX_code_examples/tree/master/code_examples/GTM_ATOM_PWM_1_KIT_TC397_T...
0 Likes
3 Replies
User19757
Level 1
Level 1
I'm sorry.

If the clocks were common, this could be accomplished by simply duplicating "g_atomConfig" and "g_atomDriver".
(When I first tried it, some of the code to duplicate was missing.)

The issues in this thread have been resolved.
0 Likes
User19978
Level 1
Level 1
Hi...
May I get the code for the same query to operate 4LEDs using ATOM
0 Likes
User19757
Level 1
Level 1
Hi,

I'm afraid I simply copied the sample code...
(This will cause LEDs 1-4 on the application kit to flash differently.)




/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
#define ISR_PRIORITY_ATOM 20 /* Interrupt priority number */
#define LED IfxGtm_ATOM2_5_TOUT91_P13_0_OUT /* LED which will be driven by the PWM */
#define LED2 IfxGtm_ATOM2_6_TOUT92_P13_1_OUT
#define LED3 IfxGtm_ATOM2_7_TOUT93_P13_2_OUT
#define LED4 IfxGtm_ATOM3_0_TOUT94_P13_3_OUT
#define CLK_FREQ 1000000.0f /* CMU clock frequency, in Hertz */
#define PWM_PERIOD 5000 /* 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_atomConfig; /* Timer configuration structure */
IfxGtm_Atom_Pwm_Config g_atomConfig2;
IfxGtm_Atom_Pwm_Config g_atomConfig3;
IfxGtm_Atom_Pwm_Config g_atomConfig4;
IfxGtm_Atom_Pwm_Driver g_atomDriver; /* Timer Driver structure */
IfxGtm_Atom_Pwm_Driver g_atomDriver2;
IfxGtm_Atom_Pwm_Driver g_atomDriver3;
IfxGtm_Atom_Pwm_Driver g_atomDriver4;
uint32 g_fadeValue = 0; /* Initialization of the fade value */
uint32 g_fadeValue2 = 0;
uint32 g_fadeValue3 = 0;
uint32 g_fadeValue4 = 0;
sint8 g_fadeDir = 1; /* Initialization of the fade direction variable */

/*********************************************************************************************************************/
/*-----------------------------------------------Function Prototypes-------------------------------------------------*/
/*********************************************************************************************************************/
void setDutyCycle(uint32 dutyCycle);
void setDutyCycle2(uint32 dutyCycle);
void setDutyCycle3(uint32 dutyCycle);
void setDutyCycle4(uint32 dutyCycle);

/*********************************************************************************************************************/
/*--------------------------------------------Function Implementations-----------------------------------------------*/
/*********************************************************************************************************************/
/* This function initializes the ATOM */
void initGtmATomPwm(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 */

IfxGtm_Atom_Pwm_initConfig(&g_atomConfig, &MODULE_GTM); /* Initialize default parameters */
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig2, &MODULE_GTM);
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig3, &MODULE_GTM);
IfxGtm_Atom_Pwm_initConfig(&g_atomConfig4, &MODULE_GTM);

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

g_atomConfig2.atom = LED2.atom;
g_atomConfig2.atomChannel = LED2.channel;
g_atomConfig2.period = PWM_PERIOD;
g_atomConfig2.pin.outputPin = &LED2;
g_atomConfig2.synchronousUpdateEnabled = TRUE;

g_atomConfig3.atom = LED3.atom;
g_atomConfig3.atomChannel = LED3.channel;
g_atomConfig3.period = PWM_PERIOD;
g_atomConfig3.pin.outputPin = &LED3;
g_atomConfig3.synchronousUpdateEnabled = TRUE;

g_atomConfig4.atom = LED4.atom;
g_atomConfig4.atomChannel = LED4.channel;
g_atomConfig4.period = PWM_PERIOD;
g_atomConfig4.pin.outputPin = &LED4;
g_atomConfig4.synchronousUpdateEnabled = TRUE;


IfxGtm_Atom_Pwm_init(&g_atomDriver, &g_atomConfig); /* Initialize the PWM */
IfxGtm_Atom_Pwm_init(&g_atomDriver2, &g_atomConfig2);
IfxGtm_Atom_Pwm_init(&g_atomDriver3, &g_atomConfig3);
IfxGtm_Atom_Pwm_init(&g_atomDriver4, &g_atomConfig4);
IfxGtm_Atom_Pwm_start(&g_atomDriver, TRUE); /* Start the PWM */
IfxGtm_Atom_Pwm_start(&g_atomDriver2, TRUE);
IfxGtm_Atom_Pwm_start(&g_atomDriver3, TRUE);
IfxGtm_Atom_Pwm_start(&g_atomDriver4, TRUE);
}

/* This function is creating the fade effect for the LED */
void fadeLED(void)
{
if(g_fadeValue >= PWM_PERIOD)
{
g_fadeValue = 0; /* Set the direction of the fading */
}
if(g_fadeValue2 >= PWM_PERIOD)
{
g_fadeValue2 = 0; /* Set the direction of the fading */
}
if(g_fadeValue3 >= PWM_PERIOD)
{
g_fadeValue3 = 0; /* Set the direction of the fading */
}
if(g_fadeValue4 >= PWM_PERIOD)
{
g_fadeValue4 = 0; /* Set the direction of the fading */
}

/* Calculation of the new duty cycle */
g_fadeValue += FADE_STEP;
g_fadeValue2 += PWM_PERIOD / 50;
g_fadeValue3 += PWM_PERIOD / 25;
g_fadeValue4 += PWM_PERIOD / 10;

/* Set the calculated duty cycle */
setDutyCycle(g_fadeValue);
setDutyCycle2(g_fadeValue2);
setDutyCycle3(g_fadeValue3);
setDutyCycle4(g_fadeValue4);

}

/* This function sets the duty cycle of the PWM */
void setDutyCycle(uint32 dutyCycle)
{
g_atomConfig.dutyCycle = dutyCycle; /* Set duty cycle */
IfxGtm_Atom_Pwm_init(&g_atomDriver, &g_atomConfig); /* Re-initialize the PWM */
}

void setDutyCycle2(uint32 dutyCycle)
{
g_atomConfig2.dutyCycle = dutyCycle;
IfxGtm_Atom_Pwm_init(&g_atomDriver2, &g_atomConfig2);

}

void setDutyCycle3(uint32 dutyCycle)
{
g_atomConfig3.dutyCycle = dutyCycle;
IfxGtm_Atom_Pwm_init(&g_atomDriver3, &g_atomConfig3);
}

void setDutyCycle4(uint32 dutyCycle)
{
g_atomConfig4.dutyCycle = dutyCycle;
IfxGtm_Atom_Pwm_init(&g_atomDriver4, &g_atomConfig4);
}
0 Likes