11//
22// FILE: ACS712.cpp
33// AUTHOR: Rob Tillaart, Pete Thompson
4- // VERSION: 0.3.1
4+ // VERSION: 0.3.2
55// DATE: 2020-08-02
66// PURPOSE: ACS712 library - current measurement
7- //
8- // HISTORY:
9- // 0.1.0 2020-03-17 initial version
10- // 0.1.1 2020-03-18 first release version
11- // 0.1.2 2020-03-21 automatic form factor test
12- // 0.1.3 2020-05-27 fix library.json
13- // 0.1.4 2020-08-02 Allow for faster processors
14- //
15- // 0.2.0 2020-08-02 Add autoMidPoint
16- // 0.2.1 2020-12-06 Add Arduino-CI + readme + unit test + refactor
17- // 0.2.2 2021-06-23 support for more frequencies.
18- // 0.2.3 2021-10-15 changed frequencies to float, for optimal tuning.
19- // updated build CI, readme.md
20- // 0.2.4 2021-11-22 add experimental detectFrequency()
21- // 0.2.5 2021-12-03 add timeout to detectFrequency()
22- // 0.2.6 2021-12-09 update readme.md + license
23- // 0.2.7 2022-08-10 change mVperAmp to float
24- // add ACS712_FF_SAWTOOTH
25- // update readme.md + unit test + minor edits
26- // 0.2.8 2022-08-19 prepare for 0.3.0
27- // Fix #21 FormFactor
28- // add mA_AC_sampling() as method to determine
29- // current when FormFactor is unknown.
30- // added float _AmperePerStep cached value.
31- // added getAmperePerStep();
32- // moved several functions to .cpp
33- // improve documentation
34- //
35- // 0.3.0 2022-09-01 return midPoint value in MP functions.
36- // float return type for mA() functions
37- // add float mA_peak2peak(freq, cycles)
38- // add debug getMinimum(), getmaximum();
39- // update Readme.md
40- // 0.3.1 2022-09-xx add float mVNoiseLevel(frequency, cycles)
41- // add void suppressNoise(bool flag)
42- // experimental suppression by averaging two samples.
43- // update readme.md
44- // improve midPoint functions
45- // add resetMidPoint()
46- // add RP2040 pico in build-ci
477
488
499#include " ACS712.h"
@@ -184,6 +144,7 @@ float ACS712::mA_AC_sampling(float frequency, uint16_t cycles)
184144 }
185145 float current = value - _midPoint;
186146 sumSquared += (current * current);
147+ // not adding noise squared might be more correct for small currents.
187148 // if (abs(current) > noiseLevel)
188149 // {
189150 // sumSquared += (current * current);
@@ -223,7 +184,7 @@ float ACS712::mA_DC(uint16_t cycles)
223184// CALIBRATION MIDPOINT
224185uint16_t ACS712::setMidPoint (uint16_t midPoint)
225186{
226- if (midPoint <= _maxADC) _midPoint = midPoint;
187+ if (midPoint <= _maxADC) _midPoint = ( int ) midPoint;
227188 return _midPoint;
228189};
229190
@@ -236,7 +197,7 @@ uint16_t ACS712::getMidPoint()
236197
237198uint16_t ACS712::incMidPoint ()
238199{
239- if (_midPoint < _maxADC) _midPoint += 1 ;
200+ if (_midPoint < ( int )( _maxADC) ) _midPoint += 1 ;
240201 return _midPoint;
241202};
242203
0 commit comments