FTM & PORT setup for input compare

cancel
Showing results for 
Search instead for 
Did you mean: 

FTM & PORT setup for input compare

366 Views
tomášpilný
Contributor I

Hello,

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 :smileyhappy:

Also if you have any other tip on setting up FTM for measuring length of incoming pulse I would appreciate it too.

Thanks

Tom

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

    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

    for(;;) {}

    return 0;

}

Labels (1)
Tags (3)
0 Kudos
3 Replies

116 Views
egoodii
Senior Contributor III

Because the pin 'muxed' as PortA-3 is a debugger-pin.  Choose a different pin, NOT any of PortA0thru4.

116 Views
tomášpilný
Contributor I

Umh ok, but how do I use those channels then? Does this mean that I can use only CH2thru4 => PTA5thru7 ?

Anyway thanks for answer.

0 Kudos

116 Views
egoodii
Senior Contributor III

FTM0 chs. 0/1/5/6/7 are available on 'other pins' (ports C and D).  All we can say is that one must be 'careful' what functions to try to place on A0-4 (not all debuggers use all 5, by the way -- SWD&CLK and SWO might suffice for you on A0, A2 and A3).  Personally, I put 'status LEDs' on these lines, as while in the debugger "they don't matter".  And also, for IAR tools, I pre-start with this macro that LOCKS the pins to 'debug' functions, so that attempts in the code to run the LEDs will simply be ignored (this macro also happens to force a full reset-vector load, even while debugging):

execUserReset() {

    __var __reset;

   __reset = __readMemory32(4,"Memory");

  #PC = __reset;

   __reset = __readMemory32(0,"Memory");

  #SP = __reset;

  __message "---- Forcing Debug on Port A0,2,3 ----" ;

  __writeMemory32(0xFFFF,0x40048038, "Memory");         //Enable ALL the port clocks

  __writeMemory32(0x00008743,0x40049000, "Memory");  // PTA0 TCK LOCKED (SWD_CLK)

  __writeMemory32(0x00008743,0x40049008, "Memory");  // PTA2 Trace data LOCKED (SWO)

  __writeMemory32(0x00008743,0x4004900C, "Memory");  // PTA3 TDIO data LOCKED (SWD)

}