Skip to content

Commit

Permalink
Added piezo disk connection detection #featureadd
Browse files Browse the repository at this point in the history
 - First implementation for #46
  • Loading branch information
pyr0ball committed Dec 28, 2019
1 parent 2e4cf0c commit 881940c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/*------------------------------------------------*/
3 changes: 2 additions & 1 deletion firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -190,6 +212,9 @@ void serialPrintState() {
Serial.print("\"Err\":");
Serial.print(ERR_STATE);

Serial.print("\"PzCon\":");
Serial.print(PZ_STATE);

Serial.println("}");
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down

1 comment on commit 881940c

@pyr0ball
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction, this was for #48

Please sign in to comment.