diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp index 95906c0..9267dc4 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp @@ -37,6 +37,7 @@ Trace::Trace(QString name, QColor color, QString live) reference_impedance(50.0), domain(DataType::Frequency), deembeddingActive(false), + deembedded_reference_impedance(50.0), lastMath(nullptr) { settings.valid = false; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.cpp index d4b7329..cee2079 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.cpp @@ -38,6 +38,12 @@ void Deembedding::startMeasurementDialog(DeembeddingOption *option) measurementUI = ui; ui->setupUi(measurementDialog); connect(measurementDialog, &QDialog::finished, [=](){ + if(measuring) { + measuring = false; + emit finishedMeasurement(); + } + measuringOption = nullptr; + measurementUI = nullptr; delete ui; }); @@ -52,6 +58,7 @@ void Deembedding::startMeasurementDialog(DeembeddingOption *option) traceChooser->setEnabled(false); ui->buttonBox->setEnabled(false); measuring = true; + emit triggerMeasurement(); }); connect(ui->buttonBox, &QDialogButtonBox::accepted, [=](){ @@ -128,15 +135,6 @@ Deembedding::Deembedding(TraceModel &tm) void Deembedding::Deembed(DeviceDriver::VNAMeasurement &d) { - // figure out the point in one sweep based on the incomig pointNums - static unsigned lastPointNum; - if (d.pointNum == 0) { - sweepPoints = lastPointNum; - } else if(d.pointNum > sweepPoints) { - sweepPoints = d.pointNum; - } - lastPointNum = d.pointNum; - for(auto it = options.begin();it != options.end();it++) { if (measuring && measuringOption == *it) { // this option needs a measurement @@ -144,14 +142,17 @@ void Deembedding::Deembed(DeviceDriver::VNAMeasurement &d) if(measurements.size() == 0) { // this is the first point of the measurement measurements.push_back(d); - } else { - // this is the first point of the next sweep, measurement complete - measuring = false; - measurementCompleted(); } } else if(measurements.size() > 0) { // in the middle of the measurement, add point measurements.push_back(d); + + if(d.pointNum == sweepPoints - 1) { + // this is the last point, measurement complete + measuring = false; + emit finishedMeasurement(); + measurementCompleted(); + } } if(measurementUI) { @@ -223,6 +224,11 @@ void Deembedding::clear() } } +bool Deembedding::isMeasuring() +{ + return measuring; +} + std::set Deembedding::getAffectedPorts() { set ret; @@ -233,6 +239,11 @@ std::set Deembedding::getAffectedPorts() return ret; } +void Deembedding::setPointsInSweepForMeasurement(unsigned int points) +{ + sweepPoints = points; +} + nlohmann::json Deembedding::toJSON() { nlohmann::json list; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.h b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.h index 3c12183..15a2fb7 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/Deembedding/deembedding.h @@ -30,7 +30,10 @@ public: void swapOptions(unsigned int index); void clear(); + bool isMeasuring(); + std::set getAffectedPorts(); + void setPointsInSweepForMeasurement(unsigned int points); std::vector& getOptions() {return options;} nlohmann::json toJSON() override; @@ -38,7 +41,8 @@ public: public slots: void configure(); signals: - void triggerMeasurement(bool S11 = true, bool S12 = true, bool S21 = true, bool S22 = true); + void triggerMeasurement(); + void finishedMeasurement(); void optionAdded(); void allOptionsCleared(); private: diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index 331d52f..5287245 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -192,6 +192,18 @@ VNA::VNA(AppWindow *window, QString name) enableDeembeddingAction->setEnabled(false); manualDeembed->setEnabled(false); }); + connect(&deembedding, &Deembedding::triggerMeasurement, [=]() { + // de-embedding measurement requested + wasRunningBeforeDeembeddingMeasurement = running; + Run(); + }); + connect(&deembedding, &Deembedding::finishedMeasurement, [=](){ + if(wasRunningBeforeDeembeddingMeasurement) { + Run(); + } else { + Stop(); + } + }); // Tools menu auto toolsMenu = new QMenu("Tools", window); @@ -1220,6 +1232,7 @@ void VNA::SetPoints(unsigned int points) settings.activeSegment = 0; } emit pointsChanged(points); + deembedding.setPointsInSweepForMeasurement(points); settings.npoints = points; SettingsChanged(); } @@ -1799,9 +1812,18 @@ void VNA::ConfigureDevice(bool resetTraces, std::function cb) s.excitedPorts.push_back(i); } } else { - for(unsigned int i=1;i<=DeviceDriver::getInfo(window->getDevice()).Limits.VNA.ports;i++) { - if(traceModel.PortExcitationRequired(i)) - s.excitedPorts.push_back(i); + if(deembedding.isMeasuring()) { + // use the required ports for the de-embedding measurement + for(auto p : deembedding.getAffectedPorts()) { + s.excitedPorts.push_back(p); + } + } else { + // use the required ports from the trace model + for(unsigned int i=1;i<=DeviceDriver::getInfo(window->getDevice()).Limits.VNA.ports;i++) { + if(traceModel.PortExcitationRequired(i)) { + s.excitedPorts.push_back(i); + } + } } } settings.excitedPorts = s.excitedPorts; diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h index f7285da..4a4392b 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h @@ -170,6 +170,7 @@ private: Deembedding deembedding; QAction *enableDeembeddingAction; bool deembedding_active; + bool wasRunningBeforeDeembeddingMeasurement; // Status Labels QLabel *lAverages;