From 56c06008d4f7463a284561b5d0a337b573caa5e8 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Fri, 19 Jul 2019 15:04:01 -0700 Subject: [PATCH] Migrated configs to separate header file, made adjustment to definition --- .../Pyr0_Piezo_Sensor_v2.x.x.ino | 15 ++----- .../Pyr0_Piezo_Sensor_v2.x.x/pP_config.h | 41 +++++++++++++++++++ .../Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h | 10 +++-- 3 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h 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 9fe39a2..7ca9956 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 @@ -54,16 +54,6 @@ The gain STATE is representative of these values: 4 = 11x */ -// Configurable settings: -int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x -#define InitCount 6 // Number of times to blink the LED on start -int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions -int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms -#define senseThrs 1450 -#define compThrs 2850 -int Hyst = 20; // Hysteresis value for ADC measurements -long voltMeterConstant = 1125300L; // For fine tuning input voltage sense - /*------------------------------------------------------------*/ // Debug output toggle. Uncomment to enable @@ -76,12 +66,13 @@ long voltMeterConstant = 1125300L; // For fine tuning input voltage sense // Headers, variables, and functions #include "LightChrono.h" #include "pP_pins.h" +#include "pP_config.h" #include "pP_volatile.h" #include "pP_function.h" #include "pP_serial.h" // i2c input toggle. Uncomment to enable -#define I2C true +//#define I2C_INPUT true void setup() { pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT @@ -103,7 +94,7 @@ void setup() { /*------------------------------------------------*/ void loop() { - if (mainLoop.haspassed(LOOP_DUR)) { + if (mainLoop.hasPassed(LOOP_DUR)) { mainLoop.restart(); // Blink LED's on init if (BlinkCount > 0) { diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h new file mode 100644 index 0000000..4b0e5c3 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h @@ -0,0 +1,41 @@ +// Configurable settings: + +#if !(defined(GAIN_FACTOR)) + int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +#endif + +#ifndef senseThrs + #define senseThrs 1450 +#endif + +#ifndef compThrs + #define compThrs 2850 +#endif + +#ifndef InitCount + #define InitCount 6 // Number of times to blink the LED on start +#endif + +#if !(defined(LOOP_DUR)) + int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions +#endif + +#if !(defined(TRG_DUR)) + int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms +#endif + +#if !(defined(Hyst)) + int Hyst = 20; // Hysteresis value for ADC measurements +#endif + +#if !(defined(voldMeterConstant)) + long voltMeterConstant = 1125300L; // For fine tuning input voltage sense +#endif + +#ifdef I2C + #if !(defined(pP_i2c_address)) + byte pP_i2c_address = 0xa0; // I2C Bus Address + #endif +#endif + + diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h index a5a78f8..e266170 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h @@ -9,10 +9,11 @@ int VOld = 5000; // Variable to store previous cycle's Vin int VLast = 0; // Convert threshold values based on the input voltage + long senseLong = senseThrs * 1024L; long compLong = compThrs * 1024L; -long senseInt = senseLong / Vin; -long compInt = compLong / Vin; +long senseInt; +long compInt; // Voltage Comparator Adjustment parameters int VComp = 0; @@ -25,6 +26,7 @@ int diffAdjL = VAdj - senseInt; int diffAdjH = senseInt - VAdj; // Error blink parameters + int BlinkState = LOW; int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle toggle state @@ -39,8 +41,8 @@ bool serialIncoming = false; char serialMessageIn[buffSize] = {0}; int serialInt = 0; -#define LOW 0 -#define HIGH 1 +//#define LOW 0 +//#define HIGH 1 // Task scheduler instances LightChrono mainLoop;