Author Topic: AVR- Interrupt flag not getting cleared up  (Read 2203 times)

0 Members and 1 Guest are viewing this topic.

Offline sanka1pTopic starter

  • Contributor
  • Posts: 25
  • Country: us
AVR- Interrupt flag not getting cleared up
« on: February 29, 2024, 07:51:10 pm »
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.


Code: [Select]
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;
}
Using Analog in a Digital world.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3280
  • Country: gb
Re: AVR- Interrupt flag not getting cleared up
« Reply #1 on: March 02, 2024, 02:59:02 pm »
You don't have any hysteresis configured, perhaps you are seeing the interrupt being constantly raised due to noise when the input voltages of the comparator are very close?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf