Open
Description
Hi leomil72,
I tested your lib and noticed, that you handle ATMEGA 2560 (16 analog ins) wrong.
If you select A0 to A15 for AIN+ with "SetOn" it only works for A0..A7.
You must only use Bit0..Bit2 of ADMUX in case of using A/D-multiplexer for analog comparator.
Bit 3 has to be written to ADCSRB's MUX5-Bit to complete the 4 bits necessary for value 0..15.
in addition, the Manual says, that you have to clear PRADC-Bit in PRR0 to use A/D-Multiplexer for comparator.
I entered the following in analogComp.cpp to correct: (from line 109 in analogComp.cpp)
#ifndef ATMEGAxU
#ifdef ATMEGAx0
//Bit "PRADC" in Register “PRR0" (Power Reduction Register 0)” has to be cleared, to use input multiplexer of A/D for comparator.
PRR0 &= ~(1<<PRADC);
ADMUX |= ((tempAIN1)& 0b00000111); //only MUX2 .. MUX0 are used for selection
AC_REGISTER &= ( ~(1<<MUX5)); //Bit4 must be written to AC_REGISTER (ADCSRB for ATMEGA2560)
AC_REGISTER |= ((tempAIN1 >7)<<MUX5);
#else
ADMUX |= tempAIN1; //choose the ADC channel (0..NUM_ANALOG_INPUTS-1)
#endif