Added function to alert the user when calibrating

This commit is contained in:
pyr0ball 2019-04-22 16:06:40 -07:00
parent bcdae2e9e4
commit 37f7d4d085

View file

@ -62,14 +62,10 @@ 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 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 #define InitCount 6 // Number of times to blink the LED on start
int TRG_DUR = 120; // duration of the Z-axis pulse sent, in ms int TRG_DUR = 120; // duration of the Z-axis pulse sent, in ms
#define senseThrs 2.45 #define senseThrs 1.85
//float senseHighThrs = 2.35; // Upper threshold of Voltage Follower before adjustment #define compThrs 1.85
//float senseLowThrs = 1.8; // Lower threshold of Voltage Follower before adjustment
#define compThrs 3.15
//float compHighThrs = 2.75; // Upper threshold of Comparator before adjustment
//float compLowThrs = 2.54; // Lower threshold of Comparator before adjustment
#define Hyst 20 // Hysteresis value for ADC measurements int Hyst = 20; // Hysteresis value for ADC measurements
#define Vin 5 // input reference voltage #define Vin 5 // input reference voltage
@ -98,28 +94,19 @@ volatile int ERR_STATE = 0;
// Convert float to integer for adjustment functions // Convert float to integer for adjustment functions
int senseInt = (senseThrs / 5) * 1024; // Voltage Follower upper converted to adg interger int senseInt = (senseThrs / 5) * 1024; // Voltage Follower upper converted to adg interger
//int senseHighInt = (senseHighThrs / 5) * 1024; // Voltage Follower upper converted to adg interger
//int senseLowInt = (senseLowThrs / 5) * 1024; // Voltage Follower lower converted to adg interger
int compInt = (compThrs / 5) * 1024; // Upper threshold of Comparator before adjustment int compInt = (compThrs / 5) * 1024; // Upper threshold of Comparator before adjustment
//int compHighInt = (compHighThrs / 5) * 1024; // Upper threshold of Comparator before adjustment
//int compLowInt = (compLowThrs / 5) * 1024; // Lower threshold of Comparator before adjustment
// Voltage Comparator Adjustment parameters // Voltage Comparator Adjustment parameters
//float VCompRef = 0.00; // variable to store the float value read from the comparator reference //float VCompRef = 0.00; // variable to store the float value read from the comparator reference
int VComp = 0; int VComp = 0;
int diffCompL = VComp - compInt; int diffCompL = VComp - compInt;
int diffCompH = compInt - VComp; int diffCompH = compInt - VComp;
//int diffCompL = VComp - compLowInt;
//int diffCompH = compHighInt - VComp;
// Voltage Follower Adjustment parameters // Voltage Follower Adjustment parameters
//float vAdjRead = 0.00; // variable to store the value read from the follower //float vAdjRead = 0.00; // variable to store the value read from the follower
int VAdj = 0; int VAdj = 0;
int diffAdjL = VAdj - senseInt; int diffAdjL = VAdj - senseInt;
int diffAdjH = senseInt - VAdj; int diffAdjH = senseInt - VAdj;
//int diffAdjL = VAdj - senseLowInt;
//int diffAdjH = senseHighInt - VAdj;
// Error blink parameters // Error blink parameters
int BlinkState = LOW; int BlinkState = LOW;
@ -198,14 +185,17 @@ void adjustComp() {
analogWrite(VCOMP_PWM, ADJ_COMP); analogWrite(VCOMP_PWM, ADJ_COMP);
} }
void calibrateAlert() {
if (diffAdjL > 0.0 || diffAdjH > 0.0 || diffCompL > 0.0 || diffCompH > 0.0) {
ERR_STATE = 1;
}
}
/*------------------------------------------------*/ /*------------------------------------------------*/
void adjustGain() { void adjustGain() {
if (GAIN_FACTOR < 0 || GAIN_FACTOR > 4) { if (GAIN_FACTOR == 0) {
ERR_STATE = 1;
}
else if (GAIN_FACTOR == 0) {
pinMode(GADJ_R3, INPUT); pinMode(GADJ_R3, INPUT);
pinMode(GADJ_R2, INPUT); pinMode(GADJ_R2, INPUT);
pinMode(GADJ_R1, INPUT); pinMode(GADJ_R1, INPUT);
@ -499,16 +489,10 @@ void loop() {
VComp = analogRead(VCOMP_SENSE_PIN); VComp = analogRead(VCOMP_SENSE_PIN);
diffCompL = ((VComp - compInt) / 4) - Hyst; diffCompL = ((VComp - compInt) / 4) - Hyst;
diffCompH = ((compInt - VComp) / 4) - Hyst; diffCompH = ((compInt - VComp) / 4) - Hyst;
//diffCompL = VComp - compLowInt;
//diffCompH = compHighInt - VComp;
//VCompRef = (float)(VComp * 5) / 1024;
VAdj = analogRead(V_FOLLOW_PIN); VAdj = analogRead(V_FOLLOW_PIN);
diffAdjL = ((VAdj - senseInt) / 4) - Hyst; diffAdjL = ((VAdj - senseInt) / 4) - Hyst;
diffAdjH = ((senseInt - VAdj) / 4) - Hyst; diffAdjH = ((senseInt - VAdj) / 4) - Hyst;
//diffAdjL = VAdj - senseLowInt;
//diffAdjH = senseHighInt - VAdj;
//vAdjRead = (float)(VAdj * 5) / 1024;
// Set the amplification gain factor // Set the amplification gain factor
@ -520,6 +504,9 @@ void loop() {
// Voltage Comparator adjustment // Voltage Comparator adjustment
adjustComp(); adjustComp();
// Alert the user that auto-calibration is ongoing
calibrateAlert();
// Check for error state // Check for error state
checkError(); checkError();