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

Thread: Port interrupt programming in Teensy 3.5

  1. #1
    Junior Member
    Join Date
    Mar 2018

    Port interrupt programming in Teensy 3.5

    Hi All
    I am trying to get this propeller balancer

    Working in Teensy 3.5.

    The following lines are written for the Mega which need to be converted to Teensy speak.

    //DDRK &= ~(1<<0); PORTK |= (1<<0); PCMSK2 |= (1<<0); PCICR |= (1<<2);


    PJRC have explanations of the Interrupts on

    But I can't get it to work. There are only a few examples of Port manipulation for interrupts on the net.

    Can someone explain step by step how this is converted ?

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    No need to struggle with direct port manipulation since the T3.5 is so much quicker than the Mega. Rewrite the code using attachInterrupt() and corresponding callback functions.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Yes I did that
    pinMode(3, INPUT_PULLDOWN);
    attachInterrupt(digitalPinToInterrupt(3),ISRspeed, RISING);

    But I need warp speed

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Quote Originally Posted by t-bird View Post
    But I need warp speed
    Ok then.... (though I'm skeptical it really matters when the hardware is a brushless motor that can't possibly change its magnetic fields anywhere near this ~100 nanoseconds time scale)

    You can get the fastest possible using digitalReadFast(pin), so at least that part is easy. If the pin number is a constant, this compiles to the native register access.

    For the interrupt, you can get it with ordinary attachInterrupt(), than then after attachInterrupt has done the setup work, you can directly commandeer the interrupt vector with attachInterruptVector(interrupt, function). This is defined in kinetis.h, so look there for details. You'll need to figure out which of the 5 actual native port interrupts your pin uses. The easiest way to find the native port/pin name is the schematic.

    Your native interrupt function MUST manually clear the interrupt flag in the port config register (chapter 10 in the manual). If you don't use the normal attachInterrupt function which does this for you, then your code is responsible. This flag isn't cleared automatically by hardware. If the interrupt code doesn't clear it before returning, your interrupt code will become an infinite loop, blocking all other lower priority interrupts.

    If you want the absolute fastest response time, also use NVIC_SET_PRIORITY(interrupt, 0) to give your interrupt the highest priority. Lower numbers are higher priority. By default, nothing is higher than 32, so if you give yours 0, it will interrupt all other interrupts, except of course when code has disabled all interrupts.

    Also use FASTRUN on your interrupt function, so the compiler puts it into the zero wait state RAM. By default, functions go into the flash memory.

    If you *really* want to dive into extreme ARM optimizations, I highly recommend Joseph Yiu's Definitive Guide book. It covers many important details of ARM Cortex-M that matter greatly for maximum optimization. You can find a link on the datasheets page.
    Last edited by PaulStoffregen; 03-18-2018 at 11:16 AM.

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Thank you Paul.

    I have already used NVIC_SET_PRIORITY(IRQ_PORTA, 0); which I got from one of your previous post.

    I will look at the FASTRUN function.

Posting Permissions

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