Skip to content

Commit

Permalink
issue jawi#228 - improved one wire signal tracing and adapted timing …
Browse files Browse the repository at this point in the history
…constants to better match datasheet tolerances
  • Loading branch information
tudorp committed Sep 18, 2016
1 parent 79282d4 commit 57fc151
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 " ) );

Expand All @@ -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
{
Expand All @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,28 +55,32 @@ 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 )
{
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;
Expand All @@ -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 );
}

/**
Expand Down

0 comments on commit 57fc151

Please sign in to comment.