From 0636ab1cbd6a0eded7cd38162535e5f2dcba87b1 Mon Sep 17 00:00:00 2001 From: oliverhaag Date: Sat, 22 Jan 2011 16:14:48 +0000 Subject: [PATCH] Fixed DSO-2090 pretrigger bug and improved timing of sampling routine --- openhantek/ChangeLog | 8 ++++++++ openhantek/src/hantek/control.cpp | 58 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog index 21d6ff4..d5c2919 100644 --- a/openhantek/ChangeLog +++ b/openhantek/ChangeLog @@ -106,3 +106,11 @@ 2010-12-13 Oliver Haag * Triggermode Auto working correctly now * Improved frequency detection routine + +2011-01-22 Oliver Haag +* Storing positions of docking windows and toolbars in settings now +* Added submenu to show/hide docking windows and toolbars to the View menu + +2011-01-22 Oliver Haag +* Fixed bug with wrong pretrigger position when using a DSO-2090 +* Improved timing of the Hantek DSO sampling routine diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp index 5adba57..e5187f7 100644 --- a/openhantek/src/hantek/control.cpp +++ b/openhantek/src/hantek/control.cpp @@ -115,7 +115,7 @@ namespace Hantek { /// \brief Handles all USB things until the device gets disconnected. void Control::run() { - int errorCode, waitCounter = 0; + int errorCode, cycleCounter = 0, startCycle = 0; // The control loop is running until the device is disconnected int captureState = CAPTURE_WAITING; @@ -171,9 +171,10 @@ namespace Hantek { if(captureState == LIBUSB_ERROR_NO_DEVICE) break; - // Check the current oscilloscope state every 50 ms - /// \todo Maybe the time interval could be improved... - this->msleep(50); + // Check the current oscilloscope state everytime 25% of the buffer should be refilled + // Not more often than every 10 ms though + int cycleTime = qMax(this->samplerateDivider * this->bufferSize * 250 / this->samplerateMax, (long unsigned int) 10); + this->msleep(cycleTime); if(!this->sampling) { samplingStarted = false; @@ -209,21 +210,31 @@ namespace Hantek { case CAPTURE_WAITING: if(samplingStarted && lastTriggerMode == this->triggerMode) { - waitCounter++; + cycleCounter++; - if(this->triggerMode == Dso::TRIGGERMODE_AUTO) { - if(waitCounter > (double) this->samplerateDivider / this->samplerateMax * this->bufferSize * 20 + 2) { - // Force triggering - errorCode = this->device->bulkCommand(this->command[COMMAND_FORCETRIGGER]); + if(cycleCounter == startCycle) { + // Buffer refilled completely since start of sampling, enable the trigger now + errorCode = this->device->bulkCommand(this->command[COMMAND_ENABLETRIGGER]); + if(errorCode < 0) { if(errorCode == LIBUSB_ERROR_NO_DEVICE) captureState = LIBUSB_ERROR_NO_DEVICE; + break; + } + #ifdef DEBUG + qDebug("Enabling trigger"); + #endif + } + else if(cycleCounter >= 8 + startCycle && this->triggerMode == Dso::TRIGGERMODE_AUTO) { + // Force triggering + errorCode = this->device->bulkCommand(this->command[COMMAND_FORCETRIGGER]); + if(errorCode == LIBUSB_ERROR_NO_DEVICE) + captureState = LIBUSB_ERROR_NO_DEVICE; #ifdef DEBUG qDebug("Forcing trigger"); #endif - } } - if(waitCounter < 80) + if(cycleCounter < 50 || cycleCounter < 4000 / cycleTime) break; } @@ -238,19 +249,9 @@ namespace Hantek { qDebug("Starting to capture"); #endif - // Enable trigger - errorCode = this->device->bulkCommand(this->command[COMMAND_ENABLETRIGGER]); - if(errorCode < 0) { - if(errorCode == LIBUSB_ERROR_NO_DEVICE) - captureState = LIBUSB_ERROR_NO_DEVICE; - break; - } -#ifdef DEBUG - qDebug("Enabling trigger"); -#endif - samplingStarted = true; - waitCounter = 0; + cycleCounter = 0; + startCycle = this->triggerPosition * 1000 / cycleTime + 1; lastTriggerMode = this->triggerMode; break; @@ -373,7 +374,7 @@ namespace Hantek { } // Convert data from the oscilloscope and write it into the sample buffer - unsigned int bufferPosition = this->triggerPoint * 2; + unsigned int bufferPosition = (this->triggerPoint + 1) * 2; if(using10Bits) { // Additional 2 most significant bits after the normal data unsigned int extraBitsPosition; // Track the position of the extra bits in the additional byte @@ -412,7 +413,7 @@ namespace Hantek { } // Convert data from the oscilloscope and write it into the sample buffer - unsigned int bufferPosition = this->triggerPoint * 2; + unsigned int bufferPosition = (this->triggerPoint + 1) * 2; if(using10Bits) { // Additional 2 most significant bits after the normal data for(unsigned int realPosition = 0; realPosition < channelDataCount; realPosition++, bufferPosition += 2) { @@ -665,7 +666,6 @@ namespace Hantek { this->updateBufferSize(this->bufferSize); this->setTriggerPosition(this->triggerPosition); - this->setTriggerSlope(this->triggerSlope); return this->samplerateMax / this->samplerateDivider; } @@ -955,7 +955,7 @@ namespace Hantek { // SetTriggerAndSamplerate bulk command for trigger slope CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE]; - commandSetTriggerAndSamplerate->setTriggerSlope((/*this->bufferSize != BUFFER_SMALL ||*/ commandSetTriggerAndSamplerate->getSamplerateFast() % 2 == 0) ? slope : Dso::SLOPE_NEGATIVE - slope); + commandSetTriggerAndSamplerate->setTriggerSlope(slope); this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true; break; } @@ -988,10 +988,10 @@ namespace Hantek { positionSamples /= HANTEK_CHANNELS; // Calculate the position value (Start point depending on buffer size) - unsigned long int positionStart = (this->bufferSize == BUFFER_SMALL) ? 0x77660 : 0x78000; + unsigned long int position = 0x7ffff - this->bufferSize + positionSamples; // SetTriggerAndSamplerate bulk command for trigger position - ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(positionStart + positionSamples); + ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true; break; -- libgit2 0.21.4