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: 9a27ea7c3f0f
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d3a0f1fd3f53
Choose a head ref
  • 1 commit
  • 8 files changed
  • 1 contributor

Commits on Oct 1, 2020

  1. Added TachometerFilter. Fixes #294. Fixed bug causing frequency measu…

    …rement to have incorrect sample duration
    azonenberg committed Oct 1, 2020
    Copy the full SHA
    d3a0f1f View commit details
3 changes: 3 additions & 0 deletions scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -144,6 +144,9 @@ string Unit::PrettyPrint(double value)
case UNIT_UI:
unit = "UI";
break;
case UNIT_RPM:
unit = "RPM";
break;

//Degrees do not use SI prefixes
case UNIT_DEGREES:
1 change: 1 addition & 0 deletions scopehal/Unit.h
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ class Unit
UNIT_WATTS, //Power
UNIT_UI, //Unit interval (relative to signal bit rate)
UNIT_DEGREES, //Angular degrees
UNIT_RPM, //Revolutions per minute

UNIT_MILLIVOLTS, //Hack needed for voltage in the X axis since we use integer coordinates there

1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ set(SCOPEPROTOCOLS_SOURCES
SPIDecoder.cpp
SPIFlashDecoder.cpp
SubtractFilter.cpp
TachometerFilter.cpp
ThresholdFilter.cpp
TIEMeasurement.cpp
TMDSDecoder.cpp
11 changes: 6 additions & 5 deletions scopeprotocols/FrequencyMeasurement.cpp
Original file line number Diff line number Diff line change
@@ -136,14 +136,15 @@ void FrequencyMeasurement::Refresh()
double start = edges[i];
double end = edges[i+2];

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

cap->m_offsets.push_back(start);
cap->m_durations.push_back(delta);
cap->m_samples.push_back(delta);
cap->m_durations.push_back(round(delta));
cap->m_samples.push_back(freq);

rmin = min(rmin, delta);
rmax = max(rmax, delta);
rmin = min(rmin, freq);
rmax = max(rmax, freq);
}

m_range = rmax - rmin;
170 changes: 170 additions & 0 deletions scopeprotocols/TachometerFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include "scopeprotocols.h"
#include "TachometerFilter.h"

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

TachometerFilter::TachometerFilter(string color)
: Filter(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_MISC)
{
m_yAxisUnit = Unit(Unit::UNIT_RPM);

//Set up channels
CreateInput("din");

m_midpoint = 0.5;
m_range = 1;

m_ticksname = "Pulses per revolution";
m_parameters[m_ticksname] = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_COUNTS));
m_parameters[m_ticksname].SetIntVal(1);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory methods

bool TachometerFilter::ValidateChannel(size_t i, StreamDescriptor stream)
{
if(stream.m_channel == NULL)
return false;

if( (i == 0) && (stream.m_channel->GetType() == OscilloscopeChannel::CHANNEL_TYPE_ANALOG) )
return true;

return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void TachometerFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "Tachometer(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string TachometerFilter::GetProtocolName()
{
return "Tachometer";
}

bool TachometerFilter::IsOverlay()
{
//we create a new analog channel
return false;
}

bool TachometerFilter::NeedsConfig()
{
return true;
}

double TachometerFilter::GetVoltageRange()
{
return m_range;
}

double TachometerFilter::GetOffset()
{
return -m_midpoint;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void TachometerFilter::Refresh()
{
//Make sure we've got valid inputs
if(!VerifyAllInputsOKAndAnalog())
{
SetData(NULL, 0);
return;
}
auto din = GetAnalogInputWaveform(0);

//Find average voltage of the waveform and use that as the zero crossing
float midpoint = GetAvgVoltage(din);

//Timestamps of the edges
vector<double> edges;
FindZeroCrossings(din, midpoint, edges);
if(edges.size() < 2)
{
SetData(NULL, 0);
return;
}

//Create the output
auto cap = new AnalogWaveform;

int64_t pulses_per_rev = m_parameters[m_ticksname].GetIntVal();
float pulses_to_rpm = 60.0f / pulses_per_rev;

double rmin = FLT_MAX;
double rmax = 0;
size_t elen = edges.size();
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
double start = edges[i];
double end = edges[i+2];

double delta = end - start;
double freq = 1.0e12 / delta;
double rpm = freq * pulses_to_rpm;

cap->m_offsets.push_back(start);
cap->m_durations.push_back(round(delta));
cap->m_samples.push_back(rpm);

rmin = min(rmin, rpm);
rmax = max(rmax, rpm);
}

m_range = rmax - rmin;
m_midpoint = rmin + m_range/2;

//minimum scale
if(m_range < 0.001*m_midpoint)
m_range = 0.001*m_midpoint;

SetData(cap, 0);

//Copy start time etc from the input. Timestamps are in picoseconds.
cap->m_timescale = 1;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startPicoseconds = din->m_startPicoseconds;
}
65 changes: 65 additions & 0 deletions scopeprotocols/TachometerFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of TachometerFilter
*/
#ifndef TachometerFilter_h
#define TachometerFilter_h

class TachometerFilter : public Filter
{
public:
TachometerFilter(std::string color);

virtual void Refresh();

virtual bool NeedsConfig();
virtual bool IsOverlay();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual double GetVoltageRange();
virtual double GetOffset();

virtual bool ValidateChannel(size_t i, StreamDescriptor stream);

PROTOCOL_DECODER_INITPROC(TachometerFilter)

protected:
double m_midpoint;
double m_range;

std::string m_ticksname;
};

#endif
3 changes: 2 additions & 1 deletion scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -98,8 +98,9 @@ void ScopeProtocolStaticInit()
AddDecoderClass(SPIDecoder);
AddDecoderClass(SPIFlashDecoder);
AddDecoderClass(SubtractFilter);
AddDecoderClass(TIEMeasurement);
AddDecoderClass(TachometerFilter);
AddDecoderClass(ThresholdFilter);
AddDecoderClass(TIEMeasurement);
AddDecoderClass(TMDSDecoder);
AddDecoderClass(TopMeasurement);
AddDecoderClass(UARTDecoder);
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.h
Original file line number Diff line number Diff line change
@@ -98,6 +98,7 @@
#include "SPIDecoder.h"
#include "SPIFlashDecoder.h"
#include "SubtractFilter.h"
#include "TachometerFilter.h"
#include "ThresholdFilter.h"
#include "TIEMeasurement.h"
#include "TMDSDecoder.h"