Added piezo disk connection detection #featureadd

- First implementation for #46
This commit is contained in:
pyr0ball 2019-12-28 03:32:10 -08:00
parent 2e4cf0ce58
commit 881940c217
7 changed files with 67 additions and 1 deletions

View file

@ -112,6 +112,7 @@ void setup() {
pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT
pinMode(ERR_LED, OUTPUT);
pinMode(PZDET_PIN, INPUT);
pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup
pinMode(V_FOLLOW_PIN, INPUT);
pinMode(VCOMP_SENSE_PIN, INPUT);
@ -171,6 +172,9 @@ void loop() {
ERR_STATE = 0;
}
// Check that the piezo disk is properly connected
pzConCheck();
// Blink LED's on init
if (BlinkCount > 0) {
BlinkState = !BlinkState;

View file

@ -10,6 +10,7 @@ int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and othe
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 Debug = 0;
long voltMeterConstant = VM_CONST_DEFAULT;
uint8_t pP_i2c_address = 0xa0;
@ -25,6 +26,7 @@ void eraseEEPROM() {
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);
}
@ -83,6 +85,13 @@ void restoreConfig() {
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) {
@ -107,6 +116,7 @@ void setDefaultConfig() {
TRG_DUR = TRG_DUR_DEFAULT;
Hyst = HYST_DEFAULT;
LOGIC = LOGIC_DEFAULT;
PZDET = PZDET_DEFAULT;
voltMeterConstant = VM_CONST_DEFAULT;
adjustFollow();
adjustComp();

View file

@ -49,6 +49,12 @@
extern bool LOGIC; // Trigger logic scheme, Active LOW is default
#endif
#define PZDET_DEFAULT 0
#define PZDET_ADDRESS 26
#if !(defined(PZDET))
extern bool PZDET; // Enable or disable piezo connection detection, default is off
#endif
#if !(defined(Debug))
extern int Debug;
#endif

View file

@ -174,3 +174,15 @@ void checkError () {
digitalWriteFast(ERR_LED, BlinkState);
}
}
/*------------------------------------------------*/
void pzConCheck () {
PZ_STATE = digitalRead(PZDET_PIN)
if (PZ_STATE == 1) {
digitalWriteFast(TRG_OUT, LOGIC);
ERR_STATE = 1;
}
}
/*------------------------------------------------*/

View file

@ -29,4 +29,5 @@ Default pins (based on Rev.2.x.xPCB layout)
#define GADJ_R2 5 // "
#define GADJ_R3 6 // "
#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment
#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment
#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment
#define PZDET_PIN 16 // Digital input pin for detecting piezo connection

View file

@ -110,6 +110,22 @@ void updateHysteresis() {
}
/*------------------------------------------------*/
void updateLogic() {
if (serialLong >= 0) {
Hyst = serialLong;
EEPROM.put(LOGIC_ADDRESS, LOGIC);
}
}
/*------------------------------------------------*/
void updatePzDet() {
if (serialLong >= 0) {
Hyst = serialLong;
EEPROM.put(PZDET_ADDRESS, PZDET);
}
}
/*------------------------------------------------*/
void updateConstant() {
if (serialLong >= 0) {
voltMeterConstant = (long) serialLong;
@ -168,6 +184,12 @@ void serialPrintConfig() {
Serial.print("HYST ");
Serial.println(Hyst);
Serial.print("LOGIC ");
Serial.println(LOGIC);
Serial.print("PZDET ");
Serial.println(PZDET);
Serial.print("VM_CONST ");
Serial.println(voltMeterConstant);
}
@ -190,6 +212,9 @@ void serialPrintState() {
Serial.print("\"Err\":");
Serial.print(ERR_STATE);
Serial.print("\"PzCon\":");
Serial.print(PZ_STATE);
Serial.println("}");
}
@ -213,6 +238,12 @@ void updateParams() {
else if (strcmp(serialMessageIn, "HYST") == 0) {
updateHysteresis();
}
else if (strcmp(serialMessageIn, "LOGIC") == 0) {
updateLogic();
}
else if (strcmp(serialMessageIn, "PZDET") == 0) {
updatePzDet();
}
else if (strcmp(serialMessageIn, "CONST") == 0) {
updateConstant();
}

View file

@ -3,6 +3,7 @@ volatile int sensorHReading = 0; // variable to store the value read from t
volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
volatile int ERR_STATE = 0;
volatile int PZ_STATE = 0;
int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000)
int VOld = 5000; // Variable to store previous cycle's Vin
@ -26,6 +27,7 @@ int VFol = 0;
int BlinkState = 0;
int BlinkCount = (InitCount * 2) + 1; // Multiply Blink count by 2 to handle toggle state, add one extra to make sure light is on after
// Serial Input Parsing Variables
#define buffSize 40
char inputBuffer[buffSize];