Capturing timer value based on external interrupt , leveraging the 62.5nsec (16MHz) resolution) of the ATMEGA328 on the Arduino Uno

TIMSK1=(1<<ICIE1)|(1<<TOIE1);

The code does not like having the overflow interrupt enabled without an overflow interrupt vector.

I don't see where you actually use the overflow interrupt vector, so you can change the line to just the input capture.
TIMSK1=(1<<ICIE1);

Alternatively, until you figure out what you want for the overflow vector just use a dummy

ISR (TIMER1_OVF_vect)
{
  return;
}

Either course allows the program to avoid the resets.

the original code, not this debug version, has the overflow vector ISR defined --in fact, just like you wrote it since I didn't know how I wanted to handle it yet. It resets similarly -- but perhaps for a different reason.
I will try it on the debug version to see if that makes it run without resets...
Thank you!

You are getting the value from ICR1 but in the ISR you saved the value in dlyTime.

You are enabling the Timer1 Overrflow Interrupt but you didn't define an ISR for that interrupt.

I don't THINK it's a problem but I would take the 'return;' statement out of the ISR.

In your ISR you stop the counter but I don't think that will prevent the ISR from triggering again if the analog compare triggers again.

The official way to write an empty interrupt vector is shown here
(avr-libc: <avr/interrupt.h>: Interrupts)

Instead of the empty vector or with the use of return, use instead

EMPTY_INTERRUPT(TIMER1_OVF_vect);

Alternatively, you can make an active overflow vector and increment an overflow count, which is what you will do if you actually use the overflow vector.

What are the values in this RC network and are you discharging the capacitor directly with the Arduino pin or using a transistor?

which also states:


If an unexpected interrupt occurs (interrupt is enabled and no handler is installed,
which usually indicates a bug), then the default action is to reset the device by
jumping to the reset vector.

Seems kinda familiar...

1 Like

Yes, if the interrupt is enabled/triggered and there is no interrupt vector, the program jumps to the NULL vector which is at memory address 0 and is the reset vector for the avr platforms.

@blh64, indeed!!

I found the issue on Sunday. I misunderstood the datasheet and was enabling the comparator interrupt as well, when what I wanted was just to enable the Analog Comparator Input Capture (ACIC bit on ACSR). It was jumping to the (undefined) comparator interrupt vector.

Thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.