From 20897d9d84ffed3944744e6e4e59ef64d1bacc74 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Fri, 18 Nov 2016 13:42:51 +1100 Subject: [PATCH] Final tidy up of ADC interrupt before merge --- sensors.h | 6 +++--- sensors.ino | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sensors.h b/sensors.h index a22aa5a8..9b227bdc 100644 --- a/sensors.h +++ b/sensors.h @@ -44,13 +44,13 @@ ISR(ADC_vect) #if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) if (nChannel==7) { ADMUX = 0x40; } #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - if(ADCSRB & 0x08) { nChannel+=8; } //8 to 15 - if(nChannel==15) + if(ADCSRB & 0x08) { nChannel += 8; } //8 to 15 + if(nChannel == 15) { ADMUX = 0x40; //channel 0 ADCSRB = 0x00; //clear MUX5 bit } - else if (nChannel==7) //channel 7 + else if (nChannel == 7) //channel 7 { ADMUX = 0x40; ADCSRB = 0x08; //Set MUX5 bit diff --git a/sensors.ino b/sensors.ino index 4230d202..e54f4a34 100644 --- a/sensors.ino +++ b/sensors.ino @@ -15,7 +15,6 @@ void initialiseADC() noInterrupts(); //Interrupts should be turned off when playing with any of these registers ADCSRB = 0x00; //ADC Auto Trigger Source is in Free Running mode - //ADCSRB &= B11111000; ADMUX = 0x40; //Select AREF as reference, ADC Left Adjust Result, Starting at channel 0 //All of the below is the longhand version of: ADCSRA = 0xEE; @@ -24,7 +23,7 @@ void initialiseADC() BIT_SET(ADCSRA,ADIE); //Set ADC interrupt enabled BIT_CLEAR(ADCSRA,ADIF); //Clear interrupt flag - // Set ADC clock to 250KHz (Prescaler = 64) + // Set ADC clock to 125KHz (Prescaler = 128) BIT_SET(ADCSRA,ADPS2); BIT_SET(ADCSRA,ADPS1); BIT_SET(ADCSRA,ADPS0); @@ -35,10 +34,9 @@ void initialiseADC() BIT_SET(ADCSRA,ADSC); //Start conversion #else - //This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS) + //This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS) when using the standard analogRead() function //1Mhz is the fastest speed permitted by the CPU without affecting accuracy - //Please see chapter 11 of 'Practical Arduino' (http://books.google.com.au/books?id=HsTxON1L6D4C&printsec=frontcover#v=onepage&q&f=false) for more details - //Can be disabled by removing the #include "fastAnalog.h" above + //Please see chapter 11 of 'Practical Arduino' (http://books.google.com.au/books?id=HsTxON1L6D4C&printsec=frontcover#v=onepage&q&f=false) for more detail BIT_SET(ADCSRA,ADPS2); BIT_CLEAR(ADCSRA,ADPS1); BIT_CLEAR(ADCSRA,ADPS0);