Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: FTM Interrupt Service Routine Runs Once

  1. #1
    Member
    Join Date
    Apr 2014
    Location
    Saint Louis, Missouri
    Posts
    34

    FTM Interrupt Service Routine Runs Once

    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 manitou; 02-17-2020 at 01:54 PM. Reason: add CODE tags

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,616
    Why not use FreqMeasure lib? here are some tips and a DMA capture example
    https://forum.pjrc.com/threads/53142...ode-Teensy-3-5

  3. #3
    Member
    Join Date
    Apr 2014
    Location
    Saint Louis, Missouri
    Posts
    34
    Quote Originally Posted by manitou View Post
    Why not use FreqMeasure lib? here are some tips and a DMA capture example
    https://forum.pjrc.com/threads/53142...ode-Teensy-3-5
    I could use the freqmeasure lib but I'm trying to learn how to write my own libraries. When the ISR fires it does run once in the program I wrote but it never fires again. Does an ISR need to have the interrupt enabled after every event? I tried writing a zero to the ftm1_C0V register and reset the ftm1_C0SC interrupt flag was also reset but still the ISR only runs once.
    I'll look at the examples you sent and see if they help me get my head around this, thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •