Skip to content

Commit 3906e2c

Browse files
committed
Bumped version to 4.3.0
1 parent 5b729b3 commit 3906e2c

File tree

5 files changed

+250
-70
lines changed

5 files changed

+250
-70
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ Average minutes remaining until empty: 16 h 11 min
236236
![Fritzing schematics](extras/SBMInfo_Schaltplan.png)
237237

238238
# Revision History
239-
### Version 4.3
239+
### Version 4.3.0
240240
- Fixed no voltage measurement bug.
241241
- Improved print and LCD display after I2C reconnection.
242242

243-
### Version 4.2
243+
### Version 4.2.0
244244
- Removed compile time warnings.
245245

246246
### Version 4.1.0

SBMInfo/ADCUtils.h

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,87 @@
8585
#define ADC_TEMPERATURE_CHANNEL_MUX 15
8686
#define ADC_1_1_VOLT_CHANNEL_MUX 12
8787
#define ADC_GND_CHANNEL_MUX 13
88+
#define ADC_CHANNEL_MUX_MASK 0x0F
8889

8990
#elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
9091
#define ADC_ISCR_CHANNEL_MUX 3
9192
#define ADC_TEMPERATURE_CHANNEL_MUX 11
9293
#define ADC_1_1_VOLT_CHANNEL_MUX 12
9394
#define ADC_GND_CHANNEL_MUX 14
9495
#define ADC_VCC_4TH_CHANNEL_MUX 13
96+
#define ADC_CHANNEL_MUX_MASK 0x1F
9597

9698
#elif defined(__AVR_ATmega328P__)
9799
#define ADC_TEMPERATURE_CHANNEL_MUX 8
98100
#define ADC_1_1_VOLT_CHANNEL_MUX 14
99101
#define ADC_GND_CHANNEL_MUX 15
102+
#define ADC_CHANNEL_MUX_MASK 0x0F
103+
104+
#elif defined(__AVR_ATmega644P__)
105+
#define ADC_TEMPERATURE_CHANNEL_MUX // not existent
106+
#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E
107+
#define ADC_GND_CHANNEL_MUX 0x1F
108+
#define ADC_CHANNEL_MUX_MASK 0x0F
100109

101110
#elif defined(__AVR_ATmega32U4__)
102111
#define ADC_TEMPERATURE_CHANNEL_MUX 0x27
103112
#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E
104113
#define ADC_GND_CHANNEL_MUX 0x1F
114+
#define ADC_CHANNEL_MUX_MASK 0x3F
105115

106116
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
107117
#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E
108118
#define ADC_GND_CHANNEL_MUX 0x1F
119+
#define ADC_CHANNEL_MUX_MASK 0x1F
120+
109121
#define INTERNAL INTERNAL1V1
110122

111123
#else
112124
#error "No temperature channel definitions specified for this AVR CPU"
113125
#endif
114126

127+
/*
128+
* Thresholds for OVER and UNDER voltage and detection of kind of power supply (USB or Li-ion)
129+
*
130+
* Default values are suitable for Li-ion batteries.
131+
* We normally have voltage drop at the connectors, so the battery voltage is assumed slightly higher, than the Arduino VCC.
132+
* But keep in mind that the ultrasonic distance module HC-SR04 may not work reliable below 3.7 volt.
133+
*/
134+
#if !defined(LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT)
135+
#define LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT 3400 // Do not stress your battery and we require some power for standby
136+
#endif
137+
#if !defined(LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT)
138+
#define LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT 3000 // Many Li-ions are specified down to 3.0 volt
139+
#endif
140+
141+
#if !defined(VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT)
142+
#define VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT
143+
#endif
144+
#if !defined(VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT)
145+
#define VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT
146+
#endif
147+
#if !defined(VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT)
148+
#define VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT 5250 // + 5 % operation voltage
149+
#endif
150+
#if !defined(VCC_EMERGENCY_OVERVOLTAGE_THRESHOLD_MILLIVOLT)
151+
#define VCC_EMERGENCY_OVERVOLTAGE_THRESHOLD_MILLIVOLT 5500 // +10 %. Max recommended operation voltage
152+
#endif
153+
#if !defined(VCC_CHECK_PERIOD_MILLIS)
154+
#define VCC_CHECK_PERIOD_MILLIS 10000L // 10 seconds period of VCC checks
155+
#endif
156+
#if !defined(VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP)
157+
#define VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP 6 // Shutdown after 6 times (60 seconds) VCC below VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT or 1 time below VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT
158+
#endif
159+
160+
#if !defined(VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT)
161+
#define VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT 4300 // Assume USB powered above this voltage
162+
#endif
163+
164+
#if !defined(VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT)
165+
#define VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT 4950 // Assume USB powered below this voltage, because of the loss in USB cable. If we have > 4950, we assume to be powered by VIN.
166+
// In contrast to e.g. powered by VIN, which results in almost perfect 5 volt supply
167+
#endif
168+
115169
extern long sLastVCCCheckMillis;
116170
extern uint8_t sVCCTooLowCounter;
117171

@@ -122,7 +176,10 @@ uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t a
122176
uint16_t readADCChannelWithOversample(uint8_t aADCChannelNumber, uint8_t aOversampleExponent);
123177
void setADCChannelAndReferenceForNextConversion(uint8_t aADCChannelNumber, uint8_t aReference);
124178
uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);
125-
uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples);
179+
uint32_t readADCChannelMultiSamples(uint8_t aPrescale, uint16_t aNumberOfSamples);
180+
uint16_t readADCChannelMultiSamplesWithReference(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples);
181+
uint32_t readADCChannelMultiSamplesWithReferenceAndPrescaler(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aPrescale,
182+
uint16_t aNumberOfSamples);
126183
uint16_t readADCChannelWithReferenceMax(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples);
127184
uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire);
128185
uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aDelay,
@@ -150,11 +207,15 @@ float getCPUTemperatureSimple(void);
150207
float getCPUTemperature(void);
151208
float getTemperature(void) __attribute__ ((deprecated ("Renamed to getCPUTemperature()"))); // deprecated
152209

153-
bool isVCCTooLowMultipleTimes();
154-
void resetVCCTooLowMultipleTimes();
155-
bool isVCCTooLow();
156-
bool isVCCTooHigh();
157-
bool isVCCTooHighSimple();
210+
bool isVCCUSBPowered();
211+
bool isVCCUSBPowered(Print *aSerial);
212+
bool isVCCUndervoltageMultipleTimes();
213+
void resetCounterForVCCUndervoltageMultipleTimes();
214+
bool isVCCUndervoltage();
215+
bool isVCCEmergencyUndervoltage();
216+
bool isVCCOvervoltage();
217+
bool isVCCOvervoltageSimple(); // Version using readVCCVoltageMillivoltSimple()
218+
bool isVCCTooHighSimple(); // Version not using readVCCVoltageMillivoltSimple()
158219

159220
#endif // defined(__AVR__) ...
160221

0 commit comments

Comments
 (0)