Added piezo disk connection detection #featureadd
- First implementation for #46
This commit is contained in:
parent
2e4cf0ce58
commit
881940c217
7 changed files with 67 additions and 1 deletions
|
|
@ -112,6 +112,7 @@ void setup() {
|
||||||
|
|
||||||
pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT
|
pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT
|
||||||
pinMode(ERR_LED, OUTPUT);
|
pinMode(ERR_LED, OUTPUT);
|
||||||
|
pinMode(PZDET_PIN, INPUT);
|
||||||
pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup
|
pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup
|
||||||
pinMode(V_FOLLOW_PIN, INPUT);
|
pinMode(V_FOLLOW_PIN, INPUT);
|
||||||
pinMode(VCOMP_SENSE_PIN, INPUT);
|
pinMode(VCOMP_SENSE_PIN, INPUT);
|
||||||
|
|
@ -171,6 +172,9 @@ void loop() {
|
||||||
ERR_STATE = 0;
|
ERR_STATE = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the piezo disk is properly connected
|
||||||
|
pzConCheck();
|
||||||
|
|
||||||
// Blink LED's on init
|
// Blink LED's on init
|
||||||
if (BlinkCount > 0) {
|
if (BlinkCount > 0) {
|
||||||
BlinkState = !BlinkState;
|
BlinkState = !BlinkState;
|
||||||
|
|
|
||||||
|
|
@ -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 TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms
|
||||||
int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements
|
int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements
|
||||||
bool LOGIC = LOGIC_DEFAULT; // Trigger output logic (active low or active high)
|
bool LOGIC = LOGIC_DEFAULT; // Trigger output logic (active low or active high)
|
||||||
|
bool PZDET = PZDET_DEFAULT; // Enable/disable piezo connection detection
|
||||||
int Debug = 0;
|
int Debug = 0;
|
||||||
long voltMeterConstant = VM_CONST_DEFAULT;
|
long voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
uint8_t pP_i2c_address = 0xa0;
|
uint8_t pP_i2c_address = 0xa0;
|
||||||
|
|
@ -25,6 +26,7 @@ void eraseEEPROM() {
|
||||||
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR);
|
||||||
EEPROM.put(HYST_ADDRESS, Hyst);
|
EEPROM.put(HYST_ADDRESS, Hyst);
|
||||||
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
EEPROM.put(LOGIC_ADDRESS, LOGIC);
|
||||||
|
EEPROM.put(PZDET_ADDRESS, PZDET);
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,6 +85,13 @@ void restoreConfig() {
|
||||||
LOGIC = temp;
|
LOGIC = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EEPROM.get(PZDET_ADDRESS, temp);
|
||||||
|
if (temp < 0 || temp > 1) {
|
||||||
|
erase = true;
|
||||||
|
} else {
|
||||||
|
PZDET = temp;
|
||||||
|
}
|
||||||
|
|
||||||
long longTemp;
|
long longTemp;
|
||||||
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
EEPROM.get(VM_CONST_ADDRESS, longTemp);
|
||||||
if (longTemp < 1000000L || longTemp > 1200000L) {
|
if (longTemp < 1000000L || longTemp > 1200000L) {
|
||||||
|
|
@ -107,6 +116,7 @@ void setDefaultConfig() {
|
||||||
TRG_DUR = TRG_DUR_DEFAULT;
|
TRG_DUR = TRG_DUR_DEFAULT;
|
||||||
Hyst = HYST_DEFAULT;
|
Hyst = HYST_DEFAULT;
|
||||||
LOGIC = LOGIC_DEFAULT;
|
LOGIC = LOGIC_DEFAULT;
|
||||||
|
PZDET = PZDET_DEFAULT;
|
||||||
voltMeterConstant = VM_CONST_DEFAULT;
|
voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
adjustComp();
|
adjustComp();
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,12 @@
|
||||||
extern bool LOGIC; // Trigger logic scheme, Active LOW is default
|
extern bool LOGIC; // Trigger logic scheme, Active LOW is default
|
||||||
#endif
|
#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))
|
#if !(defined(Debug))
|
||||||
extern int Debug;
|
extern int Debug;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -174,3 +174,15 @@ void checkError () {
|
||||||
digitalWriteFast(ERR_LED, BlinkState);
|
digitalWriteFast(ERR_LED, BlinkState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
||||||
|
void pzConCheck () {
|
||||||
|
PZ_STATE = digitalRead(PZDET_PIN)
|
||||||
|
if (PZ_STATE == 1) {
|
||||||
|
digitalWriteFast(TRG_OUT, LOGIC);
|
||||||
|
ERR_STATE = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------*/
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,5 @@ Default pins (based on Rev.2.x.xPCB layout)
|
||||||
#define GADJ_R2 5 // "
|
#define GADJ_R2 5 // "
|
||||||
#define GADJ_R3 6 // "
|
#define GADJ_R3 6 // "
|
||||||
#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment
|
#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
|
||||||
|
|
@ -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() {
|
void updateConstant() {
|
||||||
if (serialLong >= 0) {
|
if (serialLong >= 0) {
|
||||||
voltMeterConstant = (long) serialLong;
|
voltMeterConstant = (long) serialLong;
|
||||||
|
|
@ -168,6 +184,12 @@ void serialPrintConfig() {
|
||||||
Serial.print("HYST ");
|
Serial.print("HYST ");
|
||||||
Serial.println(Hyst);
|
Serial.println(Hyst);
|
||||||
|
|
||||||
|
Serial.print("LOGIC ");
|
||||||
|
Serial.println(LOGIC);
|
||||||
|
|
||||||
|
Serial.print("PZDET ");
|
||||||
|
Serial.println(PZDET);
|
||||||
|
|
||||||
Serial.print("VM_CONST ");
|
Serial.print("VM_CONST ");
|
||||||
Serial.println(voltMeterConstant);
|
Serial.println(voltMeterConstant);
|
||||||
}
|
}
|
||||||
|
|
@ -190,6 +212,9 @@ void serialPrintState() {
|
||||||
Serial.print("\"Err\":");
|
Serial.print("\"Err\":");
|
||||||
Serial.print(ERR_STATE);
|
Serial.print(ERR_STATE);
|
||||||
|
|
||||||
|
Serial.print("\"PzCon\":");
|
||||||
|
Serial.print(PZ_STATE);
|
||||||
|
|
||||||
Serial.println("}");
|
Serial.println("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,6 +238,12 @@ void updateParams() {
|
||||||
else if (strcmp(serialMessageIn, "HYST") == 0) {
|
else if (strcmp(serialMessageIn, "HYST") == 0) {
|
||||||
updateHysteresis();
|
updateHysteresis();
|
||||||
}
|
}
|
||||||
|
else if (strcmp(serialMessageIn, "LOGIC") == 0) {
|
||||||
|
updateLogic();
|
||||||
|
}
|
||||||
|
else if (strcmp(serialMessageIn, "PZDET") == 0) {
|
||||||
|
updatePzDet();
|
||||||
|
}
|
||||||
else if (strcmp(serialMessageIn, "CONST") == 0) {
|
else if (strcmp(serialMessageIn, "CONST") == 0) {
|
||||||
updateConstant();
|
updateConstant();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_FOLLOW = 0; // Variable for Follower adjustment
|
||||||
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
|
volatile int ADJ_COMP = 0; // Variable for Comparator adjustment
|
||||||
volatile int ERR_STATE = 0;
|
volatile int ERR_STATE = 0;
|
||||||
|
volatile int PZ_STATE = 0;
|
||||||
|
|
||||||
int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000)
|
int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000)
|
||||||
int VOld = 5000; // Variable to store previous cycle's Vin
|
int VOld = 5000; // Variable to store previous cycle's Vin
|
||||||
|
|
@ -26,6 +27,7 @@ int VFol = 0;
|
||||||
int BlinkState = 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
|
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
|
// Serial Input Parsing Variables
|
||||||
#define buffSize 40
|
#define buffSize 40
|
||||||
char inputBuffer[buffSize];
|
char inputBuffer[buffSize];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue