From eb052133a3e8ff98adfc93e52984e0c1b626b0d0 Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 15:42:45 -0400 Subject: [PATCH] =?UTF-8?q?Code=20change=20implements=20analogReadFast,=20?= =?UTF-8?q?which=20reduces=20the=20read=20time=20of=20an=20anolog=20pin=20?= =?UTF-8?q?from=20112=20=C2=B5S=20down=20to=2021=20=C2=B5S.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Pyr0_Piezo_Sensor_V2.x.x.cpp | 4 ++-- .../AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp index af37f29..26bddca 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp @@ -156,8 +156,8 @@ void loop() { // Check voltage of first and second stages and compare against thresholds readVin(); - VComp = analogRead(VCOMP_SENSE_PIN); - VFol = analogRead(V_FOLLOW_PIN); + VComp = analogReadFast(VCOMP_SENSE_PIN); + VFol = analogReadFast(V_FOLLOW_PIN); VLast = VOld - Vin; if (VLast > Hyst || VLast < -Hyst) { diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h index fdf588f..4395428 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h @@ -12,6 +12,14 @@ void digitalWriteFast(uint8_t pin, uint8_t x) { } } +int inline analogReadFast(byte ADCpin) +{ byte ADCSRAoriginal = ADCSRA; + ADCSRA = (ADCSRA & B11111000) | 4; + int adc = analogRead(ADCpin); + ADCSRA = ADCSRAoriginal; + return adc; +} + /*------------------------------------------------*/ void pulse() {