Skip to content

Commit b4a8f9e

Browse files
authored
Merge pull request #235 from tudorp/fixonewire
issue #228 - improved one wire signal tracing and adapted timing const. @tudorp : thanks for the fix!
2 parents 79282d4 + 57fc151 commit b4a8f9e

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserTask.java

+52-7
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,28 @@ private void decodeData( final AcquisitionResult aData, final OneWireDataSet aDa
204204
// Found, lets check whether it is a valid slave presence pulse...
205205
slavePresent = this.owTiming.isSlavePresencePulse( ( nextFallingEdge - risingEdge ) * timingCorrection );
206206
}
207-
208-
// Advance the time until *after* the reset pulse...
209-
time = ( long )( fallingEdge + ( this.owTiming.getResetFrameLength() / timingCorrection ) );
207+
long ttime = ( long )( fallingEdge + ( this.owTiming.getResetFrameLength() / timingCorrection ) );
208+
if(slavePresent) {
209+
//slavePresent means there was a falling edge soon enough after the reset rising edge
210+
//so now lets look for the rising edge of the slavePresent pulse
211+
long slavePresentRisingEdge = findEdge(aData, nextFallingEdge, endOfDecode, Edge.RISING );
212+
if(slavePresentRisingEdge>0) {
213+
long nextSlotFallingEdge = findEdge(aData, slavePresentRisingEdge, endOfDecode, Edge.FALLING );
214+
if(nextSlotFallingEdge>0) {
215+
//set time one sample before the falling edge of the next slot, like accounting for the recovery time
216+
time = nextSlotFallingEdge - 1;
217+
} else {
218+
//may occur if capture ends before the begining of the next slot
219+
time = ttime;
220+
}
221+
} else {
222+
//may occur if capture ends during slavePresent pulse
223+
time = ttime;
224+
}
225+
} else {
226+
// 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)
227+
time = ttime;
228+
}
210229

211230
LOG.log( Level.FINE, "Master bus reset; slave is {0}present...", ( slavePresent ? "" : "NOT " ) );
212231

@@ -224,14 +243,12 @@ private void decodeData( final AcquisitionResult aData, final OneWireDataSet aDa
224243
if ( this.owTiming.isZero( diff ) )
225244
{
226245
// Zero bit: only update timing...
227-
time = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection ) );
228246
}
229247
else if ( this.owTiming.isOne( diff ) )
230248
{
231249
// Bytes are sent LSB first, so decode the byte as well with LSB
232250
// first...
233-
byteValue |= 0x80;
234-
time = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection ) );
251+
byteValue |= 0x80;
235252
}
236253
else
237254
{
@@ -242,7 +259,35 @@ else if ( this.owTiming.isOne( diff ) )
242259
time = fallingEdge;
243260
// Don't bother continuing; instead start over...
244261
continue;
245-
}
262+
}
263+
264+
//looking for the rising edge of the low pulse
265+
long tRisingEdge = findEdge(aData, fallingEdge, endOfDecode, Edge.RISING );
266+
long ttime = ( long )( fallingEdge + ( this.owTiming.getBitFrameLength() / timingCorrection ));
267+
if(tRisingEdge>0) {
268+
//rising edge of the pulse is within the capture
269+
// now looking for the start of the next slot
270+
long tFallingEdge = findEdge(aData, tRisingEdge, endOfDecode, Edge.FALLING );
271+
if(tFallingEdge > 0) {
272+
//start of the next slot is within the capture
273+
// ending current slot one sample before so that next slot can be identified
274+
// on the next loop
275+
time = tFallingEdge - 1;
276+
if(time>ttime) {
277+
//when the next slot starts after idle time
278+
// the current slot limit is considered the maximum slot length
279+
time = ttime;
280+
}
281+
} else {
282+
//the next slot does not start within the capture
283+
// the current slot limit is considered the maximum slot length
284+
time = ttime;
285+
}
286+
} else {
287+
//the current low pulse does not finish within the capture
288+
// the current slot limit is considered the maximum slot length
289+
time = ttime;
290+
}
246291

247292
if ( --bitCount == 0 )
248293
{

tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireTiming.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ final class OneWireTiming
3030
// VARIABLES
3131

3232
private final double aMin, aMax;
33-
private final double bMin;
33+
private final double bMin, bMax;
3434
private final double cMin, cMax;
35-
private final double dMin;
35+
private final double dMin, dMax;
3636
private final double eMax;
3737
private final double gMin;
3838
private final double hMin, hMax;
@@ -55,28 +55,32 @@ public OneWireTiming( final OneWireBusMode aMode )
5555
{
5656
// Issue #76, take 3: make the minimum level for writing a 'one' even
5757
// shorter...
58-
this.aMin = 3;
58+
this.aMin = 1;
5959
this.aMax = 15;
6060
this.bMin = 59;
61+
this.bMax = 119;
6162
this.cMin = 60;
6263
this.cMax = 120;
6364
this.dMin = 5.3;
64-
this.eMax = 9.3;
65+
this.dMax = 60;
66+
this.eMax = 0;
6567
this.gMin = 0;
6668
this.hMin = 480;
6769
this.hMax = 640;
68-
this.iMin = 60.3;
69-
this.iMax = 75.3;
70+
this.iMin = 15;
71+
this.iMax = 60;
7072
this.jMin = 410;
7173
}
7274
else if ( OneWireBusMode.OVERDRIVE == aMode )
7375
{
7476
this.aMin = 1;
7577
this.aMax = 2;
7678
this.bMin = 8;
79+
this.bMax = 15;
7780
this.cMin = 7;
7881
this.cMax = 14;
7982
this.dMin = 2.3;
83+
this.dMax = 10;
8084
this.eMax = 1.2;
8185
this.gMin = 2.5;
8286
this.hMin = 68;
@@ -100,7 +104,7 @@ else if ( OneWireBusMode.OVERDRIVE == aMode )
100104
*/
101105
public double getBitFrameLength()
102106
{
103-
return Math.max( this.aMin + this.bMin, this.cMin + this.dMin );
107+
return Math.max( this.aMin + this.bMax, this.cMin + this.dMax );
104108
}
105109

106110
/**

0 commit comments

Comments
 (0)