Commit 67afd83c7996eec867cf38d4ad79aa6ba34e7c10

Authored by Denis Dovzhenko
Committed by David Gräff
1 parent 93d81624

Moved timebaseSteps to HorizontalDock, record length changed to 8K samples (6022BE only)

.gitignore
@@ -2,4 +2,5 @@ @@ -2,4 +2,5 @@
2 .o 2 .o
3 .so 3 .so
4 .*~ 4 .*~
5 -build/  
6 \ No newline at end of file 5 \ No newline at end of file
  6 +CMakeLists.txt.user
  7 +build/
openhantek/src/dockwindows.cpp
@@ -27,6 +27,8 @@ @@ -27,6 +27,8 @@
27 #include <QDockWidget> 27 #include <QDockWidget>
28 #include <QLabel> 28 #include <QLabel>
29 29
  30 +#include <cmath>
  31 +
30 #include "dockwindows.h" 32 #include "dockwindows.h"
31 33
32 #include "helper.h" 34 #include "helper.h"
@@ -51,7 +53,6 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent, @@ -51,7 +53,6 @@ HorizontalDock::HorizontalDock(DsoSettings *settings, QWidget *parent,
51 this->samplerateSiSpinBox->setMaximum(1e8); 53 this->samplerateSiSpinBox->setMaximum(1e8);
52 this->samplerateSiSpinBox->setUnitPostfix("/s"); 54 this->samplerateSiSpinBox->setUnitPostfix("/s");
53 55
54 - QList<double> timebaseSteps;  
55 timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0; 56 timebaseSteps << 1.0 << 2.0 << 4.0 << 10.0;
56 57
57 this->timebaseLabel = new QLabel(tr("Timebase")); 58 this->timebaseLabel = new QLabel(tr("Timebase"));
@@ -144,10 +145,19 @@ void HorizontalDock::setSamplerate(double samplerate) { @@ -144,10 +145,19 @@ void HorizontalDock::setSamplerate(double samplerate) {
144 145
145 /// \brief Changes the timebase. 146 /// \brief Changes the timebase.
146 /// \param timebase The timebase in seconds. 147 /// \param timebase The timebase in seconds.
147 -void HorizontalDock::setTimebase(double timebase) {  
148 - this->suppressSignals = true;  
149 - this->timebaseSiSpinBox->setValue(timebase);  
150 - this->suppressSignals = false; 148 +double HorizontalDock::setTimebase(double timebase) {
  149 + // timebaseSteps are repeated in each decade
  150 + double decade = pow(10, floor(log10(timebase)));
  151 + double vNorm = timebase / decade;
  152 + for (int i = 0; i < timebaseSteps.size() - 1; ++i) {
  153 + if (timebaseSteps.at(i) <= vNorm && vNorm < timebaseSteps.at(i + 1)) {
  154 + suppressSignals = true;
  155 + timebaseSiSpinBox->setValue(decade * timebaseSteps.at(i));
  156 + suppressSignals = false;
  157 + break;
  158 + }
  159 + }
  160 + return timebaseSiSpinBox->value();
151 } 161 }
152 162
153 /// \brief Changes the record length if the new value is supported. 163 /// \brief Changes the record length if the new value is supported.
openhantek/src/dockwindows.h
@@ -51,7 +51,7 @@ public: @@ -51,7 +51,7 @@ public:
51 51
52 void setFrequencybase(double timebase); 52 void setFrequencybase(double timebase);
53 void setSamplerate(double samplerate); 53 void setSamplerate(double samplerate);
54 - void setTimebase(double timebase); 54 + double setTimebase(double timebase);
55 void setRecordLength(unsigned int recordLength); 55 void setRecordLength(unsigned int recordLength);
56 int setFormat(Dso::GraphFormat format); 56 int setFormat(Dso::GraphFormat format);
57 57
@@ -75,6 +75,7 @@ protected: @@ -75,6 +75,7 @@ protected:
75 ///interpreted and shown 75 ///interpreted and shown
76 76
77 DsoSettings *settings; ///< The settings provided by the parent class 77 DsoSettings *settings; ///< The settings provided by the parent class
  78 + QList<double> timebaseSteps; ///< Steps for the timebase spinbox
78 79
79 QStringList formatStrings; ///< Strings for the formats 80 QStringList formatStrings; ///< Strings for the formats
80 81
openhantek/src/hantek/control.cpp
@@ -266,7 +266,8 @@ int Control::getCaptureState() { @@ -266,7 +266,8 @@ int Control::getCaptureState() {
266 int Control::getSamples(bool process) { 266 int Control::getSamples(bool process) {
267 int errorCode; 267 int errorCode;
268 268
269 - const unsigned int DROP_DSO6022_SAMPLES = 0x410; 269 + const unsigned int DROP_DSO6022_HEAD = 0x410;
  270 + const unsigned int DROP_DSO6022_TAIL = 0x3F0;
270 271
271 if (this->device->getModel() != MODEL_DSO6022BE) { 272 if (this->device->getModel() != MODEL_DSO6022BE) {
272 // Request data 273 // Request data
@@ -395,13 +396,15 @@ int Control::getSamples(bool process) { @@ -395,13 +396,15 @@ int Control::getSamples(bool process) {
395 } else { 396 } else {
396 // Normal mode, channels are using their separate buffers 397 // Normal mode, channels are using their separate buffers
397 sampleCount = totalSampleCount / HANTEK_CHANNELS; 398 sampleCount = totalSampleCount / HANTEK_CHANNELS;
398 - // if device is 6022BE, drop first DROP_DSO6022_SAMPLES samples 399 + // if device is 6022BE, drop heading & trailing samples
399 if (this->device->getModel() == MODEL_DSO6022BE) 400 if (this->device->getModel() == MODEL_DSO6022BE)
400 - sampleCount -= DROP_DSO6022_SAMPLES; 401 + sampleCount -= (DROP_DSO6022_HEAD + DROP_DSO6022_TAIL);
401 for (int channel = 0; channel < HANTEK_CHANNELS; ++channel) { 402 for (int channel = 0; channel < HANTEK_CHANNELS; ++channel) {
402 if (this->settings.voltage[channel].used) { 403 if (this->settings.voltage[channel].used) {
403 // Resize sample vector 404 // Resize sample vector
404 - this->samples[channel].resize(sampleCount); 405 + if (samples[channel].size() < sampleCount) {
  406 + this->samples[channel].resize(sampleCount);
  407 + }
405 408
406 // Convert data from the oscilloscope and write it into the sample 409 // Convert data from the oscilloscope and write it into the sample
407 // buffer 410 // buffer
@@ -440,8 +443,8 @@ int Control::getSamples(bool process) { @@ -440,8 +443,8 @@ int Control::getSamples(bool process) {
440 } else { 443 } else {
441 if (this->device->getModel() == MODEL_DSO6022BE) { 444 if (this->device->getModel() == MODEL_DSO6022BE) {
442 bufferPosition += channel; 445 bufferPosition += channel;
443 - // if device is 6022BE, offset DROP_DSO6022_SAMPLES incrementally  
444 - bufferPosition += DROP_DSO6022_SAMPLES * 2; 446 + // if device is 6022BE, offset DROP_DSO6022_HEAD incrementally
  447 + bufferPosition += DROP_DSO6022_HEAD * 2;
445 } else 448 } else
446 bufferPosition += HANTEK_CHANNELS - 1 - channel; 449 bufferPosition += HANTEK_CHANNELS - 1 - channel;
447 450
@@ -1098,13 +1101,11 @@ void Control::connectDevice() { @@ -1098,13 +1101,11 @@ void Control::connectDevice() {
1098 this->specification.samplerate.single.base = 1e6; 1101 this->specification.samplerate.single.base = 1e6;
1099 this->specification.samplerate.single.max = 48e6; 1102 this->specification.samplerate.single.max = 48e6;
1100 this->specification.samplerate.single.maxDownsampler = 10; 1103 this->specification.samplerate.single.maxDownsampler = 10;
1101 - this->specification.samplerate.single.recordLengths << UINT_MAX << 10240  
1102 - << 32768; 1104 + this->specification.samplerate.single.recordLengths << UINT_MAX << 10240;
1103 this->specification.samplerate.multi.base = 1e6; 1105 this->specification.samplerate.multi.base = 1e6;
1104 this->specification.samplerate.multi.max = 48e6; 1106 this->specification.samplerate.multi.max = 48e6;
1105 this->specification.samplerate.multi.maxDownsampler = 10; 1107 this->specification.samplerate.multi.maxDownsampler = 10;
1106 - this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480  
1107 - << 65536; 1108 + this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480;
1108 this->specification.bufferDividers << 1000 << 1 << 1; 1109 this->specification.bufferDividers << 1000 << 1 << 1;
1109 this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 1110 this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60
1110 << 4.00 << 8.0 << 16.0 << 40.0; 1111 << 4.00 << 8.0 << 16.0 << 40.0;
@@ -1248,12 +1249,14 @@ double Control::setSamplerate(double samplerate) { @@ -1248,12 +1249,14 @@ double Control::setSamplerate(double samplerate) {
1248 this->controlPending[CONTROLINDEX_SETTIMEDIV] = true; 1249 this->controlPending[CONTROLINDEX_SETTIMEDIV] = true;
1249 this->settings.samplerate.current = samplerate; 1250 this->settings.samplerate.current = samplerate;
1250 1251
  1252 + // Provide margin for SW trigger
  1253 + unsigned int sampleMargin = 2000;
1251 // Check for Roll mode 1254 // Check for Roll mode
1252 if (this->settings.samplerate.limits 1255 if (this->settings.samplerate.limits
1253 ->recordLengths[this->settings.recordLengthId] != UINT_MAX) 1256 ->recordLengths[this->settings.recordLengthId] != UINT_MAX)
1254 emit recordTimeChanged( 1257 emit recordTimeChanged(
1255 - (double)this->settings.samplerate.limits  
1256 - ->recordLengths[this->settings.recordLengthId] / 1258 + (double)(this->settings.samplerate.limits
  1259 + ->recordLengths[this->settings.recordLengthId] - sampleMargin) /
1257 this->settings.samplerate.current); 1260 this->settings.samplerate.current);
1258 emit samplerateChanged(this->settings.samplerate.current); 1261 emit samplerateChanged(this->settings.samplerate.current);
1259 1262
openhantek/src/openhantek.cpp
@@ -691,9 +691,8 @@ void OpenHantekMainWindow::recordTimeChanged(double duration) { @@ -691,9 +691,8 @@ void OpenHantekMainWindow::recordTimeChanged(double duration) {
691 if (this->settings->scope.horizontal.samplerateSet && 691 if (this->settings->scope.horizontal.samplerateSet &&
692 this->settings->scope.horizontal.recordLength != UINT_MAX) { 692 this->settings->scope.horizontal.recordLength != UINT_MAX) {
693 // The samplerate was set, let's adapt the timebase accordingly 693 // The samplerate was set, let's adapt the timebase accordingly
694 - this->settings->scope.horizontal.timebase = duration / DIVS_TIME;  
695 - this->horizontalDock->setTimebase(  
696 - this->settings->scope.horizontal.timebase); 694 + this->settings->scope.horizontal.timebase =
  695 + this->horizontalDock->setTimebase(duration / DIVS_TIME);
697 } 696 }
698 697
699 // The trigger position should be kept at the same place but the timebase has 698 // The trigger position should be kept at the same place but the timebase has
@@ -733,6 +732,7 @@ void OpenHantekMainWindow::samplerateSelected() { @@ -733,6 +732,7 @@ void OpenHantekMainWindow::samplerateSelected() {
733 void OpenHantekMainWindow::timebaseSelected() { 732 void OpenHantekMainWindow::timebaseSelected() {
734 this->dsoControl->setRecordTime(this->settings->scope.horizontal.timebase * 733 this->dsoControl->setRecordTime(this->settings->scope.horizontal.timebase *
735 DIVS_TIME); 734 DIVS_TIME);
  735 + this->dsoWidget->updateTimebase(settings->scope.horizontal.timebase);
736 } 736 }
737 737
738 /// \brief Sets the offset of the oscilloscope for the given channel. 738 /// \brief Sets the offset of the oscilloscope for the given channel.