isr analog comparator problem

hello, i'm trying to star an interumpt when my sensor detect an object around 53cm, the IR distance sensor send voltage greater then 1,1v (wich is the reference), it means the IR send 1,1v at 54cm so a voltage greater then 1,1v is between 20cm-53cm thats where i want the interupt to occur , from the datasheet i got 3 modes of compar ;Rising (11),failing(10) and change(00) but the problem is that the 3 of them give me the same answer they generate an interumption between 54cm and 150cm and the interumpts stop at 20cm-53cm.
when i see the serial monitor it gives me an interupt when the ISR(ANALOG_COMP_vect) returns 1 but what i got is the oposite here is my code

int interrupt_inputpin = 7;
volatile int interrupt_var;
//---------------------------------------------------
void setup() 
{
 
  Serial.begin(9600); 
  pinMode(interrupt_inputpin, INPUT);
   pinMode(6, INPUT);
  ACSR = B01011010;
  interrupt_var = 0; 
}
//---------------------------------------------------
void loop() 
{
  if(interrupt_var == 1)
  {
    Serial.println(" +++++++ objet ++++++");
    interrupt_var = 0;
  }
  else
  {
    Serial.println(" waiting ");
  }
  delay(200);
}
//------------------------------------------------------------

//-----------------------------------------------------------
ISR(ANALOG_COMP_vect)
{
  interrupt_var = 1;
}
//------------------------------------------------------------
  ACSR = B01011010;

Can you re-do that line with symbolic constants please? Who knows what those bits are?

See: Gammon Forum : Electronics : Microprocessors : Using the Arduino Analog Comparator

Also please post your schematic.

B01011010;
ACSR =
(0<<ACD) | // Analog Comparator: Enabled
(1<<ACBG) | // Analog Comparator Bandgap Select: the internal reference is set
(0<<ACO) | // Analog Comparator Output: Off
(1<<ACI) | // Analog Comparator Interrupt Flag: Clear Pending Interrupt
(1<<ACIE) | // Analog Comparator Interrupt: Enabled
(0<<ACIC) | // Analog Comparator Input Capture: Disabled
(1<<ACIS1) | (0<ACIS0); // Analog Comparator Interrupt Mode: Comparator Interrupt on failing Output Edge

Thanks. You hardly need to show the "0" lines, right? Zero shifted left by x bits is still zero.

what i got is the oposite

Now show your wiring.

i dont havea a photo of it because i'm not home but i'm using an arduino nano with a GP2Y0A02 distance sensor on pin 7 .

what i ment is when the ISR(ANALOG_COMP_vect) occur the interrupt_var == 1 then the message "i got an interupt" is written but what i have is "waiting" when i know that voltage from the IR is higher from the refrence.

and ACSR = B01011010;
ACSR= [ACD= 0 , ACBG=1, ACO=0, ACI=1, ACIE=1, ACIC=0, ACIS1=1, ACIS0=0]

so the last two bits are the ones to change the comp technique from :
rising ( ACIS1=1, ACIS0=1) when IR<refrence
failing ( ACIS1=1, ACIS0=0) when IR>refrence
change ( ACIS1=0, ACIS0=0) when IR =! refrence

I'm not going to guess what you have done. Sketch your wiring. For example after searching for that sensor:

(note: this sensor draws current in large, short bursts, and the manufacturer recommends putting a 10 µF capacitor or larger across power and ground close to the sensor to stabilize the power supply line)

Do you have such a capacitor?

I tried simulating this with a potentiometer.

Code:

volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACBG)    // Analog Comparator Bandgap Select
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  int rawADC = analogRead (A0);
  const float Vref = 5;
  
  float voltage = ((float) rawADC  + 0.5 ) / 1024.0 * Vref;

  Serial.println (voltage);
    
  if (triggered)
    {
    Serial.println ("Triggered!"); 
    triggered = false;
    }
  delay (100);
  
  }  // end of loop

Results:

5.00
5.00
4.95
4.48
4.02
3.65
3.37
3.09
2.84
2.65
2.48
2.31
2.20
2.12
2.05
1.99
1.91
1.84
1.76
1.66
1.62
1.55
1.47
1.37
1.26
1.15
1.05
Triggered!
0.93
Triggered!
0.82
0.73
0.63
0.51

As you can see it triggered on the falling edge (there were two triggers probably because it would hover around the trigger point for a bit).

Wiring: Pot outer pins to +5V and Gnd. Pot middle pin to A0 and also joined to D7 (analog comparator negative input).

thank you and yes i do hae a capasitor of 10uf i will try your code and tell you my result