comparator interrupt handler (doesn't get called? or does it?)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

comparator interrupt handler (doesn't get called? or does it?)

Jump to solution
936 Views
rickstuart
Contributor V

Hi,

I have a KL27 on one of Freescale's development boards here and have not been able to get it to call a comparator interrupt routine.  I'll start out just describing what's going on.  If someone see the "bug" I've over looked that would be great.  If not, I can start posting bits of code.

I have a bit of Freescale example code where the D/A block of the KL27 is set up to supply a programmable reference to the Comparator block of the KL27.  My signal is the other input to the Comparator.  I wrote code to sample and send out the Comparator result to an external pin.  I can see the input and output perform as expected when I run this code.

Now I have added a method to handle the Comparator's interrupts.  I have set up the KL27's interrupt vectors for the CMP0 interrupt.  And I have set up the falling edge interrupt of the Comparator.  But now when I run my code it does nothing.  When I stop it, the program counter is at a place in memory that is outside of anything in the memory map the linker put together for this program.  The bit of code, in infinite loop, looks suspiciously close to the default interrupt handler that "should" be used if no interrupt handler was written for the "bitweak" defined interrupt.

Now, did the program go "south" because of a CMP0 interrupt??  Well, if I comment out the line that sets up the KL27's interrupt vector for the CMP0 the program works as expected.  Recall the program is written as an infinite loop which samples the state of the CMP0 comparator and outputs that to a pin.   That all works w/o the KL27's interrupt vector for CMP0 enabled.

Likewise, I can comment out the line that sets up the falling edge interrupt of the Comparator and get the program to sample and report the state of CMP0.

As one last test, I restored all the code and stopped sending my external signal into the KL27's Comparator.  That too allowed the program to work.  I could stop in the code, single step and then continue execution.

At this point, it sound like my interrupt code is bad and sending the program into a spin.  So I set a break point so the execution should stop as soon as it jumps to the interrupt handler.  That never breaks.  I then, just in case, move the break point to the default handler.  That never breaks.

Now what?

-thanks for any help or suggestions

0 Kudos
1 Solution
668 Views
rickstuart
Contributor V

Someone from Freescale suggested that my former FOPT register value (0xFFFFFFFE) was setup to send my processor off to boot ROM space where it would execute forever waiting for communications.  And to change it to (0xFFFF3DFE).  I have not see the problem since the change.  Here is the bit of code I changed.  Note where the value "0xFFFF3DFE" is located:

__FlashConfig

          DCD    0xFFFFFFFF

          DCD    0xFFFFFFFF

          DCD    0xFFFFFFFF

          DCD    0xFFFF3DFE

__FlashConfig_End

View solution in original post

0 Kudos
3 Replies
669 Views
rickstuart
Contributor V

Someone from Freescale suggested that my former FOPT register value (0xFFFFFFFE) was setup to send my processor off to boot ROM space where it would execute forever waiting for communications.  And to change it to (0xFFFF3DFE).  I have not see the problem since the change.  Here is the bit of code I changed.  Note where the value "0xFFFF3DFE" is located:

__FlashConfig

          DCD    0xFFFFFFFF

          DCD    0xFFFFFFFF

          DCD    0xFFFFFFFF

          DCD    0xFFFF3DFE

__FlashConfig_End

0 Kudos
668 Views
rickstuart
Contributor V

It was suggested that I switch turning on the CMP0 interrupt from "NVIC->ISER[0] = (1 << (CMP0_IRQn & 0x1f));" to "NVIC_EnableIRQ(CMP0_IRQn);".  When I single step through the code I see where "NVIC_EnableIRQ()" calls this method:

/** \brief  Enable External Interrupt

    The function enables a device-specific interrupt in the NVIC interrupt controller.

    \param [in]      IRQn  External interrupt number. Value cannot be negative.

*/

__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)

{

  NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));

}

As I am single stepping I fail to keep control of the code when executing the "NVIC->ISER[0]..." line above.  If I stop the debugger, I see that I am again back at address 0x1c002228 at an instructions which appears to be jumping back to address 0x1c002228 (i.e. infinite loop). This is the problem as described in my initial post.

What is really aggravating is that this code was working a few hours ago.  Good enough that I was able to debug a few problems I had.  But now we are back at address 0x1c002228 in an infinite loop.

Rest assured if I knew why the program started working as expected and/or why it is ending up at address 0x1c002228 (again) I would post the solution.

0 Kudos
668 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Rick,

Please consider to use below code to enable the CMP0 interrupt:

enable_irq(16);

void enable_irq (int irq)

{  

    /* Make sure that the IRQ is an allowable number. Up to 32 is

     * used.

     *

     * NOTE: If you are using the interrupt definitions from the header

     * file, you MUST SUBTRACT 16!!!

     */

    if (irq > 32)

        printf("\nERR! Invalid IRQ value passed to enable irq function!\n");

    else

    {

      /* Set the ICPR and ISER registers accordingly */

      NVIC_ICPR |= 1 << (irq%32);

      NVIC_ISER |= 1 << (irq%32);

    }

}

Wish it helps.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos