Hi i am trying to capture rising edge with a flextimer. I wont to calculate the time from one rising edge to the next one. I am trying in this way:
void initFlexTimer()
{
unsigned int irPort;
//Port initialisering
definePort();
fnDebugMsg("IR\n");
irPort = _READ_PORT_MASK(C, PORTC_BIT6);
fnDebugDec(irPort, 0);
//Enable the Clock to the FTM0 Module
SIM_SCGC6 |= SIM_SCGC6_FTM0;
FTM0_SC |= FTM_SC_PS_1; // clock prescaler / 1
//turn off FTM write protection;
FTM0_MODE |= FTM_MODE_WPDIS;
FTM0_MODE |= FTM_MODE_FTMEN;
FTM0_SC = 0x0;
FTM0_SC = 0; //Make sure its Off!
FTM0_CNT = 0; //Reset counter, make sure we are starting at 0
FTM0_MOD = (FTM_CSC_ELSA | FTM_CSC_ELSB); //Set the overflow rate
//FTM0_MOD = IRQ_RISING_EDGE;
FTM0_SC |= FTM_SC_TOIE; //Enable the interrupt mask.
FTM0_SC |= FTM_SC_CLKS_SYS; //Select the System Clock
fnDebugMsg("Timer is running, with value: ");
//fnDebugDec(FTM0_CNT, 0);
fnDebugDec(FTM0_MOD, 0);
}
I dosen´t seems to work, i just geth the value 12 the hole time. Someone now whats maybe is wrong ?
I think i have found what there is wrong. If i make this statement in isr:
FTM0_CNT = 0;
FTM0_C0SC &= ~FTM_CSC_CHF;
check = FTM_SC_TOF;
fnDebugDec(check, 0);
if( FTM0_SC |= FTM_SC_TOF)
{
fnDebugMsg("Wrong");
}
else
{
print = FTM0_C0V;
fnDebugDec(print,0);
}
i am getting in to the wrong value when i push the button, so i think i need to clear the tof flag in some way
Finally i goth the frequenzy, one off the thinks wash i needed to change the delay in the for loop to 8800 :smileyhappy:
Ok
Its very short time
I change so i now have FTM1_MODE |= FTM_MODE_FTMEN;
but nothing happens
you need to configure FTM1_MOD with max value of the counter.
if 4096 is max value of your counter FTM1_MOD = 4095
and FTM1_MODE you can configure in accordance with your task.
at least you did something like that: FTM1_MODE |= FTM_MODE_FTMEN;
Hi
I have now try to change my code to:
Its not make any sence to me any more
i have try to test the example FlexTimer_NVIC_IRQ and tryet to follow that example in som parts but i cant geth it
i have been looking in to this also
http://cache.freescale.com/files/32bit/doc/app_note/AN4381.pdf