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
lock attach
Attachments are accessible only for community members.
masoud_iranmehr
Level 1
Level 1
First reply posted First question asked Welcome!

I am using TC275 microcontroller and I want to create PWM generation for three phase motors. I have used both TOM and ATOM timers in order to do that.

But I got no result yet. All pins did not changed their voltage state. 

 

How can I solve this problem?

My code for TOM timer is this:

 

 

#include "GTM_ATOM_PWM.h"
#include "IfxGtm_Tom_Pwm.h"
#include "IfxGtm_Tom_Timer.h"
#include "IfxGtm_Trig.h"
#include "IfxPort.h"


#include "Bsp.h"
#include "IfxCpu.h"
#include "IfxGtm_PinMap.h"
#include "IfxGtm_Tom.h"
#include "IfxGtm_Tom_PwmHl.h"
#include "Ifx_Types.h"
#include <stdbool.h>
#include <stdint.h>




#define USER_INVERTER_PWM_FREQ_HZ (20000U)

IfxGtm_Tom_Timer pwmhl_tom_timer;
IfxGtm_Tom_PwmHl pwmhl_tom_driver;

const IfxGtm_Tom_ToutMapP Ifx_Cfg_ccxCh[3] = {&IfxGtm_TOM1_2_TOUT12_P00_3_OUT,
                                              &IfxGtm_TOM1_4_TOUT14_P00_5_OUT,
                                              &IfxGtm_TOM1_6_TOUT16_P00_7_OUT};
const IfxGtm_Tom_ToutMapP Ifx_Cfg_coutxCh[3] = {
    &IfxGtm_TOM1_1_TOUT10_P00_1_OUT,
    &IfxGtm_TOM1_3_TOUT29_P33_7_OUT,
    &IfxGtm_TOM1_5_TOUT15_P00_6_OUT,
};

