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-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e9705ca185a4
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 88bb365af2f5
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 1, 2019

  1. Updated freqresp example

    azonenberg committed Jun 1, 2019
    Copy the full SHA
    cedc1b2 View commit details
  2. Copy the full SHA
    88bb365 View commit details
Showing with 59 additions and 37 deletions.
  1. +46 −32 examples/freqresp/main.cpp
  2. +13 −5 glscopeclient/main.cpp
78 changes: 46 additions & 32 deletions examples/freqresp/main.cpp
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ int main(int argc, char* argv[])
scope.DisableChannel(0);
scope.DisableChannel(1);
scope.EnableChannel(2); //reference signal
scope.EnableChannel(3); //signal throguh probe
scope.EnableChannel(3); //signal through probe

//Measure the input frequency
FrequencyMeasurement freq_meas;
@@ -105,49 +105,63 @@ int main(int argc, char* argv[])
pp_probe.SetInput(0, scope.GetChannel(3));

//Main loop
fgen.SetFunctionChannelActive(0, true);
//fgen.SetFunctionChannelActive(0, true);
LogNotice("freq_mhz,ref_mv,probe_mv,gain_db\n");
for(float mhz = 0.5; mhz <= 10; mhz += 0.01)
//for(float mhz = 0.5; mhz <= 10; mhz += 0.01)
while(true)
{
//Configure the function generator and wait a little while (there's some lag on the output)
fgen.SetFunctionChannelFrequency(0, mhz * 1.0e6f);
//fgen.SetFunctionChannelFrequency(0, mhz * 1.0e6f);
usleep(1000 * 50);

//Acquire a waveform (TODO average a few?)
scope.StartSingleTrigger();
bool triggered = false;
for(int i=0; i<50; i++)
float actual_mhz = 0;
float amp_ref = 0;
float amp_probe = 0;
float gain_db = 0;
float navg = 5;
for(int j=0; j<navg; j++)
{
if(scope.PollTrigger() == Oscilloscope::TRIGGER_MODE_TRIGGERED)
//Acquire a waveform (TODO average a few?)
scope.StartSingleTrigger();
bool triggered = false;
for(int i=0; i<50; i++)
{
triggered = true;
if(scope.PollTrigger() == Oscilloscope::TRIGGER_MODE_TRIGGERED)
{
triggered = true;
break;
}
usleep(10 * 1000);
}
if(!triggered)
{
//LogError("Scope never triggered\n");
continue;
}
if(!scope.AcquireData())
{
LogError("Couldn't acquire data\n");
break;
}
usleep(10 * 1000);
}
if(!triggered)
{
LogError("Scope never triggered\n");
break;
}
if(!scope.AcquireData())
{
LogError("Couldn't acquire data\n");
break;
}

//Update the measurements
freq_meas.Refresh();
pp_ref.Refresh();
pp_probe.Refresh();
//Update the measurements
freq_meas.Refresh();
pp_ref.Refresh();
pp_probe.Refresh();

//Done
float actual_mhz = freq_meas.GetValue() * 1e-6f;
float amp_ref = pp_ref.GetValue();
float amp_probe = pp_probe.GetValue();
float gain_db = 10 * log10(amp_probe / amp_ref);
//Done
actual_mhz += freq_meas.GetValue() * 1e-6f;
amp_ref += pp_ref.GetValue();
amp_probe += pp_probe.GetValue();
gain_db += 20 * log10(amp_probe / amp_ref);
}

LogNotice("%f,%f,%f,%f\n", actual_mhz, amp_ref * 1000, amp_probe * 1000, gain_db);
LogNotice("%f,%f,%f,%f\n",
actual_mhz / navg,
amp_ref * 1000 / navg,
amp_probe * 1000 / navg,
gain_db / navg);
fflush(stdout);
}

return 0;
18 changes: 13 additions & 5 deletions glscopeclient/main.cpp
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
#include "../scopeprotocols/scopeprotocols.h"
#include "../scopemeasurements/scopemeasurements.h"
#include "../scopehal/LeCroyVICPOscilloscope.h"
#include "../scopehal/RigolLANOscilloscope.h"
#include "../scopehal/RigolOscilloscope.h"
#include <thread>

using namespace std;
@@ -212,7 +212,7 @@ int main(int argc, char* argv[])
if(port == 0)
port = 5555;

auto scope = new RigolLANOscilloscope(host, port);
auto scope = new RigolOscilloscope(new SCPISocketTransport(host, port));
scope->m_nickname = nick;
app->m_scopes.push_back(scope);
}
@@ -288,8 +288,8 @@ void ScopeThread(Oscilloscope* scope)
double now = GetTime();
double dt = now - tlast;
tlast = now;
LogTrace("Triggered, dt = %.3f ms (npolls = %zu, delay_ms = %.2f)\n",
dt*1000, npolls, delay_us * 0.001f);
//LogDebug("Triggered, dt = %.3f ms (npolls = %zu, delay_ms = %.2f)\n",
// dt*1000, npolls, delay_us * 0.001f);

//Adjust polling interval so that we poll a handful of times between triggers
if(npolls > 5)
@@ -308,6 +308,14 @@ void ScopeThread(Oscilloscope* scope)
delay_us = delay_min;
}

//If we have a really high trigger latency (super low bandwidth link?)
//then force the delay to be a bit higher so we have time for other threads to get to the scope
if(dt > 2000)
{
if(delay_us < 5000)
delay_us = 5000;
}

npolls = 0;
continue;
}
@@ -319,7 +327,7 @@ void ScopeThread(Oscilloscope* scope)
//If we've polled a ton of times and the delay is tiny, do a big step increase
if(npolls > 50)
{
LogTrace("Super laggy scope, bumping polling interval\n");
//LogDebug("Super laggy scope, bumping polling interval\n");
delay_us *= 10;
npolls = 0;
}