Sorry, I don't get it done but it has to be so easy. I want to use A0 and A1 to do a comparision of two voltages. So I use a voltage divider for a threshold on A0 and A1 is used for the voltage to be looked at. My addtional hardware is fine, so I test both pins using the ADC and I can "see" the right adjuested threshold on A0 and also the variable voltage on A1. I learnt from 328p datasheet that the initial configuration of the comparator is to use A0 for the positive input and A1 for the inverting one.
Change the voltage on A1 do not call my ISR. Here my code:
int detected = false;
void setup()
{
ACSR =
(0<<ACD) | // Analog Comparator: Enabled
(0<<ACBG) | // Analog Comparator Bandgap Select: AIN0 is applied to the positive input
(0<<ACO) | // only readable
(1<<ACI) | // Analog Comparator Interrupt Flag: Clear Pending Interrupt
(1<<ACIE) | // Analog Comparator Interrupt: Enabled
(0<<ACIC) | // Analog Comparator Input Capture: Disabled
(0<<ACIS1) | (0<ACIS0); // Analog Comparator Interrupt Mode: Comparator Interrupt on any edge
Serial.begin(19200);
}
void loop()
{
if (detected)
{
Serial.println("ISR");
}
}
ISR(ANALOG_COMP_vect )
{
detected = true;
}
I also tried similar code snippets but it doesn't work. Any idea what I have overseen?
I want to use A0 and A1 to do a comparision of two voltages. So I use a voltage divider for a threshold on A0 and A1 is used for the voltage to be looked at.
Why not feed the reference voltage in VRef, use analogReference(EXTERNAL), and just apply the voltage to be measured to another pin, and let the Arduino manage stuff?
It is possible to select any of the ADC7..0 pins to replace the negative input to the Analog Com-
parator. .....
If ACME is cleared or ADEN is set, AIN1 is applied to the negative input to the Analog
Comparator.
A0 and A1 are not the same as AIN0 and AIN1.
PC1 (ADC1/PCINT9) pin and PC0 (ADC0/PCINT8)
PCINT23 /AIN1 - pin D7 and PCINT22/OC0A/AIN0 - pin D6)