# Short post on Successful data out of OSLRF-01 Laser Range Finder

March 3, 2014

It's late and I'm going to bed. My eyes are blurry, and I've got a headache... but!!!

I'm getting reliable (for the most part) Distance readings out of the OSLRF-01 as evidenced here in my putty dump. The "ACTUAL" distance to target was in fact 2.67m. I've got a fairly consistent reflection or ghost at 0.67 and few more stragglers that I will work to filter, but I'm quite pleased.

Thank you once again ** LightWare Optoelectronics ...**

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2014.03.03 22:06:02 =~=~=~=~=~=~=~=~=~=~=~=

RST, Running oslrf01_rawdata - State Machine. 140303

Timebase Control set to 20

12, zeroCenter = 0 returnCenter = 0 Delta = 0 SyncWidth = 0 Distance = 0.00

114, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21464 Distance = 0.67

215, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19416 Distance = 2.67

317, zeroCenter = 448 returnCenter = 1008 Delta = 560 SyncWidth = 21464 Distance = 0.48

419, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 2.67

520, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21480 Distance = 0.67

622, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19424 Distance = 2.67

724, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

825, zeroCenter = 240 returnCenter = 3072 Delta = 2832 SyncWidth = 19432 Distance = 2.67

927, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 2.67

1028, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 19432 Distance = 0.74

1130, zeroCenter = 224 returnCenter = 3056 Delta = 784 SyncWidth = 21488 Distance = 0.67

1232, zeroCenter = 224 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 2.67

1333, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 0.67

1435, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 19432 Distance = 2.67

1536, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 2.67

1638, zeroCenter = 240 returnCenter = 1024 Delta = 784 SyncWidth = 21472 Distance = 0.67

1740, zeroCenter = 240 returnCenter = 3072 Delta = 2832 SyncWidth = 19432 Distance = 2.67

1841, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

1943, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

2045, zeroCenter = 240 returnCenter = 1024 Delta = 784 SyncWidth = 21472 Distance = 0.67

2146, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

2248, zeroCenter = 464 returnCenter = 3072 Delta = 2608 SyncWidth = 19424 Distance = 2.46

2349, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21472 Distance = 0.67

2451, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19416 Distance = 2.67

2553, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21464 Distance = 0.67

2654, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19416 Distance = 2.67

2756, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21472 Distance = 0.67

2859, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19416 Distance = 2.67

2961, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21456 Distance = 0.67

3063, zeroCenter = 456 returnCenter = 1016 Delta = 560 SyncWidth = 19408 Distance = 2.67

3164, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19408 Distance = 2.67

3266, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21472 Distance = 0.67

3368, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19440 Distance = 2.67

3469, zeroCenter = 240 returnCenter = 1024 Delta = 784 SyncWidth = 21488 Distance = 0.67

3571, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19440 Distance = 2.67

3672, zeroCenter = 240 returnCenter = 1024 Delta = 784 SyncWidth = 21480 Distance = 0.67

3774, zeroCenter = 232 returnCenter = 2840 Delta = 2608 SyncWidth = 19424 Distance = 2.46

3876, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21472 Distance = 0.67

3977, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19424 Distance = 2.67

4079, zeroCenter = 224 returnCenter = 2832 Delta = 2608 SyncWidth = 21472 Distance = 2.23

4182, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 19432 Distance = 0.74

4284, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19432 Distance = 2.67

4386, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

4487, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

4589, zeroCenter = 240 returnCenter = 1024 Delta = 784 SyncWidth = 21464 Distance = 0.67

4691, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19416 Distance = 2.67

4792, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21464 Distance = 0.67

4894, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19432 Distance = 2.67

4995, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21488 Distance = 0.67

5097, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19432 Distance = 2.67

5199, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19424 Distance = 2.67

5300, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21480 Distance = 0.67

5402, zeroCenter = 240 returnCenter = 3072 Delta = 2832 SyncWidth = 19440 Distance = 2.67

5505, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21472 Distance = 0.67

5607, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

5709, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

5810, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19432 Distance = 2.67

5912, zeroCenter = 224 returnCenter = 784 Delta = 560 SyncWidth = 21472 Distance = 0.48

6014, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19416 Distance = 2.67

6115, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

6217, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19440 Distance = 2.67

6318, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21480 Distance = 0.67

6420, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19440 Distance = 2.67

6522, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21488 Distance = 0.67

6623, zeroCenter = 240 returnCenter = 3072 Delta = 2832 SyncWidth = 21480 Distance = 2.42

6725, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

6828, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 19432 Distance = 0.74

6930, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19424 Distance = 2.67

7032, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21456 Distance = 0.67

7133, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19400 Distance = 2.68

7235, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21448 Distance = 0.67

7337, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 19432 Distance = 0.74

7438, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19464 Distance = 2.67

7540, zeroCenter = 240 returnCenter = 3056 Delta = 2832 SyncWidth = 19448 Distance = 2.67

7641, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 19432 Distance = 0.74

7743, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19424 Distance = 2.67

7845, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21464 Distance = 0.67

