Skip to content

Commit

Permalink
fixed logic and pzdet inputs #bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
pyr0ball committed Dec 31, 2019
1 parent d903a8a commit c30905b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 114 deletions.
Expand Up @@ -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);
Expand Down
111 changes: 2 additions & 109 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Expand Up @@ -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();
}
13 changes: 11 additions & 2 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h
Expand Up @@ -112,15 +112,15 @@ void updateHysteresis() {

void updateLogic() {
if (serialLong >= 0) {
Hyst = serialLong;
LOGIC = serialLong;
EEPROM.put(LOGIC_ADDRESS, LOGIC);
}
}
/*------------------------------------------------*/

void updatePzDet() {
if (serialLong >= 0) {
Hyst = serialLong;
PZDET = serialLong;
EEPROM.put(PZDET_ADDRESS, PZDET);
}
}
Expand Down

0 comments on commit c30905b

Please sign in to comment.