PWM Generation using GTM TOM PWM Driver

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

cross mob
User17370
Level 1
Level 1
Hi,

I have a KIT AURIX TC223 TRB and I'm trying to generate a PWM signal on pin 12 of port 11 but I can't. I've used an example that I found on iLLD documentation. The example is the following:


#include
#include "IfxCpu_Irq.h"

Ifx_GTM *gtm = &MODULE_GTM;
#define TOM0_CH0_PRIO 10

float32 frequency;

IFX_INTERRUPT(TOM0Ch0_ISR, 0, TOM0_CH0_PRIO)
{}

int core0_main(void){

/*
* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdog in the demo if it is required and also service the watchdog periodically
* */

IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
// install interrupt handlers
IfxCpu_Irq_installInterruptHandler (TOM0Ch0_ISR, TOM0_CH0_PRIO);

// enable GTM clock
frequency = IfxGtm_Cmu_getModuleFrequency(gtm);
// Enables the GTM
IfxGtm_enable(gtm);
// Set the global clock frequency to the max
IfxGtm_Cmu_setGclkFrequency(gtm, frequency);
// Set the CMU CLK0
IfxGtm_Cmu_setClkFrequency(gtm, IfxGtm_Cmu_Clk_0, frequency);
// FXCLK: used by TOM and CLK0: used by ATOM
IfxGtm_Cmu_enableClocks(gtm, IFXGTM_CMU_CLKEN_FXCLK); //Here was IFXGTM_CMU_CLKEN_FXCLK | IFXGTM_CMU_CLKEN_CLK0

// initialise TOM
IfxGtm_Tom_Pwm_Config tomConfig;
IfxGtm_Tom_Pwm_Driver tomHandle;

IfxGtm_Tom_Pwm_initConfig(&tomConfig, gtm);

tomConfig.tomChannel = IfxGtm_Tom_Ch_7; //Here was IfxGtm_Tom_Ch_0
tomConfig.period = 20;
tomConfig.dutyCycle = 10;
tomConfig.interrupt.ccu0Enabled = FALSE;
tomConfig.interrupt.isrPriority = TOM0_CH0_PRIO;
tomConfig.pin.outputPin = &IfxGtm_TOM0_7_TOUT101_P11_12_OUT; //Here was IfxGtm_TOM0_0_TOUT106_P10_4_OUT

IfxGtm_Tom_Pwm_init(&tomHandle, &tomConfig);

while (1)
{
}
return 0;
}


Could you explain me what is wrong?

Thank you in advance.
0 Likes
6 Replies
User14049
Level 3
Level 3
I am also facing same problem
0 Likes
User16969
Level 1
Level 1
Same problem also my side
0 Likes
User17093
Level 1
Level 1
You're missing this after IfxGtm_Tom_Pwm_init

IfxGtm_Tom_Pwm_start(&tomHandle, TRUE);


Also while you set an interrupt priority, you didn't enable either the CCU0 or CCU1 interrupt so the interrupt will never happen.

Here is a code example based on illd 1_10 for tc26x:



#define TOM0_CH0_PRIO (10)
volatile uint32 Isr_TomPwm_Counter;
IfxGtm_Tom_Pwm_Driver tomHandle;

void initPwm(void) {

IfxGtm_enable(&MODULE_GTM);

// initialise TOM
IfxGtm_Tom_Pwm_Config tomConfig;

IfxGtm_Tom_Pwm_initConfig(&tomConfig, &MODULE_GTM);

tomConfig.tom = IfxGtm_Tom_0;
tomConfig.tomChannel = IfxGtm_Tom_Ch_7;

tomConfig.interrupt.ccu0Enabled = TRUE; // ISR on counter reaches period
tomConfig.interrupt.ccu1Enabled = FALSE;
tomConfig.interrupt.isrPriority = TOM0_CH0_PRIO;
tomConfig.interrupt.isrProvider = IfxSrc_Tos_cpu0;
tomConfig.interrupt.mode = IfxGtm_IrqMode_level;

tomConfig.pin.outputPin = &IfxGtm_TOM0_7_TOUT25_P33_3_OUT;
tomConfig.pin.outputMode = IfxPort_OutputMode_pushPull;
tomConfig.pin.padDriver = IfxPort_PadDriver_cmosAutomotiveSpeed1;
tomConfig.clock = IfxGtm_Tom_Ch_ClkSrc_cmuFxclk1;

tomConfig.period = 1e-3 * IfxGtm_Cmu_getFxClkFrequency(&MODULE_GTM, IfxGtm_Tom_Ch_ClkSrc_cmuFxclk1, TRUE); // 1ms period
tomConfig.dutyCycle = tomConfig.period * 0.33; // 33% duty cycle

tomConfig.signalLevel = Ifx_ActiveState_high;
tomConfig.oneShotModeEnabled = FALSE;
tomConfig.synchronousUpdateEnabled = TRUE;
tomConfig.immediateStartEnabled = FALSE;

IfxGtm_Tom_Pwm_init(&tomHandle, &tomConfig);
IfxGtm_Tom_Pwm_start(&tomHandle, TRUE);
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK);
}

