Capacitance meter correctly and accurately detects rise and fall times

This commit is contained in:
EspoTek 2017-06-29 10:29:38 +10:00
parent 1a5bd9a5d7
commit 5f66ee2916
10 changed files with 120 additions and 4 deletions

Binary file not shown.

View File

@ -330,10 +330,10 @@ bool isoBuffer::jitterCompensationProcedure(double baudRate, unsigned char curre
return true;
}
int isoBuffer::inverseSampleConvert(double voltageLevel, int TOP, bool AC){
short isoBuffer::inverseSampleConvert(double voltageLevel, int TOP, bool AC){
double scope_gain = (double)(virtualParent->driver->scopeGain);
int sample;
short sample;
if(AC){
voltageLevel += virtualParent->currentVmean; //This is old (1 frame in past) value and might not be good for signals with large variations in DC level (although the cap should filter that anyway)??
@ -348,3 +348,92 @@ int isoBuffer::inverseSampleConvert(double voltageLevel, int TOP, bool AC){
return sample;
}
#define NUM_SAMPLES_SEEKING_CAP (20)
#ifdef INVERT_MM
#define X0_COMPARISON_CAP >
#define X1_X2_COMPARISON_CAP <
#else
#define X0_COMPARISON_CAP <
#define X1_X2_COMPARISON_CAP >
#endif
int isoBuffer::cap_x0fromLast(double seconds, double vbot){
int samplesInPast = seconds * samplesPerSecond;
if(back < samplesInPast){
return -1; //too hard, not really important
}
short vbot_s = inverseSampleConvert(vbot, 2048, 0);
qDebug() << "vbot_s (x0) = " << vbot_s;
int num_found = 0;
for(int i=samplesInPast; i; i--){
short currentSample = buffer[back - i];
if(currentSample X0_COMPARISON_CAP vbot_s){
num_found++;
} else num_found--;
if(num_found < 0){
num_found = 0;
}
if (num_found > NUM_SAMPLES_SEEKING_CAP){
return samplesInPast-i;
}
}
return -1;
}
int isoBuffer::cap_x1fromLast(double seconds, int x0, double vbot){
int samplesInPast = seconds * samplesPerSecond;
samplesInPast -= x0;
if(back < samplesInPast){
return -1; //too hard, not really important
}
short vbot_s = inverseSampleConvert(vbot, 2048, 0);
qDebug() << "vbot_s (x1) = " << vbot_s;
int num_found = 0;
for(int i=samplesInPast; i; i--){
short currentSample = buffer[back - i];
if(currentSample X1_X2_COMPARISON_CAP vbot_s){
num_found++;
} else num_found--;
if(num_found < 0){
num_found = 0;
}
if (num_found > NUM_SAMPLES_SEEKING_CAP){
return samplesInPast-i + x0;
}
}
return -1;
}
int isoBuffer::cap_x2fromLast(double seconds, int x1, double vtop){
int samplesInPast = seconds * samplesPerSecond;
samplesInPast -= x1;
if(back < samplesInPast){
return -1; //too hard, not really important
}
short vtop_s = inverseSampleConvert(vtop, 2048, 0);
qDebug() << "vtop_s (x2) = " << vtop_s;
int num_found = 0;
for(int i=samplesInPast; i; i--){
short currentSample = buffer[back - i];
if(currentSample X1_X2_COMPARISON_CAP vtop_s){
num_found++;
} else num_found--;
if(num_found < 0){
num_found = 0;
}
if (num_found > NUM_SAMPLES_SEEKING_CAP){
return samplesInPast-i + x1;
}
}
return -1;
}

View File

@ -39,8 +39,10 @@ public:
void serialDecode(double baudRate);
int serialDistance();
double sampleConvert(short sample, int TOP, bool AC);
int inverseSampleConvert(double voltageLevel, int TOP, bool AC);
//int cap_x0fromLast(double seconds, double vbot);
short inverseSampleConvert(double voltageLevel, int TOP, bool AC);
int cap_x0fromLast(double seconds, double vbot);
int cap_x1fromLast(double seconds, int x0, double vbot);
int cap_x2fromLast(double seconds, int x1, double vtop);
//Generic Vars
QPlainTextEdit *console, *console1, *console2;
bool serialAutoScroll = true;

View File

@ -1007,6 +1007,31 @@ void isoDriver::multimeterStats(){
}else sendMultimeterLabel4("Resistance (Ω)");
multimeterRMS(estimated_resistance);
}
if(multimeterType == C){
double cap_vbot = 0.5;
double cap_vtop = 1.2;
int cap_x0 = internalBuffer375_CH1->cap_x0fromLast(1, cap_vbot);
if(cap_x0 == -1){
qDebug() << "cap_x0 == -1";
return;
}
int cap_x1 = internalBuffer375_CH1->cap_x1fromLast(1, cap_x0, cap_vbot);
if(cap_x1 == -1){
qDebug() << "cap_x1 == -1";
return;
}
int cap_x2 = internalBuffer375_CH1->cap_x2fromLast(1, cap_x1, cap_vtop);
if(cap_x2 == -1){
qDebug() << "cap_x2 == -1";
return;
}
qDebug() << "x0 = " << cap_x0;
qDebug() << "x1 = " << cap_x1;
qDebug() << "x2 = " << cap_x2;
qDebug() << "dt = " << cap_x2-cap_x1;
}
}
void isoDriver::enableMM(){

Binary file not shown.