From e029364cdcea0ae07c5702dc48b4dc2b74cbba6d Mon Sep 17 00:00:00 2001 From: Vsevolod Merenkov Date: Mon, 30 Sep 2019 02:56:24 +0300 Subject: [PATCH] Reverted voltmeter code #bugfix --- .../src/Pyr0_Piezo_Sensor_V2.x.x.cpp | 20 +------------------ .../src/pP_function.h | 15 ++++++++++++++ 2 files changed, 16 insertions(+), 19 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 2cd9fa0..5c2813b 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 @@ -82,9 +82,6 @@ update the voltMeterConstant variable in pP_config.h with the correct value ------------------------------------------------------------*/ -// Debug output toggle. Uncomment to enable -#define DEBUG true - /* Debug output verbose mode will continuously output sensor readings rather than waiting for user input */ //#define VERBOSE true @@ -115,20 +112,6 @@ void setup() { Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING); - - // Atmega's Secret Voltmeter setup: - // set the reference to Vcc and the measurement to the internal 1.1V reference - #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); - #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - ADMUX = _BV(MUX5) | _BV(MUX0); - #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - ADMUX = _BV(MUX3) | _BV(MUX2); - #else - ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); - #endif - - delay(2); // Wait for vref to settle Serial.println("Initializing Pyr0-Piezo Sensor..."); @@ -166,11 +149,10 @@ void loop() { VComp = analogRead(VCOMP_SENSE_PIN); VFol = analogRead(V_FOLLOW_PIN); - // Voltage Follower adjustment VLast = VOld - Vin; if (VLast > Hyst || VLast < -Hyst) { + // Voltage Follower adjustment adjustFollow(); - // Voltage Comparator adjustment adjustComp(); // Alert the user that auto-calibration is ongoing 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 4c35da6..a1ef24d 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 @@ -28,6 +28,21 @@ void pulse() { long readVcc() { // Read 1.1V reference against AVcc + + // Atmega's Secret Voltmeter setup: + // set the reference to Vcc and the measurement to the internal 1.1V reference +#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); +#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + ADMUX = _BV(MUX5) | _BV(MUX0); +#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + ADMUX = _BV(MUX3) | _BV(MUX2); +#else + ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); +#endif + + delay(2); // Wait for vref to settle + ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring