Struggling to debug FTM0_CH0 on MKE02Z64

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Struggling to debug FTM0_CH0 on MKE02Z64

1,005 Views
ad_d
Contributor I

Hello All,

 

I have already working hour meter applicaiton on MKE02Z64 for our applicaiton. I am trying to add new feature, utilizing the PWM of the system. I took FREEDOM board sample code "FTM_EPWM_demo" For my applicaiton we are using FTM0CH0 I changed all the configuration to FTM0. below is the code.

While debugging after it successfully runs FTM_PWMInit(). It doesnt pass beyond this function  FTM_SetFTMEnhanced(FTM0); after first lne of this function it jumps to default_isr funciton in vectors.c

 

I am not able to understand whats wrong??? did I missed naythign while setting up. Please can some one help its kind a urgent. Thanks a lot

AD

 

    FTM_PWMInit(FTM0, FTM_PWMMODE_EDGEALLIGNED, FTM_PWM_HIGHTRUEPULSE);

 

    /* FTMEN enable */

    FTM_SetFTMEnhanced(FTM0);

    /* update MOD value */

    FTM_SetModValue(FTM0, 9999);

    /* set clock source, start counter */

    FTM_ClockSet(FTM0, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV1); 

    /* enable FTM0 interrupt in NVIC */

    NVIC_EnableIRQ(FTM0_IRQn);

    /* setup call back function for interrupt */

    FTM_SetCallback(FTM0, FTM0_Task);

    /* enable FTM0 overflow interrupt */

    FTM_EnableOverflowInt(FTM0);

Labels (1)
Tags (3)
0 Kudos
6 Replies

650 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Arti,

Maybe what David said is correct, incorrect FTM0 vector table leads to the issue. Anyway, you can check the vector number which leads to the unexpected interrupt by checking the bit0 to bit8 of the xPSR register when isr happens, if the number is 3(hard fault interrupt), the hardware fault leads to the interrupt, the case is complex. If the vector number is FTM vector number, it confirms that David is correct, it is okay to follow up David code.

Hope it can help you.

BR

XiangJun Rong

0 Kudos

650 Views
ad_d
Contributor I

I implemented all Davids suggestion. I tried to read the register after implementing and I am reading xPSR -> ISR as 0x003.

Please can you help me.

Thanks,

Arti

0 Kudos

650 Views
ad_d
Contributor I

Found the fault. Resolved.

Thanks

Arti

0 Kudos

649 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Regarding the function FTM_SetFTMEnhanced(FTM0); I checked the body of the function as following, can you debug step by step so that you can determine which line leads to the hardfault?

sorry, I have not the board of KE02 on hand.

BR

XiangJun Rong

__STATIC_INLINE void FTM_SetFTMEnhanced(FTM_Type *pFTM)

{

    if(pFTM->MODE & FTM_MODE_WPDIS_MASK)   /* if not write protected */

    {

        pFTM->MODE |= FTM_MODE_FTMEN_MASK;

    }

    else

    {

        FTM_WriteProtectionDisable(pFTM);

        pFTM->MODE |= FTM_MODE_FTMEN_MASK;

        FTM_WriteProtectionEnable(pFTM);

    }   

}

0 Kudos

649 Views
ad_d
Contributor I

Hello XiangJun Rong,

Both Function gets halt at while checking step by step at this condition " if(pFTM->MODE & FTM_MODE_WPDIS_MASK)    /* if not write protected */" when I do next step it jumps to "default_isr".

    /* FTMEN enable */

    FTM_SetFTMEnhanced(FTM0);

    /* update MOD value */

    FTM_SetModValue(FTM0, 9999);

Please can you shed some light on this. How do I proceed  am I  missing any step in enabling any bits...

Thanks,

AD

0 Kudos

651 Views
DavidS
NXP Employee
NXP Employee

Hi AD,

I think your issue is in the isr.h header file.  I too was getting a _default_isr but when I set a breakpoint in that ISR on the return; statement, I looked in the EmbSys Registers for MKE02Z4 SystemControl->ICSR and saw the FTM0 vector number.  This helped me to look around for how the FTM2 vector was being setup and found it in the isr.h.

I copied and pasted those lines of code and changed to VECTOR_033 and FTM0_Isr as shown below.  Now example works with FTM0_CH0.

#if 1//DES 1=test of FMT0, 0=default code

#undef  VECTOR_033

#define VECTOR_033      FTM0_Isr          /*!< Vector 35 points to FTM2 interrupt service routine */

extern void FTM0_Isr(void);

#endif

#undef  VECTOR_035

#define VECTOR_035      FTM2_Isr          /*!< Vector 35 points to FTM2 interrupt service routine */

extern void FTM2_Isr(void);

Attached are the two files I modified (FTM_EPWM_demo.c and isr.h).  Look for "//DES" to see what else I changed.

They were in following path:

~\kexx_drv_lib\src\projects\KE02\FTM_EPWM_demo

Regards,

David

0 Kudos