-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* ADCUtils.h | ||
* | ||
* Copyright (C) 2016-2021 Armin Joachimsmeyer | ||
* Copyright (C) 2016-2022 Armin Joachimsmeyer | ||
* Email: [email protected] | ||
* | ||
* This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. | ||
|
@@ -17,12 +17,12 @@ | |
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>. | ||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>. | ||
* | ||
*/ | ||
|
||
#ifndef SRC_ADCUTILS_H_ | ||
#define SRC_ADCUTILS_H_ | ||
#ifndef _ADC_UTILS_H | ||
#define _ADC_UTILS_H | ||
|
||
#if defined(__AVR__) && (!defined(__AVR_ATmega4809__)) | ||
#include <Arduino.h> | ||
|
@@ -47,14 +47,6 @@ | |
#define ADC_PRESCALE ADC_PRESCALE128 | ||
#endif | ||
|
||
/* | ||
* By replacing this value with the voltage you measured a the AREF pin after a conversion | ||
* with INTERNAL you can calibrate your ADC readout. For my Nanos I measured e.g. 1060 mV and 1093 mV. | ||
*/ | ||
#ifndef ADC_INTERNAL_REFERENCE_MILLIVOLT | ||
#define ADC_INTERNAL_REFERENCE_MILLIVOLT 1100L // Value measured at the AREF pin | ||
#endif | ||
|
||
/* | ||
* Reference shift values are complicated for ATtinyX5 since we have the extra register bit REFS2 | ||
* in ATTinyCore, this bit is handled programmatical and therefore the defines are different. | ||
|
@@ -122,7 +114,7 @@ | |
uint16_t readADCChannel(uint8_t aChannelNumber); | ||
uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference); | ||
uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference); | ||
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUX(uint8_t aChannelNumber, uint8_t aReference); | ||
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aChannelNumber, uint8_t aReference); | ||
uint16_t readADCChannelWithOversample(uint8_t aChannelNumber, uint8_t aOversampleExponent); | ||
void setADCMultiplexerAndReferenceForNextConversion(uint8_t aChannelNumber, uint8_t aReference); | ||
uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent); | ||
|
@@ -150,6 +142,4 @@ float getTemperature(void); | |
|
||
#endif // defined(ADATE) | ||
#endif // defined(__AVR__) | ||
#endif /* SRC_ADCUTILS_H_ */ | ||
|
||
#pragma once | ||
#endif // _ADC_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* | ||
* ADCUtils.cpp | ||
* ADCUtils.hpp | ||
* | ||
* ADC utility functions. Conversion time is defined as 0.104 milliseconds for 16 MHz Arduinos in ADCUtils.h. | ||
* | ||
* Copyright (C) 2016-2020 Armin Joachimsmeyer | ||
* Copyright (C) 2016-2022 Armin Joachimsmeyer | ||
* Email: [email protected] | ||
* | ||
* This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. | ||
|
@@ -19,11 +19,23 @@ | |
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>. | ||
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>. | ||
*/ | ||
|
||
|
||
#ifndef _ADC_UTILS_HPP | ||
#define _ADC_UTILS_HPP | ||
|
||
#include "ADCUtils.h" | ||
#if defined(__AVR__) && defined(ADATE) | ||
#if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) | ||
|
||
/* | ||
* By replacing this value with the voltage you measured a the AREF pin after a conversion | ||
* with INTERNAL you can calibrate your ADC readout. For my Nanos I measured e.g. 1060 mV and 1093 mV. | ||
*/ | ||
#if !defined(ADC_INTERNAL_REFERENCE_MILLIVOLT) | ||
#define ADC_INTERNAL_REFERENCE_MILLIVOLT 1100L // Value measured at the AREF pin. If value > real AREF voltage, measured values are > real values | ||
#endif | ||
|
||
// Union to speed up the combination of low and high bytes to a word | ||
// it is not optimal since the compiler still generates 2 unnecessary moves | ||
|
@@ -92,7 +104,7 @@ uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aRef | |
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. | ||
* Restores ADMUX after reading | ||
*/ | ||
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUX(uint8_t aChannelNumber, uint8_t aReference) { | ||
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aChannelNumber, uint8_t aReference) { | ||
uint8_t tOldADMUX = checkAndWaitForReferenceAndChannelToSwitch(aChannelNumber, aReference); | ||
uint16_t tResult = readADCChannelWithReference(aChannelNumber, aReference); | ||
checkAndWaitForReferenceAndChannelToSwitch(tOldADMUX & MASK_FOR_ADC_CHANNELS, tOldADMUX >> SHIFT_VALUE_FOR_REFERENCE); | ||
|
@@ -435,8 +447,11 @@ float getTemperature(void) { | |
return (tTemp / 1.22); | ||
#endif | ||
} | ||
#elif defined(ARDUINO_ARCH_APOLLO3) | ||
|
||
#elif defined(ARDUINO_ARCH_APOLLO3) // defined(__AVR__) && defined(ADATE) | ||
void ADCUtilsDummyToAvoidBFDAssertions(){ | ||
; | ||
} | ||
#endif // defined(__AVR__) | ||
#endif // defined(__AVR__) && defined(ADATE) | ||
|
||
#endif // _ADC_UTILS_HPP |
Oops, something went wrong.