I guess you don't need power up the FTM.
according to AN4381 it's needed to make some steps:
1. enable the clock for FTM1
SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK;
2. enable the counter
FTM1_MODE |= FTM_MODE_FTMEN_MASK;
3. and the like... for input capturing it'll be different
//enable the counter to run in the BDM mode
FTM1_CONF |= FTM_CONF_BDMMODE(3);
//load the Modulo register and counter initial value
FTM1_MOD = 4095;
FTM1_CNTIN = 0;
//configuring FTM for quadrature mode
FTM1_QDCTRL |= FTM_QDCTRL_QUADEN_MASK;
// start the timer clock, source is the external clock
FTM1_SC |= FTM_SC_CLKS(3);
//configuring the input pins:
PORTA_PCR8 = PORT_PCR_MUX(6); // FTM1 CH0
PORTA_PCR9 = PORT_PCR_MUX(6); // FTM1 CH1
--------------------------------------------------------------------------------------
void FlexTimerCapturingInitial()
{
PORT_MemMapPtr PCtlMmp = (PORT_MemMapPtr)PORTC_BASE_PTR;
SIM_MemMapPtr SimMmp = SIM_BASE_PTR;
FTM_MemMapPtr FtmMmp = FTM0_BASE_PTR;
1. ports are FTM-inputs
PCtlMmp->PCR[1] = PORT_PCR_MUX(4);
PCtlMmp->PCR[2] = PORT_PCR_MUX(4);
2. //Enable clock to FlexTimer module
mcu::registers::sim::tSCGC6* SimScgc6 = (mcu::registers::sim::tSCGC6*)&SimMmp->SCGC6;
SimScgc6->Fields.FTM0 = 1;//Enable clock to FlexTimer module
mcu::registers::sim::tSOPT4* SimSopt4 = (mcu::registers::sim::tSOPT4*)&SimMmp->SOPT4;//It seems to be in order.
mcu::registers::ftm::tSC* SC = (mcu::registers::ftm::tSC*)&FtmMmp->SC;
mcu::registers::ftm::tMODE* Mode = (mcu::registers::ftm::tMODE*)&FtmMmp->MODE;
mcu::registers::ftm::tCNTIN* Cntin = (mcu::registers::ftm::tCNTIN*)&FtmMmp->CNTIN;
Cntin->Fields.INIT = 0x0000;//It is expected that the input capture mode be used only with CNTIN = 0x0000;
mcu::registers::ftm::tMOD* Mod = (mcu::registers::ftm::tMOD*)&FtmMmp->MOD;
Mod->Fields.MOD = 0xFFFF;
mcu::registers::ftm::tCSC* Csc0 = (mcu::registers::ftm::tCSC*)&FtmMmp->CONTROLS[0].CnSC;
Csc0->Fields.ELSA = 1;//Capture on Rising Edge
///////////////////////////////////////////////////////////////////////////////////////////
Switching on the FTM
Mode->Fields.FTMEN = 1;//FTM Enable. All registers including the FTM-specific registers (second set of registers) are available for use with no restrictions.
Clock + prescaler
SC->Fields.CLKS = 0x01;//System Clock 100 Mhz
SC->Fields.PS = 0x07;//divide by 128 -> 781250 Hz = 0xBEBC2
// 781250 / 100 (min freq of DUT) = 7812.50 and that is less than 0xFFFF, so it's good! :smileyhappy:
}