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

Thread: enable CMP! interrupt on T_3.5

  1. #1

    enable CMP! interrupt on T_3.5

    Hi,
    in this forum I found code examples for using the comparator in a Teensy 3.5.
    For comparator 1 a code example used
    Code:
    NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
    The macro name says that it is an enable function. The comment says that with this macro cmp1_isr() is attached to the interrupt.
    In kinetis.h I found the definition of NVIC_ENABLE_IRQ but I don't understand what's going on there.

    Performs this macro both, enable and attach, or only one of it?

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    209
    ISTR there is also a clock enable bit that allows the comparitor to function. Perhaps it was in a post by @thereminengineer (apologies)

  3. #3
    Quote Originally Posted by NikoTeen View Post
    Hi,
    in this forum I found code examples for using the comparator in a Teensy 3.5.
    For comparator 1 a code example used
    Code:
    NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
    The macro name says that it is an enable function. The comment says that with this macro cmp1_isr() is attached to the interrupt.
    In kinetis.h I found the definition of NVIC_ENABLE_IRQ but I don't understand what's going on there.

    Performs this macro both, enable and attach, or only one of it?
    cmp1_isr() is defined in cores\Teensy3\mk20dx128.c as shown below.

    Code:
    void cmp1_isr(void)		__attribute__ ((weak, alias("unused_isr")));
    Further down in the same file, cmp_isr is assigned as default interrupt vector for the CMP1 interrupt. So, if you enable the interrupt, and the interrupt occurs, the default cmp1_isr() will be executed. It doesn't do anything, so the interrupt flag won't be cleared, and your program will hang. You need to implement your own cmp1_isr() in your sketch, process the interrupt and clear the flag. Because the function in the Teensy3 core is defined as "weak", the linker will use your function instead of the default.

Posting Permissions

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