I am trying to write my own program ISR using the FlexTimer on a Teensy 3.1 but when I run the code I can only get the ISR to run one time and never again. I am connecting 3.3 volts to pin 3 to activate the interrupt which works like I said the first time only. This is driving me nuts because I've been reading Paul's FreqMeasure library over and over and copying the code and still no luck. I want to put 3.3 volts to pin 3 and read the C0V value and store it then touch pin 3 again and grab the C0V value again and calculate the frequency. I don't want to trip an ISR on Counter Overflow, just on pin 3 pulse. The program isn't setup for any particular function yet which is why I have the "count" value monitored to let me know when events happen. I can't get it work in general so I am unable to move forward with programming.
Code:
volatile uint32_t count = 0;
volatile uint32_t val = 0;
void setup()
{
Serial.begin(9600);
SetupOnBoardLED();
SetupFTM1Ch0();
}
void loop() {
Serial.println(count);
Serial.println(val);
delay(1000);
}
void SetupOnBoardLED()
{
//turn on the clock gating for the LED port.
SIM_SCGC5 = SIM_SCGC5|0x0800;
//enable the gpio port of the onboard LED.
PORTC_PCR5=0x100;
//set the onboard LED port direction to output.
GPIOC_PDDR=0x20;
}
#define FTM_SC_VALUE 0x0F//(FTM_SC_CLKS(1) | FTM_SC_PS(0))
#define CAPTURE_USE_FTM1_CH0 3 // FTM1 CH0 is pin 3
void SetupFTM1Ch0(void)
{
FTM1_SC = 0;
FTM1_CNT = 0;
FTM1_MOD = 0xFFFF;
FTM1_MODE = 0;
NVIC_SET_PRIORITY(IRQ_FTM1, 48);
FTM1_C0SC = 0b01000100;
*portConfigRegister(CAPTURE_USE_FTM1_CH0) = PORT_PCR_MUX(3);
NVIC_ENABLE_IRQ(IRQ_FTM1);
FTM1_SC = FTM_SC_VALUE;
}
void ftm1_isr(void)
{
if (FTM1_SC & FTM_SC_TOF)
{
count = count + 10;
FTM1_SC = FTM_SC_VALUE;
}
if ((FTM1_STATUS & 0xFF))
{
count = count + 100;
val = FTM1_C0V;
FTM1_C0SC &= ~(1<<7);
FTM1_C0V = 0;
FTM1_CNT = 0;
FTM1_SC = FTM_SC_VALUE;
FTM1_STATUS = 0;
GPIOC_PTOR=0x20;
}
count++;
}
Last edited by a moderator: