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

Thread: Teensy 3.0 and interrupts

  1. #1

    Teensy 3.0 and interrupts

    I'm porting over an Arduino sketch that relied on the chip for timer-based interrupts. It looks to me from the documentation as though the proper timer to use for this on Teensy 3.0 is the periodic interrupt timer, PIT. So I did some setup:

    // Constants for bitvalues within the TCTRL1 register
    #define TIE 2
    #define TEN 1
    void timer_setup() {
    /* Arduino version of timer setup
      TCCR2A = 0;
      TCNT2=455;    //455 outputs 1.007khz
      TCCR2B = B00000010;
      //Timer2 Overflow Interrupt Enable
      TIMSK2 = 1<<TOIE2;
      // Teensy 3.0 version
      // Turn on PIT
      PIT_MCR = 0x00;
      // Set the period of the timer.  Unit is (1 / 50MHz) = 20ns
      // So 1 kHz frequency -> 1 ms period -> 50000 * 20ns
      PIT_LDVAL1 = 50000;
      // Enable interrupts on Timer1
      PIT_TCTRL1 = TIE;
      // Start the timer
      PIT_TCTRL1 |= TEN;

    I'm not completely certain that's correct, but it's similar to code included in the chip datasheet.

    But I'm not really sure how to declare an interrupt handler for the PIT. The Arduino code is
    ISR(TIMER2_OVF_vect) { 
    // function body

    but of course that's for the AVR timer interrupt. I tried to look through the hardware/teensy3 code, but I couldn't find the relevant bits. The datasheet just says "See the MCU specification for related vector addresses and priorities," and I couldn't work out what that meant. (My best guess was "", but that doesn't have any relevant information.)

    Is there a good source of documentation on this?


  2. #2
    Sorry, probably should have been in "General Guidance." Not sure how to move it--just copying the post over there. Sorry all!

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