From cdae15c99ad3cdacc3209cb60f7fafbb7c123b3c Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Tue, 24 Sep 2019 14:40:55 -0700 Subject: [PATCH 1/3] Fixed serial input updating the wrong variable #bugfix --- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h index 4adca89..3c6b1a5 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h @@ -89,7 +89,7 @@ void updateVComp() { void updateVAdj() { if (serialInt >= 0) { - senseInt = serialInt; + senseThrs = serialInt; //compInt = senseInt; // syncing these params til #24 is fixed } } From 2bbc20ff4db69ab9eeacec7e10a45ebb6abbf3bf Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Tue, 24 Sep 2019 19:33:22 -0700 Subject: [PATCH 2/3] added explaination on how to fine-tune VccMeter. #changelog Reshuffled some of the other parts of the readVcc function moved MUX setup to the void setup function --- .../Pyr0_Piezo_Sensor_v2.x.x.ino | 14 ++++++++++ .../Pyr0_Piezo_Sensor_v2.x.x/pP_config.h | 2 +- .../Pyr0_Piezo_Sensor_v2.x.x/pP_function.h | 27 ++++++++++--------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino index 7ca9956..13f5350 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino @@ -87,6 +87,20 @@ 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..."); } diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h index 4b0e5c3..d93a69e 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h @@ -32,7 +32,7 @@ long voltMeterConstant = 1125300L; // For fine tuning input voltage sense #endif -#ifdef I2C +#ifdef I2C_INPUT #if !(defined(pP_i2c_address)) byte pP_i2c_address = 0xa0; // I2C Bus Address #endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h index 80a9f80..2e82b1c 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h @@ -25,18 +25,6 @@ void pulse() { long readVcc() { // Read 1.1V reference against AVcc - // 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 @@ -49,6 +37,21 @@ long readVcc() { return result; // Vcc in millivolts } +/* The above function assumes an "ideal" multiplier constant. +Each Atmega chip is slightly different, so it won't be completely accurate +without tuning. Most of the time this won't be necessary, so don't mess +with this if you don't know what you're doing! +The reading can be fine-tuned by using a multimeter, and this equasion: + +scale_constant = internal1.1Ref * 1023 * 1000 + +where + +internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) + +If the scale_constant calculated is different from the default 1125300, +update the voltMeterConstant variable in pP_config.h with the correct value*/ + /*------------------------------------------------*/ void adjustVin() { From 40b20c06701c4e4709961d153f5a9da8f45d9daf Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 09:47:14 -0700 Subject: [PATCH 3/3] fixed typo #changelog --- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h index b625a1c..f534f95 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h @@ -44,7 +44,7 @@ long readVcc() { Each Atmega chip is slightly different, so it won't be completely accurate without tuning. Most of the time this won't be necessary, so don't mess with this if you don't know what you're doing! -The reading can be fine-tuned by using a multimeter, and this equasion: +The reading can be fine-tuned by using a multimeter, and this equation: scale_constant = internal1.1Ref * 1023 * 1000