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

Commits on Jul 30, 2020

  1. Copy the full SHA
    ad8d3a5 View commit details
  2. Copy the full SHA
    5ca71d9 View commit details
35 changes: 34 additions & 1 deletion scopehal/ProtocolDecoder.cpp
Original file line number Diff line number Diff line change
@@ -631,7 +631,7 @@ void ProtocolDecoder::SampleOnAnyEdges(DigitalBusWaveform* data, DigitalWaveform
*/
void ProtocolDecoder::FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<int64_t>& edges)
{
//Find times of the zero crossings (TODO: extract this into reusable function)
//Find times of the zero crossings
bool first = true;
bool last = false;
int64_t phoff = data->m_timescale/2 + data->m_triggerPhase;
@@ -659,6 +659,39 @@ void ProtocolDecoder::FindZeroCrossings(AnalogWaveform* data, float threshold, s
}
}

/**
@brief Find zero crossings in a waveform, interpolating as necessary
*/
void ProtocolDecoder::FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<double>& edges)
{
//Find times of the zero crossings
bool first = true;
bool last = false;
double phoff = data->m_timescale/2 + data->m_triggerPhase;
size_t len = data->m_samples.size();
for(size_t i=1; i<len; i++)
{
bool value = data->m_samples[i] > threshold;

//Save the last value
if(first)
{
last = value;
first = false;
continue;
}

//Skip samples with no transition
if(last == value)
continue;

//Midpoint of the sample, plus the zero crossing
double t = phoff + data->m_timescale * (data->m_offsets[i] + InterpolateTime(data, i-1, threshold));
edges.push_back(t);
last = value;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

1 change: 1 addition & 0 deletions scopehal/ProtocolDecoder.h
Original file line number Diff line number Diff line change
@@ -249,6 +249,7 @@ class ProtocolDecoder : public OscilloscopeChannel

//Find interpolated zero crossings of a signal
void FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<int64_t>& edges);
void FindZeroCrossings(AnalogWaveform* data, float threshold, std::vector<double>& edges);

public:
typedef ProtocolDecoder* (*CreateProcType)(std::string);
6 changes: 3 additions & 3 deletions scopeprotocols/ClockRecoveryDecoder.cpp
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ void ClockRecoveryDecoder::Refresh()
double start = GetTime();

//Timestamps of the edges
vector<int64_t> edges;
vector<double> edges;
FindZeroCrossings(din, m_parameters[m_threshname].GetFloatVal(), edges);

if(edges.empty())
@@ -213,12 +213,12 @@ void ClockRecoveryDecoder::Refresh()
//See if the next edge occurred in this UI.
//If not, just run the NCO open loop.
//Allow multiple edges in the UI if the frequency is way off.
int64_t tnext = edges[nedge];
double tnext = edges[nedge];
cycles_open_loop ++;
while( (tnext + center < edgepos) && (nedge+1 < edges.size()) )
{
//Find phase error
int64_t delta = (edgepos - tnext) - period;
double delta = (edgepos - tnext) - period;
total_error += fabs(delta);

//If the clock is currently gated, re-sync to the edge
5 changes: 2 additions & 3 deletions scopeprotocols/FallMeasurementDecoder.cpp
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ void FallMeasurementDecoder::Refresh()
{
if( (cur < vstart) && (last >= vstart) )
{
tedge = tnow - din->m_timescale + InterpolateTime(din, i-1, vstart);
tedge = tnow - din->m_timescale + InterpolateTime(din, i-1, vstart)*din->m_timescale;
state = 1;
}
}
@@ -174,8 +174,7 @@ void FallMeasurementDecoder::Refresh()
{
if( (cur < vend) && (last >= vend) )
{
double tlerp = tnow - din->m_timescale + InterpolateTime(din, i-1, vend);
double dt = tlerp - tedge;
double dt = InterpolateTime(din, i-1, vend)*din->m_timescale + tnow - din->m_timescale - tedge;

cap->m_offsets.push_back(tlast);
cap->m_durations.push_back(tnow - tlast);
6 changes: 3 additions & 3 deletions scopeprotocols/FrequencyMeasurementDecoder.cpp
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ void FrequencyMeasurementDecoder::Refresh()
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<int64_t> edges;
vector<double> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
@@ -143,8 +143,8 @@ void FrequencyMeasurementDecoder::Refresh()
for(size_t i=0; i < (elen - 2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
int64_t start = edges[i];
int64_t end = edges[i+2];
double start = edges[i];
double end = edges[i+2];

double delta = 1.0e12 / (end - start);

6 changes: 3 additions & 3 deletions scopeprotocols/PeriodMeasurementDecoder.cpp
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ void PeriodMeasurementDecoder::Refresh()
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<int64_t> edges;
vector<double> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
@@ -143,8 +143,8 @@ void PeriodMeasurementDecoder::Refresh()
for(size_t i=0; i < (edges.size()-2); i+= 2)
{
//measure from edge to 2 edges later, since we find all zero crossings regardless of polarity
int64_t start = edges[i];
int64_t end = edges[i+2];
double start = edges[i];
double end = edges[i+2];

double delta = end - start;
cap->m_offsets.push_back(start);
5 changes: 2 additions & 3 deletions scopeprotocols/RiseMeasurementDecoder.cpp
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ void RiseMeasurementDecoder::Refresh()
{
if( (cur > vstart) && (last <= vstart) )
{
tedge = tnow - din->m_timescale + InterpolateTime(din, i-1, vstart);
tedge = tnow - din->m_timescale + InterpolateTime(din, i-1, vstart)*din->m_timescale;
state = 1;
}
}
@@ -174,8 +174,7 @@ void RiseMeasurementDecoder::Refresh()
{
if( (cur > vend) && (last <= vend) )
{
double tlerp = tnow - din->m_timescale + InterpolateTime(din, i-1, vend);
double dt = tlerp - tedge;
double dt = InterpolateTime(din, i-1, vend)*din->m_timescale + tnow - din->m_timescale - tedge;

cap->m_offsets.push_back(tlast);
cap->m_durations.push_back(tnow-tlast);