0.3.2 ACS712

This commit is contained in:
rob tillaart 2022-11-21 20:44:08 +01:00
parent df229d7bb7
commit 38d797b858
8 changed files with 107 additions and 53 deletions

View File

@ -24,4 +24,5 @@ compile:
- esp32
- esp8266
# - mega2560
- rpipico
- rpipico

View File

@ -1,49 +1,9 @@
//
// FILE: ACS712.cpp
// AUTHOR: Rob Tillaart, Pete Thompson
// VERSION: 0.3.1
// VERSION: 0.3.2
// DATE: 2020-08-02
// PURPOSE: ACS712 library - current measurement
//
// HISTORY:
// 0.1.0 2020-03-17 initial version
// 0.1.1 2020-03-18 first release version
// 0.1.2 2020-03-21 automatic form factor test
// 0.1.3 2020-05-27 fix library.json
// 0.1.4 2020-08-02 Allow for faster processors
//
// 0.2.0 2020-08-02 Add autoMidPoint
// 0.2.1 2020-12-06 Add Arduino-CI + readme + unit test + refactor
// 0.2.2 2021-06-23 support for more frequencies.
// 0.2.3 2021-10-15 changed frequencies to float, for optimal tuning.
// updated build CI, readme.md
// 0.2.4 2021-11-22 add experimental detectFrequency()
// 0.2.5 2021-12-03 add timeout to detectFrequency()
// 0.2.6 2021-12-09 update readme.md + license
// 0.2.7 2022-08-10 change mVperAmp to float
// add ACS712_FF_SAWTOOTH
// update readme.md + unit test + minor edits
// 0.2.8 2022-08-19 prepare for 0.3.0
// Fix #21 FormFactor
// add mA_AC_sampling() as method to determine
// current when FormFactor is unknown.
// added float _AmperePerStep cached value.
// added getAmperePerStep();
// moved several functions to .cpp
// improve documentation
//
// 0.3.0 2022-09-01 return midPoint value in MP functions.
// float return type for mA() functions
// add float mA_peak2peak(freq, cycles)
// add debug getMinimum(), getmaximum();
// update Readme.md
// 0.3.1 2022-09-xx add float mVNoiseLevel(frequency, cycles)
// add void suppressNoise(bool flag)
// experimental suppression by averaging two samples.
// update readme.md
// improve midPoint functions
// add resetMidPoint()
// add RP2040 pico in build-ci
#include "ACS712.h"
@ -184,6 +144,7 @@ float ACS712::mA_AC_sampling(float frequency, uint16_t cycles)
}
float current = value - _midPoint;
sumSquared += (current * current);
// not adding noise squared might be more correct for small currents.
// if (abs(current) > noiseLevel)
// {
// sumSquared += (current * current);
@ -223,7 +184,7 @@ float ACS712::mA_DC(uint16_t cycles)
// CALIBRATION MIDPOINT
uint16_t ACS712::setMidPoint(uint16_t midPoint)
{
if (midPoint <= _maxADC) _midPoint = midPoint;
if (midPoint <= _maxADC) _midPoint = (int) midPoint;
return _midPoint;
};
@ -236,7 +197,7 @@ uint16_t ACS712::getMidPoint()
uint16_t ACS712::incMidPoint()
{
if (_midPoint < _maxADC) _midPoint += 1;
if (_midPoint < (int)(_maxADC)) _midPoint += 1;
return _midPoint;
};

View File

@ -2,7 +2,7 @@
//
// FILE: ACS712.h
// AUTHOR: Rob Tillaart, Pete Thompson
// VERSION: 0.3.1
// VERSION: 0.3.2
// DATE: 2020-08-02
// PURPOSE: ACS712 library - current measurement
//
@ -12,7 +12,7 @@
#include "Arduino.h"
#define ACS712_LIB_VERSION (F("0.3.1"))
#define ACS712_LIB_VERSION (F("0.3.2"))
// ACS712_FF_SINUS == 1.0/sqrt(2) == 0.5 * sqrt(2)
@ -111,7 +111,7 @@ class ACS712
float _formFactor; // peak2peak -> RMS
float _mVperAmpere;
float _mAPerStep;
uint16_t _midPoint;
int _midPoint;
uint8_t _noisemV;
float _microsAdjust = 1.0; // 0.9986
bool _suppresNoise = false;