IFX_INTERRUPT(Isr_TomPwm, 0, TOM0_CH0_PRIO)
{
__enable();
IfxGtm_Tom_Ch_clearZeroNotification(tomHandle.tom, tomHandle.tomChannel);
Isr_TomPwm_Counter++;

}
0 Likes
User19796
Level 1
Level 1
Hi @delattre2
I also put function IfxGtm_Tom_Pwm_start(&tomHandle, TRUE); but i have got a miss is ` undefined reference to IfxGtm_Tom_Pwm_start` although i have library "IfxGtm_Tom_Pwm.h"
i don`t know what happen with them!
can you help me explain this?
thanks you!
0 Likes
teoBits
Employee
Employee
5 sign-ins 100 replies posted 50 replies posted
Hello,

did you try using the GTM_TOM_PWM_1_KIT_TC234_TFT example?
It also come with a nice and detailed tutorial: GTM_TOM_PWM_1_KIT_TC234_TFT

you should be able to run it without any problem, but if it does not flashes on your device, you can port the code for your device in AURIX Development Studio (if you don't have it yet, get it here for free), and then:

  • Create a new project selecting your device (TC22x)
  • copy-paste the files from the example linked above (both the GTM_TOM_PWM.c/.h and the cpu0_Main) into the new project
  • build the project and debug it!


hope it helps,
teoBits

PS: If you are not familiar with Eclipse based IDE’s checkout the Getting Started guide!
0 Likes
User19796
Level 1
Level 1
Thanks @teoBits,
i known what happen with my code.
but now i have new thing. I try to generate PWM with 10ns lowest pulse and 1hz lowest frequency. but it did not work
can you give me know what happen with my code?
follow my code below:


#include "GTM_TOM_PWM.h"
#include "Ifx_Types.h"
#include "IfxGtm_Tom_Pwm.h"


#define ISR_PRIORITY_TOM 20 /* Interrupt priority number */
#define LED IfxGtm_TOM0_2_TOUT104_P10_2_OUT /* LED which will be driven by the PWM IfxGtm_TOM0_8_TOUT0_P02_0_OUT */
#define PWM_PERIOD 100E6 /* PWM period for the TOM */
#define FADE_STEP PWM_PERIOD / 100 /* PWM duty cycle for the TOM */



Ifx_GTM *gtm = &MODULE_GTM;
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
IfxGtm_Tom_Pwm_Config g_tomConfig; /* Timer configuration structure */
IfxGtm_Tom_Pwm_Driver g_tomDriver; /* Timer Driver structure */
uint32 g_fadeValue = 0; /* Fade value, starting from 0 */
sint8 g_fadeDir = 1; /* Fade direction variable */

/*********************************************************************************************************************/
/*-----------------------------------------------Function Prototypes-------------------------------------------------*/
/*********************************************************************************************************************/
void setDutyCycle(uint32 dutyCycle); /* Function to set the duty cycle of the PWM */

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



IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK); /* Enable the FXU clock */

/* Initialize the configuration structure with default parameters */
IfxGtm_Tom_Pwm_initConfig(&g_tomConfig, &MODULE_GTM);

g_tomConfig.tom = LED.tom; /* Select the TOM depending on the LED */
g_tomConfig.tomChannel = LED.channel; /* Select the channel depending on the LED */
g_tomConfig.period = PWM_PERIOD; /* Set the timer period */
g_tomConfig.pin.outputPin = &LED;
g_tomConfig.dutyCycle = 1; /* Change the value of the duty cycle */
SerialASC.println(PWM_PERIOD); /* Set the LED port pin as output */
g_tomConfig.synchronousUpdateEnabled = TRUE; /* Enable synchronous update */

IfxGtm_Tom_Pwm_init(&g_tomDriver, &g_tomConfig); /* Initialize the GTM TOM */
IfxGtm_Tom_Pwm_start(&g_tomDriver, TRUE); /* Start the PWM */
}
0 Likes