fixed logic and pzdet inputs #bugfix
This commit is contained in:
parent
d903a8a4f3
commit
c30905bd74
4 changed files with 16 additions and 114 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue