I am using MK60N512VMD100 on custom board, with CW v10.6.
I'm having trouble with setting up FTM and PORT to measure length of incoming signal. The main problem is that when I try to set MUX for FTM the program crashes with "The debugger has lost communication on connection ...".
I'm beginner, so I'm obviously missing a lot of knowledge. If you could help me solve this problem, I would be most grateful
Also if you have any other tip on setting up FTM for measuring length of incoming pulse I would appreciate it too.
#include "derivative.h" /* include peripheral declarations */
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // Enable the clock on Port A
SIM_SCGC6 |= SIM_SCGC6_FTM0_MASK; // enable clock for FTM0
// crash at this line "The debugger has lost communication on connection..."
PORTA_PCR3 = PORT_PCR_MUX(3) | PORT_PCR_PE_MASK;
//Edit registers when no clock is fed to timer so the MOD value, gets pushed in immediately
FTM0_SC = 0; // Make sure its Off!
FTM0_MODE |= FTM_MODE_WPDIS_MASK; // disable write protection
FTM0_MODE |= FTM_MODE_FTMEN_MASK; // FTM0 enable
FTM0_CNT = 0; // counter initialization
FTM0_MOD = FTM_MOD_MOD(0x30d4);
FTM0_CNTIN = 0;
// some document said
// Even if the odd channels are generated automatically by complementary logic, these channels
// have to set to be in the same channel mode.
FTM0_C0SC = 0x4c; // CHIE, MS:X0, ELS:11 Dual Edge Capture; One-Shot Capture mode
FTM0_C1SC = 0x4c;
FTM0_CNTIN = FTM_CNTIN_INIT(0); //Initial Value of the FTM Counter
FTM0_CONF |= FTM_CONF_BDMMODE(2); // freeze in debug mode
NVICISER1 |= 1 << (62 % 32); // turn on FlexTimer interrupt for IRQ 62
FTM0_SC |= FTM_SC_CLKS(0x01);
// Loop forever