Skip to content

Commit

Permalink
Fixed bug for ESR > 64 Ohm
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Aug 1, 2022
1 parent f8b93aa commit 9da54e8
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 91 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ Because connecting to the Serial Plotter always resets the tester, we must be ab
</pre>

In the first row the **no load voltage** of the battery, the **30 second countdown** and the **load current** is displayed.
In the second row the **ESR** and the **difference between the load and no load voltage**, used to compute the ESR, is dispayed.
In the second row the **ESR** and the **difference between the load and no load voltage**, used to compute the ESR, is dispayed.<br/>
A value of **59.999 &ohm; indicates overflow** over the maximum value of 65.535 &ohm;.

## Mode StoreToEEPROM
- Every second, a sample is taken and displayed.
Expand Down
22 changes: 6 additions & 16 deletions UltimateBatteryTester/ADCUtils.h
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.
Expand All @@ -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>
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -150,6 +142,4 @@ float getTemperature(void);

#endif // defined(ADATE)
#endif // defined(__AVR__)
#endif /* SRC_ADCUTILS_H_ */

#pragma once
#endif // _ADC_UTILS_H
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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Loading

0 comments on commit 9da54e8

Please sign in to comment.