diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino index d76892e..5052206 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino @@ -33,10 +33,10 @@ To change trigger active duration: TRG_D [integer for milliseconds] To change gain factor: GAIN_F [integer for gain state - see note*] -To change sensor input pullup vRef high threshold: VADJH [float value] -To change sensor input pullup vRef low threshold: VADJL [float value] -To change comparator trigger high threshold: VCOMPH [float value] -To change comparator trigger high threshold: VCOMPL [float value] +To change ADC hysteresis value: HYST [integer] +To change sensor input pullup vRef low threshold: VADJ [float value] +To change comparator trigger high threshold: VCOMP [float value] + These commands should be wrapped in this format: @@ -45,7 +45,7 @@ You must include the unused variable for each instance. Examples: - + *Note for Gain Factor: The gain STATE is representative of these values: @@ -62,13 +62,13 @@ The gain STATE is representative of these values: int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x int InitCount = 6; // Number of times to blink the LED on start int TRG_DUR = 120; // duration of the Z-axis pulse sent, in ms -#define senseThrs 2.15 +#define senseThrs 2.45 //float senseHighThrs = 2.35; // Upper threshold of Voltage Follower before adjustment //float senseLowThrs = 1.8; // Lower threshold of Voltage Follower before adjustment -#define compThrs 2.75 +#define compThrs 3.15 //float compHighThrs = 2.75; // Upper threshold of Comparator before adjustment //float compLowThrs = 2.54; // Lower threshold of Comparator before adjustment -int Hyst = 20; // Hysteresis value for ADC measurements +int Hyst = 17; // Hysteresis value for ADC measurements int Vin = 5; // input reference voltage // Analog Pin Assignments @@ -163,6 +163,7 @@ void setup() { void pulse() { digitalWrite(TRG_OUT, LOW); sensorHReading = 1; + delay(TRG_DUR); } /*------------------------------------------------*/ @@ -172,10 +173,10 @@ void adjustFollow() { if positive, adjusts the follower to within the range set above*/ if (diffAdjL > 0.0) { - ADJ_FOLLOW += (diffAdjL / 4) ; + ADJ_FOLLOW += diffAdjL; } if (diffAdjH > 0.0) { - ADJ_FOLLOW -= (diffAdjH / 4); + ADJ_FOLLOW -= diffAdjH; } // Analog output (PWM) of duty cycle @@ -186,11 +187,11 @@ void adjustFollow() { void adjustComp() { if (diffCompL > 0.0) { - ADJ_COMP += (diffCompL / 4); + ADJ_COMP += diffCompL; } if (diffCompH > 0.0) { - ADJ_COMP -= (diffCompH / 4); + ADJ_COMP -= diffCompH; } analogWrite(VCOMP_PWM, ADJ_COMP); @@ -376,6 +377,9 @@ void updateParams() { //if (strcmp(serialMessageIn, "VADJL") == 0) { // updateVAdjL(); //} + if (strcmp(serialMessageIn, "HYST") == 0) { + updateHysteresis(); + } } /*------------------------------------------------*/ @@ -435,23 +439,45 @@ void updateVAdjL() { } *------------------------------------------------*/ +void updateHysteresis() { + if (serialInt >= 0) { + Hyst = serialInt; + } +} +/*------------------------------------------------*/ + void serialReply() { if (serialIncoming) { - serialIncoming = false; - Serial.print("PZ Status:"); - Serial.println(sensorHReading); - Serial.print("Voltage Reference:"); - Serial.print(VComp); - Serial.print(" "); - //Serial.println(VCompRef,2); - Serial.print("Amp Sense:"); - Serial.print(VAdj); - Serial.print(" "); - //Serial.println(vAdjRead,2); - Serial.print("Comparator State:"); - Serial.println(ADJ_COMP); - Serial.print("Follower State:"); - Serial.println(ADJ_FOLLOW); + serialIncoming = false; + + Serial.print("Comp Reference:"); + Serial.print(VComp); + Serial.print(" "); + Serial.print("Comparator State:"); + Serial.print(ADJ_COMP); + Serial.print(" "); + Serial.println(compInt); + + Serial.print("Diff"); + Serial.print(" "); + Serial.print(diffCompL); + Serial.print(" "); + Serial.println(diffCompH); + + Serial.print("Amp Sense:"); + Serial.print(VAdj); + Serial.print(" "); + Serial.print("Follower State:"); + Serial.print(ADJ_FOLLOW); + Serial.print(" "); + Serial.println(senseInt); + + Serial.print("Diff"); + Serial.print(" "); + Serial.print(diffAdjL); + Serial.print(" "); + Serial.println(diffAdjH); + Serial.print("Delay:"); Serial.println(TRG_DUR); Serial.print("Error State:"); @@ -473,11 +499,11 @@ void loop() { // Blink LED's on init if (BlinkCount > 0) { - BlinkState = !BlinkState; - digitalWrite(ERR_LED, BlinkState); - digitalWrite(TRG_OUT, BlinkState); - delay(TRG_DUR); - --BlinkCount; + BlinkState = !BlinkState; + digitalWrite(ERR_LED, BlinkState); + digitalWrite(TRG_OUT, BlinkState); + delay(TRG_DUR); + --BlinkCount; } // Get Serial Input @@ -488,15 +514,15 @@ void loop() { // Check voltage of first and second stages and compare against thresholds VComp = analogRead(VCOMP_SENSE_PIN); - diffCompL = (VComp - compInt) - Hyst; - diffCompH = (compInt - VComp) - Hyst; + diffCompL = ((VComp - compInt) / 4) - Hyst; + diffCompH = ((compInt - VComp) / 4) - Hyst; //diffCompL = VComp - compLowInt; //diffCompH = compHighInt - VComp; //VCompRef = (VComp * 5) / 1024; VAdj = analogRead(V_FOLLOW_PIN); - diffAdjL = (VAdj - senseInt) - Hyst; - diffAdjH = (senseInt - VAdj) - Hyst; + diffAdjL = ((VAdj - senseInt) / 4) - Hyst; + diffAdjH = ((senseInt - VAdj) / 4) - Hyst; //diffAdjL = VAdj - senseLowInt; //diffAdjH = senseHighInt - VAdj; //vAdjRead = (VAdj * 5) / 1024;