Recentreing in.

This commit is contained in:
EspoTek 2017-06-22 14:49:50 +10:00
parent 7c3ae61fe8
commit 445a301029
14 changed files with 34 additions and 13 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.1.0, 2017-06-20T08:23:37. -->
<!-- Written by QtCreator 4.1.0, 2017-06-22T14:16:09. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -8,7 +8,7 @@
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">2</value>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>

Binary file not shown.

View File

@ -191,7 +191,7 @@ double isoBuffer::sampleConvert(short sample, int TOP, bool AC){
double voltageLevel;
voltageLevel = (sample * (vcc/2)) / (R4/(R3+R4)*scope_gain*TOP);
if (virtualParent->driver->deviceMode != 7) voltageLevel += vcc*(R2/(R1+R2));
if (virtualParent->driver->deviceMode != 7) voltageLevel += voltage_ref;
#ifdef INVERT_MM
if(virtualParent->driver->deviceMode == 7) voltageLevel *= -1;
#endif

View File

@ -44,6 +44,7 @@ public:
bool serialAutoScroll = true;
unsigned char channel = 255;
QTimer *updateTimer;
double voltage_ref = 1.65;
private:
//Generic Vars
short *buffer, *readData = NULL;

View File

@ -109,17 +109,19 @@ void isoDriver::timerTick(void){
//free(isoTemp);
}
void isoDriver::analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC){
void isoDriver::analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC, int channel){
double scope_gain = (double)(driver->scopeGain);
double accumulated = 0;
currentVmax = -20;
currentVmin = 20;
double ref = (channel == 1 ? ch1_ref : ch2_ref);
double *data = doublePtr->data();
for (int i=0;i<GRAPH_SAMPLES;i++){
data[i] = (shortPtr[i] * (vcc/2)) / (R4/(R3+R4)*scope_gain*TOP);
if (driver->deviceMode != 7) data[i] += vcc*(R2/(R1+R2));
if (driver->deviceMode != 7) data[i] += ref;
#ifdef INVERT_MM
if(driver->deviceMode == 7) data[i] *= -1;
#endif
@ -688,7 +690,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
if (CH1_mode == 1){
analogConvert(readData375_CH1, &CH1, 128, AC_CH1);
analogConvert(readData375_CH1, &CH1, 128, AC_CH1, 1);
xmin = (currentVmin < xmin) ? currentVmin : xmin;
xmax = (currentVmax > xmax) ? currentVmax : xmax;
broadcastStats(0);
@ -696,7 +698,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
if (CH1_mode == 2) digitalConvert(readData375_CH1, &CH1);
if (CH2_mode == 1){
analogConvert(readData375_CH2, &CH2, 128, AC_CH2);
analogConvert(readData375_CH2, &CH2, 128, AC_CH2, 2);
ymin = (currentVmin < ymin) ? currentVmin : ymin;
ymax = (currentVmax > ymax) ? currentVmax : ymax;
broadcastStats(1);
@ -704,7 +706,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) //0 for off, 1
if (CH2_mode == 2) digitalConvert(readData375_CH2, &CH2);
if(CH1_mode == -1) {
analogConvert(readData750, &CH1, 128, AC_CH1);
analogConvert(readData750, &CH1, 128, AC_CH1, 1);
xmin = (currentVmin < xmin) ? currentVmin : xmin;
xmax = (currentVmax > xmax) ? currentVmax : xmax;
broadcastStats(0);
@ -820,7 +822,7 @@ void isoDriver::multimeterAction(){
readData375_CH1 = internalBuffer375_CH1->readBuffer(window,GRAPH_SAMPLES, false, delay + ((triggerEnabled&&!paused_multimeter) ? triggerDelay + window/2 : 0));
QVector<double> x(GRAPH_SAMPLES), CH1(GRAPH_SAMPLES);
analogConvert(readData375_CH1, &CH1, 2048, 0); //No AC coupling!
analogConvert(readData375_CH1, &CH1, 2048, 0, 1); //No AC coupling!
for (double i=0; i<GRAPH_SAMPLES; i++){
x[i] = -(window*i)/((double)(GRAPH_SAMPLES-1)) - delay;

View File

@ -28,6 +28,7 @@ public:
#endif
genericUsbDriver *driver;
bool doNotTouchGraph = true;
double ch1_ref = 1.65, ch2_ref = 1.65;
//State Vars
bool AC_CH1 = false, AC_CH2 = false;
bool cursorStatsEnabled = true;
@ -63,7 +64,7 @@ private:
double triggerDelay;
bool singleShotEnabled = false;
//Generic Functions
void analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC);
void analogConvert(short *shortPtr, QVector<double> *doublePtr, int TOP, bool AC, int channel);
void digitalConvert(short *shortPtr, QVector<double> *doublePtr);
bool properlyPaused();
void autoGain(void);

View File

@ -1269,10 +1269,19 @@ void MainWindow::vertScaleEvent(bool enabled){
void MainWindow::on_actionCalibrate_triggered()
{
//Must be mode 4
//Must be AC
//Must be DC coupled
//Voltage must be disconnected
qDebug() << "Calibration routine beginning!";
unsigned char oldMode = ui->controller_iso->driver->deviceMode;
ui->controller_iso->ch1_ref = 1.65;
ui->controller_iso->ch2_ref = 1.65;
ui->controller_iso->internalBuffer375_CH1->voltage_ref = 1.65;
ui->controller_iso->internalBuffer750->voltage_ref = 1.65;
ui->controller_iso->internalBuffer375_CH2->voltage_ref = 1.65;
ui->controller_iso->clearBuffers(1,0,0);
QTimer::singleShot(1200, this, SLOT(calibrateStage2()));
}
@ -1280,7 +1289,15 @@ void MainWindow::on_actionCalibrate_triggered()
void MainWindow::calibrateStage2(){
double vref_CH1 = ui->controller_iso->meanVoltageLast(1, 1);
double vref_CH2 = ui->controller_iso->meanVoltageLast(1, 2);
qDebug() << "VRef (CH1) = " << centre_voltage_CH1;
qDebug() << "VRef (CH2) = " << centre_voltage_CH2;
qDebug() << "VRef (CH1) = " << vref_CH1;
qDebug() << "VRef (CH2) = " << vref_CH2;
ui->controller_iso->ch1_ref = 3.3 - vref_CH1;
ui->controller_iso->ch2_ref = 3.3 - vref_CH2;
ui->controller_iso->internalBuffer375_CH1->voltage_ref = 3.3 - vref_CH1;
ui->controller_iso->internalBuffer750->voltage_ref = 3.3 - vref_CH1;
ui->controller_iso->internalBuffer375_CH2->voltage_ref = 3.3 - vref_CH2;
}

Binary file not shown.