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 */
static uint16_t counterVal;
// Set FTM2 capture interrupt for rising edge, also enables IRQ
// Select system clock, with 16 divisor
FTM_ClockSet(FTM2, FTM_CLOCK_SYSTEMCLOCK, FTM_CLOCK_PS_DIV16);
// Set interrupt function reference
// Enable the channel mask for FTM2CH0
// GPIOA PTA0 and PTB3 are outputs
GPIOA->PDDR = 0xffff0801;
/* set PTB3 high to start */
GPIOA->PDOR = 0x00000800;
// Now just loop
// Get capture value in variable
counterVal = FTM2->CONTROLS.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.