From 25fea87140db26dcfbd7d00b04ebf1cf31b7dce3 Mon Sep 17 00:00:00 2001 From: leo72 Date: Tue, 3 Apr 2018 18:06:21 +0200 Subject: [PATCH] Fixed code to enable/disable digital buffers (they were inverted!). Fixed ADC enable/disable: for a type, the code worked on the wrong register --- README.txt | 6 +++-- analogComp.cpp | 61 +++++++++++++++++++++++----------------------- analogComp.h | 42 +++++++++++++++---------------- library.properties | 3 +-- version | 2 +- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/README.txt b/README.txt index 150f25f..827b5d2 100644 --- a/README.txt +++ b/README.txt @@ -2,7 +2,7 @@ analogComp -This little library can be used to set and manage the analog +This little library can be used to set and manage the analog comparator that is integrated in a wide variety of Atmel microcontrollers @@ -12,6 +12,7 @@ Written by Leonardo Miliani *********************** Version history +v. 1.2.4: fixed code to enable/disable digital buffers (they were inverted!) - thanks to ami2go. Fixed ADC enable/disable: for a type, the code worked on the wrong register v. 1.2.3: added support for ATmega32U4 (old Leonardo boards) - thanks to stefandz v. 1.2.2: added compatibility with Arduino IDE >= 1.6.7 v. 1.2.1: fixed a bug that let the ADC off after a comparison @@ -139,6 +140,7 @@ them inside the library, please edit the analogComp.h file and change the value 6 to 8 of the following compiler's directive: #define ATMEGAx8 #define NUM_ANALOG_INPUTS 6 + *********************** Licence @@ -155,4 +157,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *********************** Document revision -11th revision: 2016/11/08 +Last revision: 2018/04/03 diff --git a/analogComp.cpp b/analogComp.cpp index d545a0a..88c3878 100644 --- a/analogComp.cpp +++ b/analogComp.cpp @@ -102,7 +102,7 @@ uint8_t analogComp::setOn(uint8_t tempAIN0, uint8_t tempAIN1) { ADMUX &= ~31; //reset the first 5 bits #ifndef ATMEGAxU ADMUX |= tempAIN1; //choose the ADC channel (0..NUM_ANALOG_INPUTS-1) - #else + #else switch(tempAIN1){ // see p. 313 of Atmel-7766J-USB-ATmega16U4/32U4-Datasheet_04/2016 case 0: @@ -111,58 +111,58 @@ uint8_t analogComp::setOn(uint8_t tempAIN0, uint8_t tempAIN1) { break; case 1: ADMUX |= 0b00000001; - AC_REGISTER &= ~bit(MUX5); + AC_REGISTER &= ~bit(MUX5); break; case 2: // not a valid choice - and not broken out onto Leonardo / Micro type boards break; case 3: - // not a valid choice - and not broken out onto Leonardo / Micro type boards + // not a valid choice - and not broken out onto Leonardo / Micro type boards break; case 4: ADMUX |= 0b00000100; - AC_REGISTER &= ~bit(MUX5); + AC_REGISTER &= ~bit(MUX5); break; case 5: ADMUX |= 0b00000101; - AC_REGISTER &= ~bit(MUX5); + AC_REGISTER &= ~bit(MUX5); break; case 6: ADMUX |= 0b00000110; - AC_REGISTER &= ~bit(MUX5); + AC_REGISTER &= ~bit(MUX5); break; case 7: ADMUX |= 0b00000111; - AC_REGISTER &= ~bit(MUX5); + AC_REGISTER &= ~bit(MUX5); break; case 8: //ADMUX |= 0b00000000; // redundant - AC_REGISTER |= bit(MUX5); + AC_REGISTER |= bit(MUX5); break; case 9: ADMUX |= 0b00000001; - AC_REGISTER |= bit(MUX5); + AC_REGISTER |= bit(MUX5); break; case 10: - ADMUX |= 0b00000010; - AC_REGISTER |= bit(MUX5); + ADMUX |= 0b00000010; + AC_REGISTER |= bit(MUX5); break; case 11: - ADMUX |= 0b00000011; - AC_REGISTER |= bit(MUX5); + ADMUX |= 0b00000011; + AC_REGISTER |= bit(MUX5); break; case 12: - ADMUX |= 0b00000100; - AC_REGISTER |= bit(MUX5); + ADMUX |= 0b00000100; + AC_REGISTER |= bit(MUX5); break; case 13: - ADMUX |= 0b00000101; - AC_REGISTER |= bit(MUX5); + ADMUX |= 0b00000101; + AC_REGISTER |= bit(MUX5); break; default: break; } - #endif + #endif AC_REGISTER |= (1<=100 #if defined(ARDUINO) && (ARDUINO >= 100) @@ -41,37 +41,37 @@ #undef NUM_ANALOG_INPUTS #endif -#define AC_REGISTER ADCSRB +#define AC_REGISTER ADCSRA //check if the micro is supported #if defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega48P__) || defined (__AVR_ATmega88P__) || defined (__AVR_ATmega168P__) || defined (__AVR_ATmega328P__) -#define ATMEGAx8 -#define NUM_ANALOG_INPUTS 6 + #define ATMEGAx8 + #define NUM_ANALOG_INPUTS 6 #elif defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) -#define ATTINYx5 -#define NUM_ANALOG_INPUTS 4 + #define ATTINYx5 + #define NUM_ANALOG_INPUTS 4 #elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8A__) -#define ATMEGA8 -#undef AC_REGISTER -#define AC_REGISTER SFIOR -#define NUM_ANALOG_INPUTS 6 + #define ATMEGA8 + #undef AC_REGISTER + #define AC_REGISTER SFIOR + #define NUM_ANALOG_INPUTS 6 #elif defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) -#define ATTINYx4 -#define NUM_ANALOG_INPUTS 8 + #define ATTINYx4 + #define NUM_ANALOG_INPUTS 8 #elif defined (__AVR_ATmega640__) || defined (__AVR_ATmega1280__) || defined (__AVR_ATmega1281__) || defined (__AVR_ATmega2560__) || defined (__AVR_ATmega2561__) -#define ATMEGAx0 -#define NUM_ANALOG_INPUTS 16 + #define ATMEGAx0 + #define NUM_ANALOG_INPUTS 16 #elif defined (__AVR_ATmega344__) || defined (__AVR_ATmega344P__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) || defined (__AVR_ATmega1284P__) -#define ATMEGAx4 -#define NUM_ANALOG_INPUTS 8 + #define ATMEGAx4 + #define NUM_ANALOG_INPUTS 8 #elif defined (__AVR_ATtiny2313__) || defined (__AVR_ATtiny4313__) -#define ATTINYx313 -#define NUM_ANALOG_INPUTS 0 + #define ATTINYx313 + #define NUM_ANALOG_INPUTS 0 #elif defined (__AVR_ATmega32U4__) -#define ATMEGAxU -#define NUM_ANALOG_INPUTS 14 // there are more inputs on the 32u4 than are broken out to the board + #define ATMEGAxU + #define NUM_ANALOG_INPUTS 14 // there are more inputs on the 32u4 than are broken out to the board // and they are not mapped sequentially #else -#error Sorry, microcontroller not supported! + #error Sorry, microcontroller not supported! #endif diff --git a/library.properties b/library.properties index 2bc8894..f63f4d4 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=analogComp -version=1.2.3 +version=1.2.4 author=Leonardo Miliani maintainer=Leonardo Miliani sentence=Set and manage the integrated analog comparator @@ -7,4 +7,3 @@ paragraph= category=Signal Input/Output url=http://www.leonardomiliani.com architectures=avr - diff --git a/version b/version index 0495c4a..e8ea05d 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.2.3 +1.2.4