You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* By replacing this value with the voltage you measured a the AREF pin after a conversion
34
38
* with INTERNAL you can calibrate your ADC readout. For my Nanos I measured e.g. 1060 mV and 1093 mV.
35
39
*/
36
40
#if !defined(ADC_INTERNAL_REFERENCE_MILLIVOLT)
37
-
#defineADC_INTERNAL_REFERENCE_MILLIVOLT1100L//Value measured at the AREF pin. If value > real AREF voltage, measured values are > real values
41
+
#defineADC_INTERNAL_REFERENCE_MILLIVOLT1100L//Change to value measured at the AREF pin. If value > real AREF voltage, measured values are > real values
38
42
#endif
39
43
40
44
// Union to speed up the combination of low and high bytes to a word
@@ -50,6 +54,16 @@ union WordUnionForADCUtils {
50
54
uint8_t *BytePointer;
51
55
};
52
56
57
+
/*
58
+
* Persistent storage for VCC value
59
+
*/
60
+
floatsVCCVoltage;
61
+
uint16_tsVCCVoltageMillivolt;
62
+
63
+
// for isVCCTooLowMultipleTimes()
64
+
longsLastVoltageCheckMillis;
65
+
uint8_tsVoltageTooLowCounter = 0;
66
+
53
67
/*
54
68
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
* Default values are suitable for Li-ion batteries.
496
+
* We normally have voltage drop at the connectors, so the battery voltage is assumed slightly higher, than the Arduino VCC.
497
+
* But keep in mind that the ultrasonic distance module HC-SR04 may not work reliable below 3.7 volt.
498
+
*/
499
+
#if !defined(VCC_STOP_THRESHOLD_MILLIVOLT)
500
+
#defineVCC_STOP_THRESHOLD_MILLIVOLT3400// Do not stress your battery and we require some power for standby
501
+
#endif
502
+
#if !defined(VCC_EMERGENCY_STOP_MILLIVOLT)
503
+
#defineVCC_EMERGENCY_STOP_MILLIVOLT3000// Many Li-ions are specified down to 3.0 volt
504
+
#endif
505
+
#if !defined(VCC_CHECK_PERIOD_MILLIS)
506
+
#defineVCC_CHECK_PERIOD_MILLIS10000// Period of VCC checks
507
+
#endif
508
+
#if !defined(VCC_CHECKS_TOO_LOW_BEFORE_STOP)
509
+
#defineVCC_CHECKS_TOO_LOW_BEFORE_STOP6// Shutdown after 6 times (60 seconds) VCC below VCC_STOP_THRESHOLD_MILLIVOLT or 1 time below VCC_EMERGENCY_STOP_MILLIVOLT
510
+
#endif
511
+
512
+
/*
513
+
* @ return true only once, when VCC_CHECKS_TOO_LOW_BEFORE_STOP (6) times voltage too low -> shutdown
514
+
*/
515
+
boolisVCCTooLowMultipleTimes() {
516
+
/*
517
+
* Check VCC every VCC_CHECK_PERIOD_MILLIS (10) seconds
518
+
*/
519
+
520
+
if (millis() - sLastVoltageCheckMillis >= VCC_CHECK_PERIOD_MILLIS) {
521
+
sLastVoltageCheckMillis = millis();
522
+
523
+
# if defined(INFO)
524
+
readAndPrintVCCVoltageMillivolt(&Serial);
525
+
# else
526
+
readVCCVoltageMillivolt();
527
+
# endif
528
+
529
+
if (sVoltageTooLowCounter < VCC_CHECKS_TOO_LOW_BEFORE_STOP) {
530
+
/*
531
+
* Do not check again if shutdown has happened
532
+
*/
533
+
if (sVCCVoltageMillivolt > VCC_STOP_THRESHOLD_MILLIVOLT) {
534
+
sVoltageTooLowCounter = 0; // reset counter
535
+
} else {
536
+
/*
537
+
* Voltage too low, wait VCC_CHECKS_TOO_LOW_BEFORE_STOP (6) times and then shut down.
538
+
*/
539
+
if (sVCCVoltageMillivolt < VCC_EMERGENCY_STOP_MILLIVOLT) {
Copy file name to clipboardExpand all lines: SBMInfo/MeasureVoltageAndResistance.hpp
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,8 @@
16
16
*
17
17
* This program is distributed in the hope that it will be useful,
18
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
-
* GNU General Public License for more details.
19
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
+
* See the GNU General Public License for more details.
21
21
*
22
22
* You should have received a copy of the GNU General Public License
23
23
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
@@ -79,7 +79,7 @@
79
79
#defineRESISTOR_3_PIN A3
80
80
81
81
#if !defined(ADC_INTERNAL_REFERENCE_MILLIVOLT)
82
-
#defineADC_INTERNAL_REFERENCE_MILLIVOLT1100L//can be adjusted by measuring the voltage at the AREF pin
82
+
#defineADC_INTERNAL_REFERENCE_MILLIVOLT1100L//Change to value measured at the AREF pin. If value > real AREF voltage, measured values are > real values
0 commit comments