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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
martinzw opened this issue Dec 15, 2018 · 0 comments
Open

Library handles ATMega 2560 etc. wrong! #11

martinzw opened this issue Dec 15, 2018 · 0 comments
Assignees
Labels

Comments

@martinzw
Copy link

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
@leomil72 leomil72 self-assigned this Dec 16, 2018
@leomil72 leomil72 added the bug label Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0