Commit 87a2b63379ff1f63638fd215c434c36d55d5e01d

Authored by oliverhaag
1 parent a4f5dc7e

Improved samplerate calculation routine and fixed some bugs

openhantek/ChangeLog
@@ -85,3 +85,10 @@ @@ -85,3 +85,10 @@
85 2010-09-16 Oliver Haag <oliver.haag@gmail.com> 85 2010-09-16 Oliver Haag <oliver.haag@gmail.com>
86 * Added csv export return value to doExport method 86 * Added csv export return value to doExport method
87 * Fixed DSO-2150 samplerates 87 * Fixed DSO-2150 samplerates
  88 +
  89 +2010-09-21 Oliver Haag <oliver.haag@gmail.com>
  90 +* Fixed print shortcut
  91 +* Made samplerate calculation more flexible
  92 +* DSO-5200 data conversion bugfix
  93 +* Exporter::setFormat not filtering CSV format out anymore
  94 +* Removed misplaced " before voltages in exported CSV file
openhantek/src/exporter.cpp
@@ -66,7 +66,7 @@ void Exporter::setFilename(QString filename) { @@ -66,7 +66,7 @@ void Exporter::setFilename(QString filename) {
66 66
67 /// \brief Set the output format. 67 /// \brief Set the output format.
68 void Exporter::setFormat(ExportFormat format) { 68 void Exporter::setFormat(ExportFormat format) {
69 - if(format >= EXPORT_FORMAT_PRINTER && format <= EXPORT_FORMAT_IMAGE) 69 + if(format >= EXPORT_FORMAT_PRINTER && format <= EXPORT_FORMAT_CSV)
70 this->format = format; 70 this->format = format;
71 } 71 }
72 72
@@ -379,7 +379,7 @@ bool Exporter::doExport() { @@ -379,7 +379,7 @@ bool Exporter::doExport() {
379 379
380 // And now all sample values in volts 380 // And now all sample values in volts
381 for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++) 381 for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.count; position++)
382 - csvStream << "\"," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position]; 382 + csvStream << "," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position];
383 383
384 // Finally a newline 384 // Finally a newline
385 csvStream << '\n'; 385 csvStream << '\n';
openhantek/src/hantek/control.cpp
@@ -381,7 +381,7 @@ namespace Hantek { @@ -381,7 +381,7 @@ namespace Hantek {
381 if(bufferPosition >= dataCount) 381 if(bufferPosition >= dataCount)
382 bufferPosition %= dataCount; 382 bufferPosition %= dataCount;
383 383
384 - this->samples[channel][realPosition] = ((double) (data[bufferPosition] + (data[dataCount + bufferPosition] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]]; 384 + this->samples[channel][realPosition] = ((double) ((unsigned short int) data[bufferPosition] + ((unsigned short int) data[dataCount + bufferPosition] << 8)) / 0x1ff - this->offsetReal[channel]) * this->gainSteps[this->gain[channel]];
385 } 385 }
386 } 386 }
387 else { 387 else {
@@ -600,25 +600,32 @@ namespace Hantek { @@ -600,25 +600,32 @@ namespace Hantek {
600 } 600 }
601 601
602 // The maximum sample rate depends on the buffer size 602 // The maximum sample rate depends on the buffer size
  603 + unsigned int bufferDivider = 1;
603 switch((this->commandVersion == 0) ? commandSetTriggerAndSamplerate->getBufferSize() : commandSetBuffer5200->getBufferSize()) { 604 switch((this->commandVersion == 0) ? commandSetTriggerAndSamplerate->getBufferSize() : commandSetBuffer5200->getBufferSize()) {
604 case BUFFERID_ROLL: 605 case BUFFERID_ROLL:
605 - this->samplerateMax /= 1000; 606 + bufferDivider = 1000;
606 break; 607 break;
607 case BUFFERID_LARGE: 608 case BUFFERID_LARGE:
608 - this->samplerateMax /= 2; 609 + bufferDivider = 2;
609 break; 610 break;
610 default: 611 default:
611 break; 612 break;
612 } 613 }
613 614
614 // Get divider that would provide the requested rate, can't be zero 615 // Get divider that would provide the requested rate, can't be zero
  616 + this->samplerateMax /= bufferDivider;
615 this->samplerateDivider = qMax(this->samplerateMax / samplerate, (long unsigned int) 1); 617 this->samplerateDivider = qMax(this->samplerateMax / samplerate, (long unsigned int) 1);
616 618
617 - // Use normal mode if it would meet the rate as exactly as fast rate mode  
618 - if(fastRate && this->samplerateDivider % HANTEK_CHANNELS == 0) {  
619 - fastRate = false;  
620 - this->samplerateMax /= 2;  
621 - this->samplerateDivider /= HANTEK_CHANNELS; 619 + // Use normal mode if we need valueSlow or it would meet the rate at least as exactly as fast rate mode
  620 + if(fastRate) {
  621 + unsigned long int slowSamplerate = this->samplerateChannelMax / bufferDivider;
  622 + unsigned long int slowDivider = qMax(slowSamplerate / samplerate, (long unsigned int) 1);
  623 +
  624 + if(this->samplerateDivider > 4 || (qAbs((double) slowSamplerate / slowDivider - samplerate) <= qAbs(((double) this->samplerateMax / this->samplerateDivider) - samplerate))) {
  625 + fastRate = false;
  626 + this->samplerateMax = slowSamplerate;
  627 + this->samplerateDivider = slowDivider;
  628 + }
622 } 629 }
623 630
624 // Split the resulting divider into the values understood by the device 631 // Split the resulting divider into the values understood by the device
openhantek/src/hantek/types.h
@@ -96,7 +96,7 @@ namespace Hantek { @@ -96,7 +96,7 @@ namespace Hantek {
96 /// Without using fast rate mode, the samplerate is:<br /> 96 /// Without using fast rate mode, the samplerate is:<br />
97 /// <i>Samplerate = SamplerateMax / (1comp(SamplerateSlow) * 2 + Tsr1Bits.samplerateFast)</i><br /> 97 /// <i>Samplerate = SamplerateMax / (1comp(SamplerateSlow) * 2 + Tsr1Bits.samplerateFast)</i><br />
98 /// SamplerateMax is 50 MHz for the DSO-2090.<br /> 98 /// SamplerateMax is 50 MHz for the DSO-2090.<br />
99 - /// When using fast rate mode the resulting samplerate is twice as fast, when using the large buffer it is half as fast. When Tsr1Bits.bufferSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. 99 + /// When using fast rate mode the resulting samplerate is twice (For DSO-2150 three times) as fast, when using the large buffer it is half as fast. When Tsr1Bits.bufferSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. SamplerateSlow can't be used together with fast rate mode, the result is always the the same as SlowValue = 0.
100 /// </p> 100 /// </p>
101 /// <p> 101 /// <p>
102 /// The TriggerPosition sets the position of the pretrigger in samples. The left side (0 %) is 0x77660 when using the small buffer and 0x78000 when using the large buffer. 102 /// The TriggerPosition sets the position of the pretrigger in samples. The left side (0 %) is 0x77660 when using the small buffer and 0x78000 when using the large buffer.
openhantek/src/openhantek.cpp
@@ -177,7 +177,7 @@ void OpenHantekMainWindow::createActions() { @@ -177,7 +177,7 @@ void OpenHantekMainWindow::createActions() {
177 connect(this->saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); 177 connect(this->saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
178 178
179 this->printAction = new QAction(QIcon(":actions/print.png"), tr("&Print..."), this); 179 this->printAction = new QAction(QIcon(":actions/print.png"), tr("&Print..."), this);
180 - this->saveAction->setShortcut(tr("Ctrl+P")); 180 + this->printAction->setShortcut(tr("Ctrl+P"));
181 this->printAction->setStatusTip(tr("Print the oscilloscope screen")); 181 this->printAction->setStatusTip(tr("Print the oscilloscope screen"));
182 connect(this->printAction, SIGNAL(triggered()), this->dsoWidget, SLOT(print())); 182 connect(this->printAction, SIGNAL(triggered()), this->dsoWidget, SLOT(print()));
183 183