diff --git a/ACS712.cpp b/ACS712.cpp index fb8dba7..1273a60 100644 --- a/ACS712.cpp +++ b/ACS712.cpp @@ -180,7 +180,10 @@ float ACS712::mA_DC(uint16_t cycles) value = (value + _analogRead(_pin))/2; } // for RTOS - if (i % 2 == 1) yield(); + if ((i & 0x0001) == 0x0001) // every 2nd iteration + { + yield(); + } sum += (value - _midPoint); } float mA = sum * _mAPerStep; diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f16961..43597ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [0.3.9] - 2024-01-11 -- add yield() in multiple reads to better support RTOS -- update readme.md (empty compatibility table) +- add yield() to improve the behaviour under RTOS +- update readme.md (add compatibility table). - minor edits diff --git a/README.md b/README.md index ffc3d8a..03f1bf3 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ This function is intended for signals with unknown Form Factor. - **float mA_DC(uint16_t samples = 1)** blocks < 1 ms (Arduino UNO) as it calls **analogRead()** twice. A negative value indicates the current flows in the opposite direction. - 0.2.8 the parameter samples allow to average over a number of samples. - - 0.3.9 calls yield() every 3 analogRead's to support RTOS (a bit). + - 0.3.9 calls yield() every 2nd iteration to improve behaviour under RTOS. #### mA_AC_sampling performance trick.