AnsweredAssumed Answered

About S12XE Input Capture Interrupt

Question asked by 赵子成 on Mar 21, 2019
Latest reply on Mar 22, 2019 by Edward Karpicz

Hi All,

Now I Use IOC7 Pin to capture the PWM. In order to calculate the PWM frequency and duty cycle, I set to Capture on any edge (rising or falling) and will lead to interruption.

The input PWM is 1K frequency and 50% duty cycle, everything is good.

But if the duty cycle is larger than  95%, I found sometime the  rising edge won't trigger interrupt(Maybe the period between  falling edge and following rising edge is too short). That leads to the wrong result of calculation.

 

My init code is this:

void IOC_Init(void)
{
ECT_TIOS_IOS7 = 0; //The corresponding channel acts as an input capture
ECT_TIOS_IOS4 = 0; //The corresponding channel acts as an input capture
ECT_TIOS_IOS1 = 0; //The corresponding channel acts as an input capture
ECT_TSCR1_TFFCA = 1; //A read from an input capture causes the corresponding channel flag, CxF, to be cleared in the TFLG1 register
ECT_TCTL3_EDG7x = 3; //Capture on any edge (rising or falling)
ECT_TCTL3_EDG4x = 3;
ECT_TCTL4_EDG1x = 3;
ECT_TSCR2_PR = 7; //Prescale Factor=32, capture clock is 48M/128=375K
ECT_TIE_C7I = 1; //The corresponding flag(C7F) is enabled to cause an interrupt.
ECT_TIE_C4I = 1; //The corresponding flag(C4F) is enabled to cause an interrupt.
ECT_TIE_C1I = 1; //The corresponding flag(C1F) is enabled to cause an interrupt.

ECT_TSCR1_TEN = 1; //Allows the timer to function normally
}

 

And the interrupt code is like this:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void ISR_IC7(void)
{
static UINT32 u32ICU_RiseTick;
static UINT32 u32ICU_FallDownTick;
static UINT32 u32ICU_HighLevelTick;
static UINT32 u32ICU_LowLevelTick;
UINT16 u16Fre, u16DutyCycle;


if(I_D_CP == HIGH_LEVEL)   // IOC7 Pin is high level
{
u32ICU_RiseTick = ECT_TC7;   // read the counter
if(u32ICU_RiseTick > u32ICU_FallDownTick)
{
u32ICU_LowLevelTick = u32ICU_RiseTick - u32ICU_FallDownTick;
}
else
{
u32ICU_LowLevelTick = u32ICU_RiseTick + ICU_TICK_SCALE - u32ICU_FallDownTick;
}
}
else          // IOC7 Pin is low level
{
u32ICU_FallDownTick = ECT_TC7;    // read the counter
if(u32ICU_FallDownTick > u32ICU_RiseTick)
{
u32ICU_HighLevelTick = u32ICU_FallDownTick - u32ICU_RiseTick;
}
else
{
u32ICU_HighLevelTick = u32ICU_FallDownTick + ICU_TICK_SCALE - u32ICU_RiseTick;
}
if((u32ICU_LowLevelTick + u32ICU_HighLevelTick) > 0)
{
u16DutyCycle = u32ICU_HighLevelTick * 1000 / (u32ICU_LowLevelTick + u32ICU_HighLevelTick);
u16Fre = ICU_TICK_FRE * 10 / (u32ICU_LowLevelTick + u32ICU_HighLevelTick);
}
else
{
u16DutyCycle = 0;
u16Fre = 0;
}
g_stCpPwmVar.u16Fre = u16Fre;
g_stCpPwmVar.u16DutyCycle = u16DutyCycle;
g_stCpPwmVar.u32UpdateTick = STMR_GetTickCount();
}
}

 

Can someone tell me why?

Outcomes