From c30905bd74cbeee65109ae18643ec04123abecbd Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Tue, 31 Dec 2019 15:30:21 -0800 Subject: [PATCH] fixed logic and pzdet inputs #bugfix --- .../src/Pyr0_Piezo_Sensor_V2.x.x.cpp | 2 +- .../src/pP_config.cpp | 111 +----------------- .../src/pP_function.h | 13 +- .../Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h | 4 +- 4 files changed, 16 insertions(+), 114 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 c50d32e..d13015c 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 @@ -112,7 +112,7 @@ void setup() { pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT pinMode(ERR_LED, OUTPUT); - pinMode(PZDET_PIN, INPUT); + pinMode(PZDET_PIN, INPUT_PULLUP); pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup pinMode(V_FOLLOW_PIN, INPUT); pinMode(VCOMP_SENSE_PIN, INPUT); diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp index c8796a1..2703ca5 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp @@ -9,115 +9,8 @@ int compThrs = COMP_THRESHOLD_DEFAULT; int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and other loop functions int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements -bool LOGIC = LOGIC_DEFAULT; // Trigger output logic (active low or active high) -bool PZDET = PZDET_DEFAULT; // Enable/disable piezo connection detection +int LOGIC = LOGIC_DEFAULT; // Trigger output logic (active low or active high) +int PZDET = PZDET_DEFAULT; // Enable/disable piezo connection detection int Debug = 0; long voltMeterConstant = VM_CONST_DEFAULT; uint8_t pP_i2c_address = 0xa0; - -void eraseEEPROM() { - - setDefaultConfig(); - - EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); - EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); - EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); - EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); - EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); - EEPROM.put(HYST_ADDRESS, Hyst); - EEPROM.put(LOGIC_ADDRESS, LOGIC); - EEPROM.put(PZDET_ADDRESS, PZDET); - EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant); -} - -// Restore config from EEPROM, otherwise erase config and write to EEPROM -void restoreConfig() { - int temp; - - bool erase = false; - - EEPROM.get(GAIN_FACTOR_ADDRESS, temp); - if (temp < 0 || temp > 4) { - erase = true; - } else { - GAIN_FACTOR = temp; - } - - EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) { - erase = true; - } else { - followerThrs = temp; - } - - EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) { - erase = true; - } else { - compThrs = temp; - } - - EEPROM.get(LOOP_DUR_ADDRESS, temp); - if (temp < 0 && temp > 1000) { - erase = true; - } else { - LOOP_DUR = temp; - } - - EEPROM.get(TRG_DUR_ADDRESS, temp); - if (temp < 0 || temp > 1000) { - erase = true; - } else { - TRG_DUR = temp; - } - - EEPROM.get(HYST_ADDRESS, temp); - if (temp < 0 || temp > 1000) { - erase = true; - } else { - Hyst = temp; - } - - EEPROM.get(LOGIC_ADDRESS, temp); - if (temp < 0 || temp > 1) { - erase = true; - } else { - LOGIC = temp; - } - - EEPROM.get(PZDET_ADDRESS, temp); - if (temp < 0 || temp > 1) { - erase = true; - } else { - PZDET = temp; - } - - long longTemp; - EEPROM.get(VM_CONST_ADDRESS, longTemp); - if (longTemp < 1000000L || longTemp > 1200000L) { - erase = true; - } else { - voltMeterConstant = longTemp; - } - - if (erase) { - eraseEEPROM(); - } - - adjustFollow(); - adjustComp(); -} - -void setDefaultConfig() { - GAIN_FACTOR = GAIN_FACTOR_DEFAULT; - followerThrs = FOLLOWER_THRESHOLD_DEFAULT; - compThrs = COMP_THRESHOLD_DEFAULT; - LOOP_DUR = LOOP_DUR_DEFAULT; - TRG_DUR = TRG_DUR_DEFAULT; - Hyst = HYST_DEFAULT; - LOGIC = LOGIC_DEFAULT; - PZDET = PZDET_DEFAULT; - voltMeterConstant = VM_CONST_DEFAULT; - adjustFollow(); - adjustComp(); -} 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 4d0e3a2..dd2fd54 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 @@ -178,8 +178,8 @@ void checkError () { /*------------------------------------------------*/ void pzConCheck () { - PZ_STATE = digitalRead(PZDET_PIN) - if (PZ_STATE == 1) { + PZ_STATE = digitalRead(PZDET_PIN); + if (PZ_STATE == PZDET) { digitalWriteFast(TRG_OUT, LOGIC); ERR_STATE = 1; } @@ -196,6 +196,7 @@ void eraseEEPROM() { EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); EEPROM.put(HYST_ADDRESS, Hyst); + EEPROM.put(PZDET_ADDRESS, PZDET); EEPROM.put(LOGIC_ADDRESS, LOGIC); EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant); } @@ -248,6 +249,13 @@ void restoreConfig() { Hyst = temp; } + EEPROM.get(PZDET_ADDRESS, temp); + if (temp < 0 || temp > 1) { + erase = true; + } else { + PZDET = temp; + } + EEPROM.get(LOGIC_ADDRESS, temp); if (temp < 0 || temp > 1) { erase = true; @@ -278,6 +286,7 @@ void setDefaultConfig() { LOOP_DUR = LOOP_DUR_DEFAULT; TRG_DUR = TRG_DUR_DEFAULT; Hyst = HYST_DEFAULT; + PZDET = PZDET_DEFAULT; LOGIC = LOGIC_DEFAULT; voltMeterConstant = VM_CONST_DEFAULT; adjustFollow(); diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h index 48598ed..23e5efd 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h @@ -112,7 +112,7 @@ void updateHysteresis() { void updateLogic() { if (serialLong >= 0) { - Hyst = serialLong; + LOGIC = serialLong; EEPROM.put(LOGIC_ADDRESS, LOGIC); } } @@ -120,7 +120,7 @@ void updateLogic() { void updatePzDet() { if (serialLong >= 0) { - Hyst = serialLong; + PZDET = serialLong; EEPROM.put(PZDET_ADDRESS, PZDET); } }