How do get capture interrupt working on FRDM-KE02 board?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do get capture interrupt working on FRDM-KE02 board?

757 Views
davetelling
Contributor I

I confess - I'm a total noob at this ARM stuff - but it seems that someone has made it as confusing as possible to get anything done!

I am trying to do something that should be pretty simple - I just want to use FTM0, channel 0 to capture the rising edge of a signal on PTA0, and when the interrupt occurs,

toggle PTB0.

So far, I have this:

/* timer_test_3.c tests various timer interrupt & counting functions */

#include "common.h"

#include "ics.h"

#include "ftm.h"

#include "sysinit.h"

#include "gpio.h"

#include "sim.h"

/* not used right now

typedef struct

{

  uint8_t Port0;

  uint8_t Port1;

  uint8_t Port2;

  uint8_t Port3;

} fourBytes;

typedef struct

{

   uint16_t dbyte0;

   uint16_t dbyte1;

} twoDbyte;

static union {

  fourBytes portBytes;

  twoDbyte port16;

  uint32_t portWord;

}PORTA; */

void FTM0_Task(void);

/********************************************************************/

int main (void)

{

sysinit();

//SIM->SCGC |= SIM_SCGC_FTM0_MASK; // gate clock to FTM0

FTM_InputCaptureInit(FTM0,FTM_CHANNEL_CHANNEL0,FTM_INPUTCAPTURE_RISINGEDGE);

FTM_ClockSet(FTM0, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV2);

FTM_SetCallback(FTM0,FTM0_Task);

NVIC_EnableIRQ(FTM0_IRQn);

FTM_EnableChannelInt(FTM0,FTM_CHANNEL_CHANNEL0);

GPIOA->PDDR = 0xfffffffe; /* all ones except PTA0 for outputs */

  while (1)

  {

    ;

  }

}

/* Input capture interrupt */

void FTM0_Task(void)

{

  GPIOA->PTOR = 0x00000100; // PTB0

}

If I try to step through this, it goes through to the line that sets the clock to a divide by 2. If I click the "step" button again, the system never reaches the FTM_SetCallback line, it just keeps looping to the default_ISR location.

Note that I have commented out the original SIM setting to gate th eclock, as it appears to be embedded in the InputCaptureInit function.

If I comment out the FTM_SetCallback line (which I am assuming, is SUPPOSED to tell the compiler that I have an interrupt routine labeled FTM0_Task) and comment out the FTM)_Task, the program will run, sort of, in that the counter counts,

but obviously no interrupt. I have worked on this for hours, and cannot get past this roadblock.

Can someone show, very simply, how to do what I'm trying to do, or point out the obvious error in my code? I'm using the IAR toolset.

Tags (2)
0 Kudos
2 Replies

506 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Dave,

Your code is too complicated, for you call the driver of FTM. Based on your requirement, I develop a simple example to write register directly, it is straightforward. connect the captured to PTA0, you will see the toggling of PTB0 pin.

BR

XiangJun Rong

506 Views
davetelling
Contributor I

Xiangjun,

Thank you for the code sample. I will examine it and see if ti resolves my problems.

Dave Telling

0 Kudos