void initGtmAtom(void)
{
    boolean status = TRUE;
    Ifx_GTM* gtm = &MODULE_GTM;

    status = IfxCpu_disableInterrupts();

    IfxGtm_enable(gtm);
    float32 frequency = IfxGtm_Cmu_getModuleFrequency(gtm);
    IfxGtm_Cmu_setGclkFrequency(gtm, frequency);
    IfxGtm_Cmu_enableClocks(gtm, IFXGTM_CMU_CLKEN_FXCLK);
    {
        // Setup Timer for PWM Generation
        IfxGtm_Tom_Timer_Config tmrConfig;

        tmrConfig.gtm = gtm;

        tmrConfig.base.frequency = USER_INVERTER_PWM_FREQ_HZ;
        tmrConfig.base.isrPriority = 0;
        tmrConfig.base.isrProvider = IfxSrc_Tos_cpu0;
        tmrConfig.base.minResolution = 0.1e-6;
        tmrConfig.base.trigger.enabled = true;
        //  tmrConfig.base.trigger.dutyCycle = 0.5;
        tmrConfig.base.trigger.isrPriority = 0;
        tmrConfig.base.trigger.isrProvider = IfxSrc_Tos_cpu0;
        // tmrConfig.base.trigger.outputFeature = 0;
        // tmrConfig.base.trigger.outputOption = 0;
        tmrConfig.base.trigger.outputMode = IfxPort_OutputMode_pushPull;
        tmrConfig.base.trigger.outputDriver =
            IfxPort_PadDriver_cmosAutomotiveSpeed2;
        tmrConfig.base.trigger.risingEdgeAtPeriod = false;
        tmrConfig.base.trigger.outputEnabled = true;

        tmrConfig.base.countDir = IfxStdIf_Timer_CountDir_up;

        tmrConfig.clock = IfxGtm_Tom_Ch_ClkSrc_cmuFxclk0;
        tmrConfig.tom = IfxGtm_Tom_1;

        tmrConfig.timerChannel = IfxGtm_Tom_Ch_0;
        tmrConfig.triggerOut = &IfxGtm_TOM1_7_TOUT17_P00_8_OUT;

        status = IfxGtm_Tom_Timer_init(&pwmhl_tom_timer, &tmrConfig);
        IfxGtm_Trig_toVadc(gtm, IfxGtm_Trig_AdcGroup_0, IfxGtm_Trig_AdcTrig_1,
                           IfxGtm_Trig_AdcTrigSource_tom1,
                           IfxGtm_Trig_AdcTrigChannel_7);
        IfxGtm_Trig_toVadc(gtm, IfxGtm_Trig_AdcGroup_1, IfxGtm_Trig_AdcTrig_1,
                           IfxGtm_Trig_AdcTrigSource_tom1,
                           IfxGtm_Trig_AdcTrigChannel_7);

        IfxGtm_Tom_Timer_run(&pwmhl_tom_timer);

        {
            IfxGtm_Tom_PwmHl_Config pwmConfig;
            pwmConfig.base.deadtime = 1.0e-6;
            pwmConfig.base.minPulse = 0;
            pwmConfig.base.channelCount = 3;
            pwmConfig.base.emergencyEnabled = false;
            pwmConfig.base.outputMode = IfxPort_OutputMode_pushPull;
            pwmConfig.base.outputDriver =
                IfxPort_PadDriver_cmosAutomotiveSpeed1;
            pwmConfig.base.ccxActiveState = Ifx_ActiveState_low;
            pwmConfig.base.coutxActiveState = Ifx_ActiveState_high;
            pwmConfig.base.ccxOutputEnabled = Ifx_ActiveState_high;
            pwmConfig.base.coutxOutputEnabled = Ifx_ActiveState_high;
            pwmConfig.timer = &pwmhl_tom_timer;
            pwmConfig.ccx = Ifx_Cfg_ccxCh;
            pwmConfig.coutx = Ifx_Cfg_coutxCh;
            pwmConfig.tom = IfxGtm_Tom_1;

            IfxGtm_Tom_PwmHl_init(&pwmhl_tom_driver, &pwmConfig);
            IfxGtm_Tom_PwmHl_setMode(&pwmhl_tom_driver,
                                     Ifx_Pwm_Mode_centerAligned);
        }

        {
            IfxGtm_Tom_Timer_disableUpdate(&pwmhl_tom_timer);
            IfxGtm_Tom_Timer_setTrigger(&pwmhl_tom_timer, 50);

            Ifx_TimerValue cmpValues[3];
            cmpValues[0] = 10;
            cmpValues[1] = 20;
            cmpValues[2] = 30;
            IfxGtm_Tom_PwmHl_setOnTime(&pwmhl_tom_driver, cmpValues);

            IfxGtm_Tom_Timer_applyUpdate(&pwmhl_tom_timer);
        }
    }

    IfxCpu_restoreInterrupts(status);

    IfxCpu_enableInterrupts();
}

 

 

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

HI masoud,

About 3 phase motor pwm output, you could start with eMotor application example (PMSM with FOC) AP32298

This application note describes an application example to spin a Permanent Magnetic  Synchronous Motor(PMSM) with Field Oriented Control (FOC). The Generic Timer Module (GTM) module generate the PWM, the VADC measure the phase current and the DSADC or GPT12 determines the motor position https://myicp.infineon.com/sites/microcontrollers-aurix_customer_doc/SitePages/default.aspx?RootFold...

dw

View solution in original post

0 Likes
3 Replies

Thanks. But all of them are about creating single PWM out for a single pin. I want to create three phase synchronized PWM outputs (6 pins with High & Low sides).

I was successful to run single pin output, but my problem is not there.

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

HI masoud,

About 3 phase motor pwm output, you could start with eMotor application example (PMSM with FOC) AP32298

This application note describes an application example to spin a Permanent Magnetic  Synchronous Motor(PMSM) with Field Oriented Control (FOC). The Generic Timer Module (GTM) module generate the PWM, the VADC measure the phase current and the DSADC or GPT12 determines the motor position https://myicp.infineon.com/sites/microcontrollers-aurix_customer_doc/SitePages/default.aspx?RootFold...

dw

0 Likes