View File

@ -0,0 +1,88 @@
# Change Log AD520X
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.2] - 2022-11-18
- fix #26 revert data type \_midPoint to int
- Add CHANGELOG.md
## [0.3.1 2022-09-xx
- add float mVNoiseLevel(frequency, cycles)
- add void suppressNoise(bool flag) - experimental suppression by averaging two samples.
- update readme.md
- improve midPoint functions
- add resetMidPoint()
- add RP2040 pico in build-ci
## [0.3.0] - 2022-09-01
- return midPoint value in MP functions.
- float return type for mA() functions
- add float mA_peak2peak(freq, cycles)
- add debug getMinimum(), getmaximum();
- update Readme.md
----
## [0.2.8] - 2022-08-19 prepare for 0.3.0
- Fix #21 FormFactor
- add mA_AC_sampling() as method to determine
- current when FormFactor is unknown.
- added float _AmperePerStep cached value.
- added getAmperePerStep();
- moved several functions to .cpp
- improve documentation
## [0.2.7] - 2022-08-10
- change mVperAmp to float
- add ACS712_FF_SAWTOOTH
- update readme.md + unit test + minor edits
## [0.2.6] - 2021-12-09
- update readme.md
- update license
## [0.2.5] - 2021-12-03
- add timeout to detectFrequency()
## [0.2.4] - 2021-11-22
- add experimental detectFrequency()
## [0.2.3] - 2021-10-15
- change frequencies to float, for optimal tuning.
- update build CI
- update readme.md
## [0.2.2] - 2021-06-23
- support for more frequencies
## [0.2.1] - 2020-12-06
- Add Arduino-CI + unit test
- update readme
- refactor
## [0.2.0] - 2020-08-02
- Add autoMidPoint()
----
## [0.1.4] - 2020-08-02
- Allow for faster processors
## [0.1.3] - 2020-05-27
- fix library.json
## [0.1.2] - 2020-03-21
- automatic form factor test
## [0.1.1] - 2020-03-18
- first release version
## [0.1.0] - 2020-03-17
- initial version

View File

@ -21,7 +21,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ACS712.git"
},
"version": "0.3.1",
"version": "0.3.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=ACS712
version=0.3.1
version=0.3.2
author=Rob Tillaart <rob.tillaart@gmail.com>, Pete Thompson <pete.thompson@yahoo.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=ACS712 library for Arduino.

View File

@ -147,10 +147,10 @@ The midpoint is the (raw) zero-reference for all current measurements.
It is defined in steps of the ADC and is typical around half the **maxADC** value defined
in the constructor. So for a 10 bit ADC a number between 500..525 is most likely.
Since 0.3.0 all midpoint functions return actual midPoint.
Since 0.3.0 all midpoint functions return the actual midPoint.
- **uint16_t setMidPoint(uint16_t midPoint)** sets midpoint for the ADC conversion.
Parameter must be between 0 and maxADC, otherwise midpoint is not changed.
Parameter must be between 0 and maxADC/2, otherwise midpoint is not changed.
- **uint16_t autoMidPoint(float frequency = 50, uint16_t cycles = 1)** Auto midPoint,
assuming zero DC current or any AC current.
The function takes the average of many measurements during one or more full cycles.
@ -176,7 +176,7 @@ One can use the two debug functions.
and take the average of these two values. In code:
```cpp
uint16_t midpnt = ACS.setMidPoint((ACS.getMinimum(20) + ACS.getMaximum(20)) / 2);
uint16_t midpoint = ACS.setMidPoint(ACS.getMinimum(20)/2 + ACS.getMaximum(20)/ 2);
```
See - ACS712_20_AC_midPoint_compare.ino
@ -343,7 +343,7 @@ The examples show the basic working of the functions.
#### Should - 0.3.x
- investigate noise suppression #21 (0.3.1 and later)
- external history file = changelog.md
- add external history file = changelog.md
#### Could

View File

@ -123,6 +123,10 @@ unittest(test_midPoint)
amp = ACS.getMidPoint();
assertEqual(1000, amp);
ACS.decMidPoint();
amp = ACS.getMidPoint();
assertEqual(999, amp);
ACS.resetMidPoint();
amp = ACS.getMidPoint();
assertEqual(511, amp);