actually added some of the changes intended for previous commit
This commit is contained in:
parent
9ce36b8607
commit
59387f8502
3 changed files with 68 additions and 32 deletions
|
|
@ -34,8 +34,8 @@
|
||||||
To change trigger active duration: TRG_D [integer for milliseconds]
|
To change trigger active duration: TRG_D [integer for milliseconds]
|
||||||
To change gain factor: GAIN_F [integer for gain state - see note*]
|
To change gain factor: GAIN_F [integer for gain state - see note*]
|
||||||
To change ADC hysteresis value: HYST [integer]
|
To change ADC hysteresis value: HYST [integer]
|
||||||
To change sensor input pullup vRef low threshold: VADJ [float value]
|
To change sensor input pullup vRef low threshold: VFOL [integer in millivolts]
|
||||||
To change comparator trigger high threshold: VCOMP [float value]
|
To change comparator trigger high threshold: VCOMP [integer in millivolts]
|
||||||
|
|
||||||
|
|
||||||
These commands should be wrapped in this format:
|
These commands should be wrapped in this format:
|
||||||
|
|
@ -43,7 +43,7 @@ These commands should be wrapped in this format:
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
<GAIN_F, 3> <~ set gain factor to index 3 (6x)
|
<GAIN_F, 3> <~ set gain factor to index 3 (6x)
|
||||||
<VADJ, 2350> <~ set the vref floor to 2.35V
|
<VFOL, 2350> <~ set the vref floor to 2.35V
|
||||||
|
|
||||||
*Note for Gain Factor:
|
*Note for Gain Factor:
|
||||||
The gain STATE is representative of these values:
|
The gain STATE is representative of these values:
|
||||||
|
|
@ -64,6 +64,7 @@ The gain STATE is representative of these values:
|
||||||
//#define VERBOSE true
|
//#define VERBOSE true
|
||||||
|
|
||||||
// Headers, variables, and functions
|
// Headers, variables, and functions
|
||||||
|
include <Arduino.h>
|
||||||
include <EEPROM.h>
|
include <EEPROM.h>
|
||||||
#include "LightChrono.h"
|
#include "LightChrono.h"
|
||||||
#include "pP_pins.h"
|
#include "pP_pins.h"
|
||||||
|
|
@ -104,6 +105,10 @@ void setup() {
|
||||||
delay(2); // Wait for vref to settle
|
delay(2); // Wait for vref to settle
|
||||||
|
|
||||||
Serial.println("Initializing Pyr0-Piezo Sensor...");
|
Serial.println("Initializing Pyr0-Piezo Sensor...");
|
||||||
|
|
||||||
|
restoreConfig();
|
||||||
|
|
||||||
|
adjustGain();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------*/
|
/*------------------------------------------------*/
|
||||||
|
|
@ -123,35 +128,46 @@ void loop() {
|
||||||
serialInput();
|
serialInput();
|
||||||
|
|
||||||
// Set any new parameters from serial input
|
// Set any new parameters from serial input
|
||||||
|
if (serialIncoming) {
|
||||||
updateParams();
|
updateParams();
|
||||||
|
}
|
||||||
|
|
||||||
// Set the amplification gain factor
|
// Set the amplification gain factor
|
||||||
adjustGain();
|
adjustGain();
|
||||||
|
|
||||||
// Check voltage of first and second stages and compare against thresholds
|
// Check voltage of first and second stages and compare against thresholds
|
||||||
adjustVin();
|
readVin();
|
||||||
VComp = analogRead(VCOMP_SENSE_PIN);
|
VComp = analogRead(VCOMP_SENSE_PIN);
|
||||||
VFol = analogRead(V_FOLLOW_PIN);
|
VFol = analogRead(V_FOLLOW_PIN);
|
||||||
|
|
||||||
// Voltage Follower adjustment
|
// Voltage Follower adjustment
|
||||||
|
VLast = VOld - Vin;
|
||||||
if (VLast > Hyst || VLast < -Hyst) {
|
if (VLast > Hyst || VLast < -Hyst) {
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
}
|
|
||||||
|
|
||||||
// Voltage Comparator adjustment
|
// Voltage Comparator adjustment
|
||||||
if (VLast > Hyst || VLast < -Hyst) {
|
|
||||||
adjustComp();
|
adjustComp();
|
||||||
|
// Alert the user that auto-calibration is ongoing
|
||||||
|
ERR_STATE = 1;
|
||||||
|
} else {
|
||||||
|
ERR_STATE = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alert the user that auto-calibration is ongoing
|
// Blink LED's on init
|
||||||
calibrateAlert();
|
if (BlinkCount > 0) {
|
||||||
|
BlinkState = !BlinkState;
|
||||||
|
digitalWrite(ERR_LED, BlinkState);
|
||||||
|
digitalWrite(TRG_OUT, BlinkState);
|
||||||
|
--BlinkCount;
|
||||||
|
} else {
|
||||||
// Check for error state
|
// Check for error state
|
||||||
checkError();
|
checkError();
|
||||||
|
}
|
||||||
|
|
||||||
// Reply with status
|
// Print state if debug is on
|
||||||
serialReply();
|
if (Debug > 0) {
|
||||||
|
serialPrintState();
|
||||||
|
}
|
||||||
// Sets trigger output state to false after completing loop
|
// Sets trigger output state to false after completing loop
|
||||||
//digitalWrite(TRG_OUT, HIGH);
|
//digitalWrite(TRG_OUT, HIGH);
|
||||||
sensorHReading = 0;
|
sensorHReading = 0;
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,63 @@
|
||||||
|
#ifndef PP_CONFIG_H
|
||||||
|
#define PP_CONFIG_H
|
||||||
|
|
||||||
// Configurable settings:
|
// Configurable settings:
|
||||||
|
|
||||||
|
#define GAIN_FACTOR_DEFAULT 2 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
||||||
|
#define GAIN_FACTOR_ADDRESS 0
|
||||||
#if !(defined(GAIN_FACTOR))
|
#if !(defined(GAIN_FACTOR))
|
||||||
int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x
|
extern int GAIN_FACTOR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef senseThrs
|
#define FOLLOWER_THRESHOLD_DEFAULT 1450 // Voltage follower default voltage in mV
|
||||||
#define senseThrs 1450
|
#define FOLLOWER_THRESHOLD_ADDRESS 4
|
||||||
|
#if !(defined(followerThrs))
|
||||||
|
extern int followerThrs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef compThrs
|
#define COMP_THRESHOLD_DEFAULT 2850 // Comparatore Vref default voltage in mV
|
||||||
#define compThrs 2850
|
#define COMP_THRESHOLD_ADDRESS 8
|
||||||
|
#if !(defined(compThrs))
|
||||||
|
extern int compThrs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef InitCount
|
#ifndef InitCount
|
||||||
#define InitCount 6 // Number of times to blink the LED on start
|
#define InitCount 6 // Number of times to blink the LED on start
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LOOP_DUR_DEFAULT 50 // duration of time between ADC checks and other loop functions
|
||||||
|
#define LOOP_DUR_ADDRESS 12
|
||||||
#if !(defined(LOOP_DUR))
|
#if !(defined(LOOP_DUR))
|
||||||
extern int LOOP_DUR;
|
extern int LOOP_DUR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TRG_DUR_DEFAULT 20 // duration of the Z-axis pulse sent, in ms
|
||||||
|
#define TRG_DUR_ADDRESS 16
|
||||||
#if !(defined(TRG_DUR))
|
#if !(defined(TRG_DUR))
|
||||||
int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms
|
extern int TRG_DUR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HYST_DEFAULT 20
|
||||||
|
#define HYST_ADDRESS 20
|
||||||
#if !(defined(Hyst))
|
#if !(defined(Hyst))
|
||||||
int Hyst = 20; // Hysteresis value for ADC measurements
|
extern int Hyst; // Hysteresis value for ADC measurements
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !(defined(Debug))
|
||||||
|
extern int Debug;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !(defined(voldMeterConstant))
|
#if !(defined(voldMeterConstant))
|
||||||
long voltMeterConstant = 1125300L; // For fine tuning input voltage sense
|
extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef I2C_INPUT
|
#ifdef I2C_INPUT
|
||||||
#if !(defined(pP_i2c_address))
|
#if !(defined(pP_i2c_address))
|
||||||
byte pP_i2c_address = 0xa0; // I2C Bus Address
|
extern byte pP_i2c_address = 0xa0; // I2C Bus Address
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void restoreConfig();
|
||||||
|
void resetConfig();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -11,15 +11,15 @@ int VLast = 0;
|
||||||
// Convert threshold values based on the input voltage
|
// Convert threshold values based on the input voltage
|
||||||
|
|
||||||
long followerLong = followerThrs * 1023L;
|
long followerLong = followerThrs * 1023L;
|
||||||
|
long compLong = compThrs * 1023L;
|
||||||
|
long followerInt;
|
||||||
long compInt;
|
long compInt;
|
||||||
|
|
||||||
// Voltage Comparator Adjustment parameters
|
// Voltage Comparator Adjustment parameters
|
||||||
int VComp = 0;
|
int VComp = 0;
|
||||||
|
|
||||||
// Voltage Follower Adjustment parameters
|
// Voltage Follower Adjustment parameters
|
||||||
int VAdj = 0;
|
int VFol = 0;
|
||||||
int diffAdjL = VAdj - senseInt;
|
|
||||||
int diffAdjH = senseInt - VAdj;
|
|
||||||
|
|
||||||
// Error blink parameters
|
// Error blink parameters
|
||||||
|
|
||||||
|
|
@ -29,10 +29,8 @@ int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle
|
||||||
// Serial Input Parsing Variables
|
// Serial Input Parsing Variables
|
||||||
#define buffSize 40
|
#define buffSize 40
|
||||||
char inputBuffer[buffSize];
|
char inputBuffer[buffSize];
|
||||||
#define startMarker '<'
|
#define endMarker '\n'
|
||||||
#define endMarker '>'
|
|
||||||
byte bytesRecvd = 0;
|
byte bytesRecvd = 0;
|
||||||
bool readInProgress = false;
|
|
||||||
bool serialIncoming = false;
|
bool serialIncoming = false;
|
||||||
char serialMessageIn[buffSize] = {0};
|
char serialMessageIn[buffSize] = {0};
|
||||||
int serialInt = 0;
|
int serialInt = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue