ACSR interrupt trigger issue

Hello,

I'm pretty new here and this is my first post.

I'm using a Arduino Uno to make a switch to sync two equipment. One equipment has analog output with the range from 0-5V. I let this signal go to AIN0 (I/O6) and also set AIN1 (I/O7) as 0.2V, so when the signal on AIN0 goes up to 0.2V, the internal ACSR trigger an interrupt to let I/O5 light on a LED for a bit and shut it down.

The ACSR is set based on the Amega328 datasheet and the interrupt triggering is on comparator output rising edge.

However, I found a problem that whenever the signal on AIN0 is changing higher or lower than 0.2V, an interrupt is triggered, even if I already set the triggering on the "AOC rising edge".

Could you please tell me what's the problem here? I attach my code underneath.

Thanks a lot!!!

//****************************************
volatile bool triggered= false;

int Rled=5;

void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode (Rled, OUTPUT);
digitalWrite (Rled, LOW);
ADCSRB =0;

// set ACSR
ADCSRB =0;
bitSet(ACSR,ACI);
bitSet(ACSR,ACIE);
bitSet(ACSR,ACIS1);
bitSet(ACSR, ACIS0);
bitClear(ACSR, ACIC);
bitClear(ACSR, ACBG);
}

void loop()
{
// put your main code here, to run repeatedly:
if(triggered)
{
digitalWrite(Rled, HIGH);
delay(2000);
digitalWrite(Rled, LOW);
triggered=false;
}
}

ISR (ANALOG_COMP_vect)
{
triggered = true;
}

sketch_apr24a.ino (829 Bytes)