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

User14577
Level 1
Level 1
Hi all,

I am new to Tricore architecture and my goal is to measure PWM signal(s) using the GTM - TIM module's PWM measurement mode.

Could anyone help me with a sample source code or the steps involved to configure the registers to do a measurement of dutycycle and frequency?

I tried referring to Infineons datasheet with very little success.

Thanks in advance.

Best regards,
Aparajith
7 Replies
User15256
Level 2
Level 2
10 sign-ins 10 replies posted 5 questions asked
Hi Aparajith,

Did you accomplish this? Because I'm trying the same, but I couldn't find any example on this topic.

Best.
0 Likes
User14675
Level 1
Level 1
I have accomplished this on the TC277 with ILLD 1.0.1.0.0.

I've used TIM1 module with source clock CMU_CLK0. Let me know if you need a sample of code.

Regards,
Tomaz
0 Likes
User15256
Level 2
Level 2
10 sign-ins 10 replies posted 5 questions asked
Hi Tomaz,

Thank you for your reply. It would be great to take look in your sample code. Could you please share with me?

Best,
Vinicius.
0 Likes
User14675
Level 1
Level 1
See below. I have skipped parts of code which aren't necessary and most of the comments. You should check what each function does and add comments accordingly.

INIT:

IfxGtm_Tom_Pwm_Driver _timDriver; // should be global

Ifx_GTM *gtm = &MODULE_GTM;

IfxGtm_enable(gtm);

IfxGtm_Cmu_setGclkFrequency(gtm, (float)GTM_CFG_GCLK_FREQUENCY);

IfxGtm_Cmu_setClkFrequency(gtm, IfxGtm_Cmu_Clk_0, 10000000);

IfxGtm_Cmu_enableClocks(gtm, GTM_CFG_CLK_SRC_TIM_EN);

IfxGtm_Tim_In_Config TimConfig;

IfxGtm_Tim_In_initConfig(&TimConfig, gtm);

TimConfig.capture.clock = IfxGtm_Cmu_Clk_0;
TimConfig.filter.inputPin = &IfxGtm_TIM0_0_TIN87_P14_7_IN; // select channel
TimConfig.filter.inputPinMode = IfxPort_Mode_inputNoPullDevice; // select mode

IfxGtm_Tim_In_init(&_timDriver, &TimConfig);



Measure frequency:

Ifx_GTM_TIM_CH_GPR0 GPR0;
Ifx_GTM_TIM_CH_GPR1 GPR1;
uint32 period_ticks = 0;

// check if new event
if (IfxGtm_Tim_Ch_isNewValueEvent(_timDriver.channel))
{
IfxGtm_Tim_Ch_clearNewValueEvent(_timDriver.channel);

// get values from registers
GPR1.U = _timDriver.channel->GPR1.U;
GPR0.U = _timDriver.channel->GPR0.U;
period_ticks = GPR1.B.GPR1;

// calculate frequency
_frequency = 10000000 / (float) period_ticks;
}
else
{
_frequency = 0;
}


The duty cycle will be stored in GPR0.B.GPR0 register (in ticks of TIM counter frequency).

Regards,
Tomaz
0 Likes
User15256
Level 2
Level 2
10 sign-ins 10 replies posted 5 questions asked
Hi Tomaz,

I have tryed your code with iLLD 1.0.5.0.0, unfortunately with no luck. Especially because of "IfxGtm_Tom_Pwm_Driver _time Driver;" struct:

typedef struct
{
Ifx_GTM *gtm; /**< \brief Pointer to GTM module */
IfxGtm_Tom tomIndex; /**< \brief Index of the TOM object used */
IfxGtm_Tom_Ch tomChannel; /**< \brief TOM channel used for the timer */
Ifx_GTM_TOM *tom; /**< \brief Pointer to the TOM object */
Ifx_GTM_TOM_TGC *tgc[2]; /**< \brief Pointer to the TGC object */
} IfxGtm_Tom_Pwm_Driver;


Which does not contain "_timDriver.channel" for example. Then I have tryed with "IfxGtm_Tim_In":

typedef struct
{
Ifx_GTM_TIM_CH *channel; /**< \brief TIM channel used */
uint32 periodTick; /**< \brief Period value in clock ticks */
uint32 pulseLengthTick; /**< \brief Duty value in clock ticks */
boolean dataCoherent; /**< \brief TRUE, if the duty and period values are measured from the same period */
boolean overflowCnt; /**< \brief TRUE if the last measurement show an overflow in CNT */
boolean newData; /**< \brief TRUE when values are updated, and if none of the counter CNT, CNTS have overflowed */
boolean dataLost; /**< \brief TRUE if data are lost */
uint32 edgeCounterUpper; /**< \brief upper part of the edge counter */
boolean glitch; /**< \brief TRUE if glitch is detected */
float32 captureClockFrequency; /**< \brief Capture clock frequency in Hz */
IfxGtm_Tim timIndex; /**< \brief Index of the TIM module being used. */
IfxGtm_Tim_Ch channelIndex; /**< \brief Index of the TIM channel being used. */
uint16 edgeCount; /**< \brief number of edges counted. */
} IfxGtm_Tim_In;


INIT:

/* initialize TIM */
IfxGtm_Tim_In_Config configTim;
IfxGtm_Tim_In _timDriver;

IfxGtm_enable(&MODULE_GTM);
// we set the global clock to 100MHz
IfxGtm_Cmu_setGclkFrequency(&MODULE_GTM, 100000000.0f);
// set CMU0 frequency
IfxGtm_Cmu_setClkFrequency(&MODULE_GTM, IfxGtm_Cmu_Clk_0, 100000000.0f);
// enable CMU0 clock
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_CLK0);
// enable FX clock
IfxGtm_Cmu_enableClocks(&MODULE_GTM, IFXGTM_CMU_CLKEN_FXCLK);

IfxGtm_Tim_In_initConfig(&configTim, &MODULE_GTM);
configTim.capture.clock = IfxGtm_Cmu_Clk_0;
configTim.filter.inputPin = &IfxGtm_TIM0_1_TIN1_P02_1_IN; // select channel
configTim.filter.inputPinMode = IfxPort_Mode_inputNoPullDevice; // select mode
IfxGtm_Tim_In_init(&_timDriver, &configTim);


READ:

// check if new event
if (IfxGtm_Tim_Ch_isNewValueEvent(_timDriver.channel))
{
IfxGtm_Tim_Ch_clearNewValueEvent(_timDriver.channel);
// get values from registers
GPR1.U = _timDriver.channel->GPR1.U;
GPR0.U = _timDriver.channel->GPR0.U;
period_ticks = GPR1.B.GPR1;
}


Well I will keep debbuging, thank you for your help.

Best,
Vinicius.
0 Likes
User15256
Level 2
Level 2
10 sign-ins 10 replies posted 5 questions asked
It seens to be working now.

Thank you Tomaz.
0 Likes
User14675
Level 1
Level 1
The struct IfxGtm_Tom_Pwm_Driver is completely my mistake, sorry. I've had TIM and TOM init in the same file and copied the wrong one. You've used the correct one (we're using TIM, not TOM of course).

You don't need to enable the FXCLK, that one is used only for the TOM. The TIM uses the CMU_CLKx (x = 0 to 7).

Do you know in what way it stops working?
Are there no new events or does the app hang?
How often are you calling the read code?
What input frequency are you measuring?
How many times does it work?

EDIT: No problem.
0 Likes