|
| 1 | +// |
| 2 | +// FILE: ACS712_20_AC_midPoint_performance.ino |
| 3 | +// AUTHOR: Rob Tillaart |
| 4 | +// PURPOSE: demo to compare different midPoint methods. |
| 5 | +// URL: https://github.com/RobTillaart/ACS712 |
| 6 | + |
| 7 | + |
| 8 | +#include "ACS712.h" |
| 9 | + |
| 10 | + |
| 11 | +// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps |
| 12 | +// ACS712 5A uses 185 mV per A |
| 13 | +// ACS712 20A uses 100 mV per A |
| 14 | +// ACS712 30A uses 66 mV per A |
| 15 | + |
| 16 | + |
| 17 | +ACS712 ACS(A0, 5.0, 1023, 100); |
| 18 | +// ESP 32 example (might requires resistors to step down the logic voltage) |
| 19 | +// ACS712 ACS(25, 3.3, 4095, 185); |
| 20 | + |
| 21 | +uint32_t start, stop; |
| 22 | + |
| 23 | +float mp = 0; |
| 24 | + |
| 25 | + |
| 26 | +void setup() |
| 27 | +{ |
| 28 | + Serial.begin(115200); |
| 29 | + while (!Serial); |
| 30 | + Serial.println(__FILE__); |
| 31 | + Serial.println(); |
| 32 | + Serial.print("ACS712_LIB_VERSION: "); |
| 33 | + Serial.println(ACS712_LIB_VERSION); |
| 34 | + |
| 35 | + Serial.println("Compare different midPoint methods.\n"); |
| 36 | + |
| 37 | + start = micros(); |
| 38 | + mp = ACS.getMidPoint(); |
| 39 | + stop = micros(); |
| 40 | + Serial.print("Default: \t"); |
| 41 | + Serial.print(mp); |
| 42 | + Serial.print("\t"); |
| 43 | + Serial.println(stop - start); |
| 44 | + delay(10); |
| 45 | + |
| 46 | + start = micros(); |
| 47 | + mp = ACS.autoMidPoint(); |
| 48 | + stop = micros(); |
| 49 | + Serial.print("AutoMP: \t"); |
| 50 | + Serial.print(mp); |
| 51 | + Serial.print("\t"); |
| 52 | + Serial.println(stop - start); |
| 53 | + delay(10); |
| 54 | + |
| 55 | + start = micros(); |
| 56 | + uint16_t average = (ACS.getMinimum(20) + ACS.getMaximum(20)) / 2; |
| 57 | + stop = micros(); |
| 58 | + Serial.print("Average: \t"); |
| 59 | + Serial.print(average); |
| 60 | + Serial.print("\t"); |
| 61 | + Serial.println(stop - start); |
| 62 | + delay(10); |
| 63 | + |
| 64 | + Serial.println("\ndone..."); |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +void loop() |
| 69 | +{ |
| 70 | + delay(1000); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +// -- END OF FILE -- |
0 commit comments