AnsweredAssumed Answered

FRDM KE02 board constant capture interrupt

Question asked by Dave Telling on Nov 25, 2014
Latest reply on Dec 2, 2014 by Dave Telling

I am trying to learn the Kinetis ARM system, and so far, it has been the most frustrating experience I have ever had with a microcontroller!

I cannot even get what should be a simple capture program to work.

I'm using the IAR 7.3 toolset, and my "main" project code is below:

 

 

/* simple capture program */

 

#include "common.h"

#include "ics.h"

#include "ftm.h"

#include "uart.h"

#include "sysinit.h"

 

static uint16_t counterVal;

void FTM2_Task(void);

 

int main(void)

{

  // Set FTM2 capture interrupt for rising edge, also enables IRQ

  FTM_InputCaptureInit(FTM2,FTM_CHANNEL_CHANNEL0,FTM_INPUTCAPTURE_RISINGEDGE);

  // Select system clock, with 16 divisor

  FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV16);

  // Set interrupt function reference

  FTM_SetCallback(FTM2, FTM2_Task);

  // Enable the channel mask for FTM2CH0

  FTM_EnableChannelInt(FTM2, (FTM_CHANNEL_CHANNEL0));   

  // GPIOA PTA0 and PTB3 are outputs

  GPIOA->PDDR = 0xffff0801;

  /* set PTB3 high to start */

  GPIOA->PDOR = 0x00000800;

  // Now just loop

  while (1)

  {

    ;

  }

}

 

void FTM2_Task(void)

  // Get capture value in variable

  counterVal = FTM2->CONTROLS[0].CnV;

  // Toggle PTB3

  GPIOA->PTOR = 0x0800; // toggle PTB3

}

 

Note that I SHOULD be going to FTM2_task at each rising edge of my input signal - I'm using the TTL output of a function generator, in the 600 Hz range. At each capture event, PTB3 should toggle.

If I put a breakpoint in the interrupt function, the system does what it should (kind of) i.e. PTB3 toggles each pass through. However - if I eliminate the breakpoint, and just run the program, the PTB3 output toggles at an interval of about 2.8 usec, no matter what the clock divider is set. It is as if the interrupt is constantly being called, and I cannot figure out why.

Any clues would be appreciated.

Outcomes