AnsweredAssumed Answered

FTM behaviour after reset

Question asked by Suraj Kumar on Jan 9, 2017
Latest reply on Jan 23, 2017 by Petr Stancik

#include <S32K144.h>

void Timer_FTM0_Init(void);
void NVIC_EnablIRQs(IRQn_Type IRQs_Number );

int main(void)
{

SystemOSC_Init();
SystemPLL_Init();
SystemRunMode_Init();
Gpio_Init();
Timer_FTM0_Init(); //! Initialization of FTM1 module
NVIC_EnablIRQs(FTM0_IRQn); //! Setting for Enabling FTM1 Interrupt and there Priorities Level
while(1)
{
}
}

 

void Timer_FTM0_Init(void)
{
//! System Clock is input to FTM counter so, no need to program
PCC->PCCn[PCC_FLEXTMR0_INDEX] = PCC_PCCn_PCS(6);
PCC->PCCn[PCC_FLEXTMR0_INDEX] |= PCC_PCCn_CGC_MASK;
FTM0->MODE |= FTM_MODE_WPDIS_MASK; //!WPDIS: Write Protection Enable for FTM register
FTM0->SC = 0;
FTM0->CNTIN = 0;
FTM0->SC = ( FTM_SC_PS(4)|FTM_SC_CLKS(1)|!FTM_SC_CPWMS_MASK
|FTM_SC_TOIE_MASK );
FTM0->MODE |= FTM_MODE_FTMEN_MASK;
FTM0->MOD = FTM_MOD_MOD(40000);
FTM0->CONTROLS[0].CnSC = (( FTM_CnSC_ELSA_MASK)|(!FTM_CnSC_ELSB_MASK)
|( FTM_CnSC_MSA_MASK)|(!FTM_CnSC_MSB_MASK));
FTM0->CONTROLS[0].CnSC |= FTM_CnSC_CHIE_MASK;
}

 

//!Handler For Flex Timer Module
void FTM0_IRQHandler (void)
{
if( FTM0->SC & FTM_SC_TOF_MASK ){
if( FTM0->STATUS & FTM_STATUS_CH0F_MASK ){
FTM0->STATUS &= !FTM_STATUS_CH0F_MASK;
Toggle_PortD(EVB_BLUE_LED);}}
}

 

void NVIC_EnablIRQs(IRQn_Type IRQs_Number )
{

 

FSL_NVIC->ICPR[1] = 1 << (IRQs_Number % 32); //! Clear any pending IRQ
FSL_NVIC->ISER[1] = 1 << (IRQs_Number % 32); //! Enable IRQ
FSL_NVIC->IP[IRQs_Number] = 9;
}

 

Hi all,
I have written the above code to generate the interrupt every millisecond . My code running good and on every second, i am getting the interrupt and so my ISR getting executed on each millisecond.
Below is description of my issue :
CASE1:
I am running my code on IAR embedded work bench:
1. After compiling my code i am using "downloading and debugging" option to flash the .elf file on IAR .
2. Now i am starting debugging the code ,with single step run .
a) First my breakpoints hit on main, as usually happens .
b) Then,It hit the Function :Timer_FTM0_Init(); (I have set the break-point on this function ).here i have initialise the FTM0_Chn0 for 1 millisecond.
c) Then it wait for 1 millisecond , this time it continue hitting the while statement till time out.
d)then as the timeout expire (40000),it execute the ISR , and toggle the LED.
Means with the option "debug and downloading " my code running smooth and as expected .

 

CASE2:
1. I have remove the all breakpoints.
2. Now, i have set the full free mode running.code running smooth on every second ISR executing and i my LED toggling .

 

My issue start from here .
3. Now i have reset the code on IAR debugger with option "reset"and then run again , now what happens :
a) First my breakpoints hit on main, as happening in First case1.
b) Then,It hit the Function :Timer_FTM0_Init(); (I have set the break-point on this function ).here i have initialise the FTM0_Chn0 for 1 millisecond.
now the issue is here ,below and skipping the step C , means it not hitting the while loop means not waiting for expiring the counting (40000) .
below step spiking not hitting here .
c) Then it wait for 1 millisecond , this time it continue hitting the while statement till time out.

 


it execute the ISR , without waiting for expiring the time out value (counting value of 40000).

 

Thanks!

Outcomes