Not getting correct count in GPR1 register for TIM PWM Mode

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

cross mob
User18885
Level 1
Level 1
Hi,

I am Using Infineon AURIX TC264x and I am trying to measure the Input Frequency (e.g. 60KHz).

1) I am configure GTM TIM Module 1 channel 4 in PWM Measurement Mode.
2) The GTM CMU Clock Module Global clock configure for 80MHz and CMU Clock0 for 10MHz.
3) Enable the new Value Interrupt.

according to clock select and input frequency i am supposed to get the period count approx. 166 in GPR1 register.
But I am getting the count as 10 or 11.

please let me know if I missed anything or I did something wrong?

Thank you.

For further details ,


/* initialize TIM */
IfxGtm_Tim_Config configTim;

/* Initialization */
INIT()
{
/* Enable the GTM Module */
IfxGtm_enable(&MODULE_GTM);

/* Get the module Frequency */
Globalfrequency = IfxGtmCmu_getModuleFrequency(&MODULE_GTM);

/* we set the global clock to 80MHz */
IfxGtmCmu_setGclkFrequency(&MODULE_GTM, 80000000.0f);

/* set CMU0 frequency 10MHz */
IfxGtmCmu_setClkFrequency(&MODULE_GTM, Ifx_Gtm_Tim_Clock_cmuClk0, 10000000.0f);

/* enable CMU0 clock */
IfxGtmCmu_enableClocks(&MODULE_GTM, IFXGTMCMU_CLKEN_CLK0);

/* Configuration of TIM Module */
IfxGtm_Tim_initConfig(&configTim);

/* Select Module 1 */
configTim.module = IfxGtm_Tim_Module_1;

/* Select Channel 4 */
configTim.channel = IfxGtm_Tim_Channel_4;

/* Select Channel option 4 */
configTim.chOption = IfxGtm_channelOption_4;

/* Select the GPR0 register to hold the Counter value */
configTim.gpr0Sel = Ifx_Gtm_Tim_Gpr0Sel_cnts;

/* Select Input Pin Mode */
configTim.inputPinMode = IfxPort_InputMode_pullDown;

/* Enable New Value Interrupt */
configTim.irq.irqOnNewVal = ICM_ENABLE;

/* Set IRQ Mode */
configTim.irqmode = IfxGtm_IrqMode_pulseNotify;

/* Update Interrupt Register */
ICM_EnableInterrupt(&MODULE_GTM,configTim.module,&configTim.irq,configTim.irqmode);

/* initialization */
IfxGtm_Tim_init(&MODULE_GTM, &configTim);

/* Configure the Input Pin PORT 14 pin 1*/
IfxGtm_PinMap_setTimTin(&IfxGtm_TIM1_4_TIN81_P14_1_IN, configTim.inputPinMode);
IfxPort_setPinPadDriver(&MODULE_P14, 1, IfxPort_PadDriver_cmosAutomotiveSpeed2);

}

IfxGtm_Tim_init()
{
case IfxGtm_Tim_Channel_4:
gtm->TIM[config->module].CH4_CTRL.B.ARU_EN = 0;
gtm->TIM[config->module].CH4_CTRL.B.CLK_SEL = config->clock;
gtm->TIM[config->module].CH4_CTRL.B.TIM_MODE = config->mode;
gtm->TIM[config->module].CH4_CTRL.B.GPR0_SEL = config->gpr0Sel;
gtm->TIM[config->module].CH4_CTRL.B.GPR1_SEL = 3;
gtm->TIM[config->module].CH4_CTRL.B.CNTS_SEL = 0;
gtm->TIM[config->module].CH4_CTRL.B.ISL = 0;
gtm->TIM[config->module].CH4_CTRL.B.DSL = 1;
gtm->TIM[config->module].CH4_CTRL.B.FLT_CNT_FRQ = config->filterClock;
gtm->TIM[config->module].CH4_FLT_RE.U = config->FLT_Rise_Time;
gtm->TIM[config->module].CH4_FLT_FE.U = config->FLT_Fall_Time;
gtm->TIM[config->module].CH4_CTRL.B.FLT_EN = (config->filterEnable != FALSE) ? 1:0;
gtm->TIM[config->module].CH4_CTRL.B.CICTRL = 0;
gtm->TIM[config->module].IN_SRC.B.VAL_4 = 0;
gtm->TIM[config->module].IN_SRC.B.MODE_4 = 0;
gtm->TIM[config->module].CH4_ECTRL.B.EXT_CAP_SRC = 0;
gtm->TIM[config->module].CH4_CTRL.B.EXT_CAP_EN = 0;
gtm->INOUTSEL.TIM[config->module].INSEL.B.CH4SEL = 3;
gtm->TIM[config->module].CH4_CTRL.B.TIM_EN = 1;
break;
}

/* Interrupt ISR */

if(ICM_isNewValueEvent(&MODULE_GTM,configTim.module) == ICM_ENABLE)
{
IfxPort_setPinState(&MODULE_P14,0,IfxPort_State_toggled);
TOCount = IfxGtm_Tim_getCnt(&MODULE_GTM,configTim.module,configTim.channel);
/* get the value from Counter register */
GPR01 = IfxGtm_Tim_getPeriod(&MODULE_GTM,configTim.module,configTim.channel);
/* get the value from Shadow Counter register */
GPR0 = IfxGtm_Tim_getPulse(&MODULE_GTM,configTim.module,configTim.channel);
/* clear the Interrupt Flag */
ICM_ClearInterruptFlag(&MODULE_GTM,configTim.module);
}
0 Likes
0 Replies