Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c03b4941f8d8
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7ac567162ff9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jun 12, 2020

  1. Copy the full SHA
    ff1a2e1 View commit details
  2. Merge pull request #149 from tomverbeure/siglent_volt_div_bug

    Adjust VOLT_DIV if initial try is incorrect.
    azonenberg authored Jun 12, 2020
    Copy the full SHA
    7ac5671 View commit details
Showing with 67 additions and 0 deletions.
  1. +62 −0 scopehal/SiglentSCPIOscilloscope.cpp
  2. +5 −0 scopehal/SiglentSCPIOscilloscope.h
62 changes: 62 additions & 0 deletions scopehal/SiglentSCPIOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ using namespace std;
SiglentSCPIOscilloscope::SiglentSCPIOscilloscope(SCPITransport* transport)
: LeCroyOscilloscope(transport)
, m_acquiredDataIsSigned(false)
, m_hasVdivAttnBug(true)
{
if (m_modelid == MODEL_SIGLENT_SDS2000X)
{
@@ -60,6 +61,67 @@ string SiglentSCPIOscilloscope::GetDriverNameInternal()
return "siglent";
}

void SiglentSCPIOscilloscope::SetChannelVoltageRange(size_t i, double range)
{
lock_guard<recursive_mutex> lock(m_mutex);

// FIXME: this assumes there are 8 vertical DIVs on the screen. Should this become a per-SKU parameter?
double wantedVdiv = range / 8;
m_channelVoltageRanges[i] = range;

// A Siglent SDS2304X has the 2 firmware bugs (FW 1.2.2.2 R19)
//
// When you program a VOLT_DIV of x, it actually sets a VOLT_DIV of x * probe_attenuation.
// That's the value that will show up to the scope UI and also the value that gets read back
// for VOLT_DIV?.
// So the bug only happens when sending VOLT_DIV, but not when reading it.
//
// The other bug is that, sometimes, programming VOLT_DIV just doesn't work: the value
// gets ignored. However, when you do a VOLT_DIV? immediately after a VOLT_DIV, then
// it always seems to work.
//
// It's unclear which SKUs and FW version have this bug.
//
// The following work around should be work for all scopes, whether they have the bug or not:
// 1. Program the desired value
// 2. Read it back the actual value
// 3. Program the value again, but this time adjusted by the ratio between desired and actual value.
// 4. Read back the value again to make sure it held
//
// The only disadvantage to this is that UI on the scope will update twice.
//
// A potential improvement would be to check at the start if the scope exhibits this bug...

char cmd[128];
snprintf(cmd, sizeof(cmd), "%s:VOLT_DIV %.4f", m_channels[i]->GetHwname().c_str(), wantedVdiv);
m_transport->SendCommand(cmd);

snprintf(cmd, sizeof(cmd), "%s:VOLT_DIV?", m_channels[i]->GetHwname().c_str());
m_transport->SendCommand(cmd);

string resultStr = m_transport->ReadReply();
double actVdiv;
sscanf(resultStr.c_str(), "%lf", &actVdiv);

if (!m_hasVdivAttnBug)
return;

double adjustVdiv = wantedVdiv / actVdiv;

snprintf(cmd, sizeof(cmd), "%s:VOLT_DIV %.4f", m_channels[i]->GetHwname().c_str(), wantedVdiv * adjustVdiv);
m_transport->SendCommand(cmd);

snprintf(cmd, sizeof(cmd), "%s:VOLT_DIV?", m_channels[i]->GetHwname().c_str());
m_transport->SendCommand(cmd);

resultStr = m_transport->ReadReply();
sscanf(resultStr.c_str(), "%lf", &actVdiv);

adjustVdiv = wantedVdiv / actVdiv;

LogDebug("Wanted VOLT_DIV: %lf, Actual VOLT_DIV: %lf, ratio: %lf \n", wantedVdiv, actVdiv, adjustVdiv);
}

// Somewhat arbitrary. No header has been seen that's larger than 17...
static const int maxWaveHeaderSize = 40;

5 changes: 5 additions & 0 deletions scopehal/SiglentSCPIOscilloscope.h
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ class SiglentSCPIOscilloscope
SiglentSCPIOscilloscope(SCPITransport* transport);
virtual ~SiglentSCPIOscilloscope();

virtual void SetChannelVoltageRange(size_t i, double range);

virtual bool AcquireData(bool toQueue);

protected:
@@ -58,10 +60,13 @@ class SiglentSCPIOscilloscope
int ReadWaveHeader(char *header);

bool m_acquiredDataIsSigned;
bool m_hasVdivAttnBug;

public:
static std::string GetDriverNameInternal();

OSCILLOSCOPE_INITPROC(SiglentSCPIOscilloscope)

};

#pragma pack(1)