7946, zeroCenter = 240 returnCenter = 3072 Delta = 2832 SyncWidth = 19424 Distance = 2.67

8048, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21464 Distance = 0.67

8151, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19432 Distance = 2.67

8253, zeroCenter = 232 returnCenter = 1016 Delta = 784 SyncWidth = 21472 Distance = 0.67

8355, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19416 Distance = 2.67

8456, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 21448 Distance = 2.42

8558, zeroCenter = 464 returnCenter = 1024 Delta = 560 SyncWidth = 21464 Distance = 0.48

8660, zeroCenter = 232 returnCenter = 3064 Delta = 2832 SyncWidth = 19416 Distance = 2.67

8761, zeroCenter = 224 returnCenter = 1008 Delta = 784 SyncWidth = 21456 Distance = 0.67

8863, zeroCenter = 224 returnCenter = 3056 Delta = 2832 SyncWidth = 19416 Distance = 2.67

8964, zeroCenter = 232 returnCenter = 1240 Delta = 1008 SyncWidth = 21464 Distance = 0.86

Now... sleep... night all...

## Very cool. I am curious

Very cool. I am curious what the manufacturer would have to say about the reflected measurements.

## I suspect they would tell me to check my sample timing

Woke up in the middle of the night thinking about it. I suspect it's artifact of ADC sampling .

We'll find out tonight.

Cheers.

## You might want to check the sampling timing...

During software development it's sometimes easier to separate out each of the signals - the Sync, Zero and Return, and bring them into the program one at a time. You can get a lot of clarity about the timing of the data sampling this way.

The Sync is a stable square wave that drifts slowly with changes in temperature. It represents the update rate and also indicates the time=0 point for ADC sampling. The Sync can be kept at an exact frequency by adjusting the voltage on the Control input using a software control loop. The software can "count" the duration of the Sync using the Convert as a clock (31.7225kHz) and knowing this count value it's possible to write a simple "proportional" control routine that holds the Sync frequency at the required update rate. e.g. For an update rate of 35Hz, the software would adjust the Control voltage until there were about 906 Convert signals for each Sync cycle.

Once the update rate is stable, the software can use the Convert clock to trigger ADC conversions of the Zero and Return signals. The advantage of using the Convert, instead of a random sampling frequency, is that it is precisely synchronised with the SETS (sequential, equivalent, time sampling) circuit which results in a better SNR.

The best way to test the ADC conversion routine is by sampling the Zero signal. This signal should remain very stable, meaning that the leading and trailing edges don't move very much. In practice, you may decide to use a constant value for the time of the outgoing laser pulse because there is only a small temperature coefficient. For software debugging however, it's a useful signal to test out the ADC sampling because you can expect consistent results. Using the earlier example of 35 readings per second, by synchronising the ADC to the Convert signal you would expect 906 samples for each full measurement. The easiest way to analyse these samples is to post-process them after storing the results in memory. This method has the added advantage that you can do a memory dump of the Zero pulse and draw a graph of the waveform using a spreadsheet program. One look at this graph and you can see that it has the most increadible resolution, considering that you're measuring a pulse that is only 15ns long.

Once the Sync and Zero are under control, collecting and anlysing the Return signal becomes straight forward. However, unlike the Zero, the Return is a very dynamic signal, changing size and shape with distance and surface reflectivity. Coming up with an algorithm to analyse this signal is where the fun really begins :)

## Very much what I had thought.

I *am* using the Convert Signal to time through the duration of SyncLow however....

I admit to the terrible habit of

" while (ZeroValue=analogRead(ZERO) < ZEROPRESET)"Wasting precious CPU resampling until thresholds. This was intended to *just get it providing results*. It would be more reasonable to sample on falling edge of CONVERT. I will update this tonight.With a PWM signal into CONTROL, I have found both SyncWidth and ZeroTimeRise to be very consistent. It only seems to drift if I allow CONTROL to float. (Makes sense, really...) I Was trying to see how few pins I could do this in. For the average Hobby Roboticist, Pin count and Cycle counts are pretty much all that matter.

For instance, if I'm *just* using the CONVERT interrupt, and have locked CONTROL, It seems that I can almost make a leap of faith and simply take the time from ZeroTimeRise to ReturnTimeRise... Both of which assume the slight delay from SyncLow edge.

Anyway, thank you for a wonderful opportunity.

## My pleasure, I hope you have fun!

The simplest configuration that works with reasonable accuracy needs three signal connections: Convert, Zero and Return as you have correctly deduced. The rising edge of the Zero can be used as the time=0 datum and the number of Converts between these rising edges is the "scale" of the result.

Leave the Control floating and the unit will default to around 30Hz. It doesn't matter if it drifts a little because this alters the count value of the scale, which is used as the denominator in the ratiometric conversion of counts into distance. The Return should be captured as both the rising edge and the falling edge in order to include some signal strength correction.

There are quite a few permutations of connections that can work. Once you realise that there is no such thing as an absolute time=0 then taking relative measurements starts to make sense, and this allows you to choose any suitable event as the datum. Your "leap of faith" is great engineering intuition!