attachInterruptVector(IRQ_CMP1,isr), how to write isr?

wangnick

Well-known member
Dear all,

I'm trying to measure the time it takes an 100nF capacitor to discharge via a 100kΩ resistor to about 1V after being fully charged to 3.3V, using analog comparator 1 of a Teensy 3.2, Arduino 1.8.12/Teensyduino 1.51 and the test program View attachment LightCmpTestSimple.ino.

CMP1_OUT signals the voltage transitions properly on the scope, and they are also properly reflected in CMP1_SCR.

However, I don't get the interrupt service routing to work. It seems to be called, as when I implement a naked empty isr just ahead of setup, upon interrupt the setup routine is executed again.

But whenever I try to do something in the isr, the Teensy hangs up (in the sense that it doesn't upload new software automatically anymore, only by pressing the program button).

I've spent now over six hours trying all kind of combinations and examples of isr as found in misc libraries, but nothing works.

How do I write such an isr? Which __attribute do I have to declare, and what asm preamble and postamble to use on the K20?

Kind regards,
Sebastian
 
What I believe is happening is you are doing nothing to keep the ISR from retriggering.

That is when your ISR is called and you return, the same condition exists and your ISR will be called again and again and again...

Two typical ways to handle it depending on your needs.

Clear what ever condition is set that triggers the event. I would need to relook up CMP1 stuff to know exactly what this is.
It may be clearing a bit in the status register, or maybe reading some other register clears...

and/or B: disable the ISR... That is if it is a one shot your ISR could do a: NVIC_DISABLE_IRQ(IRQ_CMP1);
 
Attached your Sketch, slightly edited with working interrupt.

It was correct so far, only resetting the Int-Flags was missing (as Kurt alrady mentioned).

CMP1_SCR |= 0b110;
 

Attachments

  • LightCmpTestSimple.ino
    3.5 KB · Views: 63
Ah, I wasn't aware that the interrupt would re-execute as long as it is enabled with the originating flag still asserted. From AVR is was used to the hardware clearing the corresponding flag prior to calling the interrupt routine. Thanks for the swift help!

Kind regards,
Sebastian
 
Back
Top