Hi All,
I am using Atmega1608 and using its internal AC to generate an INT on its positive edge. My system work as required for a second or two, but then suddenly my AC INT flag never gets cleared. I haven't faced this issue before, I am attacghing my AC init code and ISR for it. Please take a look at it. My IDE is IAR for AVR.
void analog_comparator_init()
{
VREF.CTRLA = VREF_AC0REFSEL_2V5_gc; /* Voltage reference at 2.5V */
VREF.CTRLB = VREF_AC0REFEN_bm; /* AC0 DACREF reference enable: enabled */
AC0.DACREF = 255; /* Set DAC voltage reference */
AC0.MUXCTRLA = AC_MUXPOS_PIN0_gc;
AC0.MUXCTRLA |= AC_MUXNEG_DACREF_gc;
AC0.INTCTRL = AC_CMP_bm;
AC0.CTRLA = AC_OUTEN_bm | AC_INTMODE_POSEDGE_gc | AC_ENABLE_bm ;
}
#pragma vector = AC0_AC_vect
__interrupt void AC_INT()
{
AC0.STATUS= AC_CMP_bm;
PORTA.OUTSET = PIN5_bm;
if (TCB0.CNT > 150)
{
EVSYS.STROBE = EVSYS_STROBE0_EV_STROBE_CH1_gc;
}
PORTA.OUTCLR = PIN5_bm;
}