infineon4engi@twitter infineon4engineers infineon@linkedin infineon@youtube
twitter Facebook Linkedin Youtube

Banner_Aurix_Competition Banner_AURIX_Security-Solution Banner_AURIX_Safety_Products ShieldBuddy TC275 Banner_AURIX_OnzerOS Banner_AURIX_DevelopmentStudio


+ Reply to Thread
Results 1 to 4 of 4

Thread: How to output 4 PWMs using the ATOM of the Application Kit TC3x7

  1. #1
    Beginner Beginner NYT is on a distinguished road
    Join Date
    Jun 2020
    Posts
    9
    Points
    110

    How to output 4 PWMs using the ATOM of the Application Kit TC3x7

    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/Infine...72e73cc93f0236
    # GitHub
     https://github.com/Infineon/AURIX_co..._KIT_TC397_TFT

  2. #2
    Beginner Beginner NYT is on a distinguished road
    Join Date
    Jun 2020
    Posts
    9
    Points
    110
    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.

  3. #3
    Beginner Beginner Manu0219 is on a distinguished road
    Join Date
    Jul 2020
    Posts
    2
    Points
    50
    Hi...
    May I get the code for the same query to operate 4LEDs using ATOM

  4. #4
    Beginner Beginner NYT is on a distinguished road
    Join Date
    Jun 2020
    Posts
    9
    Points
    110
    Hi,

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


    <GTM_ATOM_PWM.c>

    /************************************************** ************************************************** *****************/
    /*------------------------------------------------------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);
    }

+ Reply to Thread

Tags for this Thread

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.