From 57fc1513cf4f56c6fb48ca7a443f2aacd914e351 Mon Sep 17 00:00:00 2001 From: Tudor Date: Sun, 18 Sep 2016 18:35:19 +0300 Subject: [PATCH] issue #228 - improved one wire signal tracing and adapted timing constants to better match datasheet tolerances --- .../ols/tool/onewire/OneWireAnalyserTask.java | 59 ++++++++++++++++--- .../ols/tool/onewire/OneWireTiming.java | 18 +++--- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java b/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java index 3c79855e..5db19743 100644 --- a/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java +++ b/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java @@ -204,9 +204,28 @@ private void decodeData( final AcquisitionResult aData, final OneWireDataSet aDa // Found, lets check whether it is a valid slave presence pulse... slavePresent = this.owTiming.isSlavePresencePulse( ( nextFallingEdge - risingEdge ) * timingCorrection ); } - - // Advance the time until *after* the reset pulse... - time = ( long )( fallingEdge + ( this.owTiming.getResetFrameLength() / timingCorrection ) ); + long ttime = ( long )( fallingEdge + ( this.owTiming.getResetFrameLength() / timingCorrection ) ); + if(slavePresent) { + //slavePresent means there was a falling edge soon enough after the reset rising edge + //so now lets look for the rising edge of the slavePresent pulse + long slavePresentRisingEdge = findEdge(aData, nextFallingEdge, endOfDecode, Edge.RISING ); + if(slavePresentRisingEdge>0) { + long nextSlotFallingEdge = findEdge(aData, slavePresentRisingEdge, endOfDecode, Edge.FALLING ); + if(nextSlotFallingEdge>0) { + //set time one sample before the falling edge of the next slot, like accounting for the recovery time + time = nextSlotFallingEdge - 1; + } else { + //may occur if capture ends before the begining of the next slot + time = ttime; + } + } else { + //may occur if capture ends during slavePresent pulse + time = ttime; + } + } else { + // Advance the time until *after* the reset pulse... (in case a better criteria was not matched above, since this method does not account for admisable parmeter variation) + time = ttime; + } LOG.log( Level.FINE, "Master bus reset; slave is {0}present...", ( slavePresent ? "" : "NOT " ) ); @@ -224,14 +243,12 @@ private void decodeData( final AcquisitionResult aData, final OneWireDataSet aDa if ( this.owTiming.isZero( diff ) ) { // Zero bit: only update timing... - time = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection ) ); } else if ( this.owTiming.isOne( diff ) ) { // Bytes are sent LSB first, so decode the byte as well with LSB // first... - byteValue |= 0x80; - time = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection ) ); + byteValue |= 0x80; } else { @@ -242,7 +259,35 @@ else if ( this.owTiming.isOne( diff ) ) time = fallingEdge; // Don't bother continuing; instead start over... continue; - } + } + + //looking for the rising edge of the low pulse + long tRisingEdge = findEdge(aData, fallingEdge, endOfDecode, Edge.RISING ); + long ttime = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection )); + if(tRisingEdge>0) { + //rising edge of the pulse is within the capture + // now looking for the start of the next slot + long tFallingEdge = findEdge(aData, tRisingEdge, endOfDecode, Edge.FALLING ); + if(tFallingEdge > 0) { + //start of the next slot is within the capture + // ending current slot one sample before so that next slot can be identified + // on the next loop + time = tFallingEdge - 1; + if(time>ttime) { + //when the next slot starts after idle time + // the current slot limit is considered the maximum slot length + time = ttime; + } + } else { + //the next slot does not start within the capture + // the current slot limit is considered the maximum slot length + time = ttime; + } + } else { + //the current low pulse does not finish within the capture + // the current slot limit is considered the maximum slot length + time = ttime; + } if ( --bitCount == 0 ) { diff --git a/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireTiming.java b/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireTiming.java index 53fc9398..1a8b443b 100644 --- a/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireTiming.java +++ b/tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireTiming.java @@ -30,9 +30,9 @@ final class OneWireTiming // VARIABLES private final double aMin, aMax; - private final double bMin; + private final double bMin, bMax; private final double cMin, cMax; - private final double dMin; + private final double dMin, dMax; private final double eMax; private final double gMin; private final double hMin, hMax; @@ -55,18 +55,20 @@ public OneWireTiming( final OneWireBusMode aMode ) { // Issue #76, take 3: make the minimum level for writing a 'one' even // shorter... - this.aMin = 3; + this.aMin = 1; this.aMax = 15; this.bMin = 59; + this.bMax = 119; this.cMin = 60; this.cMax = 120; this.dMin = 5.3; - this.eMax = 9.3; + this.dMax = 60; + this.eMax = 0; this.gMin = 0; this.hMin = 480; this.hMax = 640; - this.iMin = 60.3; - this.iMax = 75.3; + this.iMin = 15; + this.iMax = 60; this.jMin = 410; } else if ( OneWireBusMode.OVERDRIVE == aMode ) @@ -74,9 +76,11 @@ else if ( OneWireBusMode.OVERDRIVE == aMode ) this.aMin = 1; this.aMax = 2; this.bMin = 8; + this.bMax = 15; this.cMin = 7; this.cMax = 14; this.dMin = 2.3; + this.dMax = 10; this.eMax = 1.2; this.gMin = 2.5; this.hMin = 68; @@ -100,7 +104,7 @@ else if ( OneWireBusMode.OVERDRIVE == aMode ) */ public double getBitFrameLength() { - return Math.max( this.aMin + this.bMin, this.cMin + this.dMin ); + return Math.max( this.aMin + this.bMax, this.cMin + this.dMax ); } /**