8000 Library handles ATMega 2560 etc. wrong! · Issue #11 · leomil72/analogComp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Library handles ATMega 2560 etc. wrong! #11
Open
@martinzw

Description

@martinzw

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0