Analog Comparators- Cant make it work

Hi
I have been unsuccessful in making any program work using ANALOG_COMP_vect.

(I've used Nick Gammons, AnalogComp.h examples and several others including frequency measuring programs, any thing I can find)

I have a 20K/20K resistor divider center to AIN1 (2.5V) and a 10K pot into AIN0, both connected to 5V and ground.

Have tried on several Nanos and a Mega.

Using Nick's program (attached) irrespective of the start voltage on AIN0 I get a trigger

My understanding is that I should get a trigger only when AIN0 is less than AIN1 (falling)
(by the way, how much less before the ISR operates?)

Is there something I am missing in the general setup of the analog inputs?
Any other clues?

AnalogComparitor_Gammon.ino (1.47 KB)

You need to make a pencil drawing showing how you have everything connected and post a photo of the drawing.

On the Uno (and presumably the Nano) AINO is Arduino digital pin 6 and AIN1 is digital pin 7

...R

I can't duplicate your problem on a Uno. I've not used the analog comparator before so it was an interesting experiment for me. I've tried with the test sketch below. If the voltage on AIN0 is less than that of AIN1, then there is no false trigger even if the Arduino is reset.

AIN0 = Pin D6
AIN1 = Pin D7
LED on D12.

If you have actually measured voltages, then it is difficult to imagine a wiring error. Of course, a potentiometer will not be 100% smooth as you are adjusting the value so you will get mixed rising and falling edges.

// as Nick Gammon's sketch but also with a LED 

volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  pinMode( 12, OUTPUT ) ;  // led on pin 12
  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 (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  digitalWrite( 12, ACSR & bit (ACO) ) ;   // 0b00100000
  if (triggered)
    {
    Serial.println ("Triggered!"); 
    triggered = false;
    }
  
  }  // end of loop