AnsweredAssumed Answered

FTM & PORT setup for input compare

Question asked by Tomáš Pilný on Apr 27, 2015
Latest reply on Apr 27, 2015 by EARL GOODRICH


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 <stdio.h>

#include "derivative.h" /* include peripheral declarations */

int main(void)


    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..."



    //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

    for(;;) {}

    return 0;