Search This Blog

Saturday, July 28, 2018

Project Swiftlet - Digital Rangefinder

Projects / Project Swiftlet  Original post date: 09/08/2015


I implement the sonar (analog) routine first to get a feel on the raw data.
  • Objects that have planar surface tends to return a reflection that have a quick rise time and exponential fall time in the envelope.
  • smaller objects/irregular objects have a more elliptical envelope.
  • Larger objects returns higher amplitudes
Do I simply return the first echo? Here is what I think:


I can use the analog comparator peripheral in the ARM. Initially, the threshold is set at around -0.75, then it is slowly increase to the steady state value. The variable comparator threshold is to ignore the ringing at the transmitter while trying to accommodate close range detection.

This is what the received signal looks like when there are no immediate obstacles. It picks up the ping from the transmitter right next to it and I am using that and the subsequent echo from my target to calculate the distance. This zeros out the time delay for the transmitter to build up its amplitude and the propagation delay of the analog circuits.

Top trace: Output of the analog comparator. In order to measure very close distances, I have to change the threshold of the comparator on the fly to be just outside of the envelope. If there is an object within that close range, the resulting echo will be strong enough to trigger the comparator. (see 2nd scope picture below)

My next step is to implement that variable threshold and if my code works, the comparator output would be clear after the first 500us or so, but still be able to detect a small object further out..


Note to self: This is around time when my regular scope blew up due to the hot summer temperature.  This is my old scope.

I can program in the analog threshold via the 6-bit DAC feeding the comparator. I am looking at he bottom half of the waveform. If the input analog voltage is below my voltage threshold, the comparator output goes high. There is an optional programmable glitch filter that can use to remove glitches.

The top trace of the scope picture shows the comparator output. The comparator output then trigger an interrupt and that very first pulse can trigger TPM input capture.


My quick and dirty measurement of what seems to be a minimum distance that I can measure. 4" or 10cm. That distance is where I can distinctly see a reflection coming back.



I tired a lot of things to get the analog comparator to work, but in the end it wasn't reliable enough.
I have inconsistent triggering of the voltage levels.
I have mis-triggering when I am changing the threshold with the 6-bit DAC. If I program the filter to eliminate the glitch, I start having problem not seeing triggers.


This is where the fine prints part that kills it for me: "Analog comparator initialization delay" means it would take up to 40us to settle down if I change the DAC! i.e. the DAC settling time plus worse case propagation delay etc This 40us window makes changing the threshold on the fly not reliable enough for my application. The 12-bit DAC is slightly faster on high power mode 15us (typ), but I had enough fooling around with analog comparators.

Fortunately, this is not the end of the story. There is a digital comparator inside the ADC block. It can be enabled to compare the ADC results with the threshold set in a register and cause an interrupt. This completely gets around the issues with analog comparator. The fastest 8-bit continuous conversion rate at ~11MHz Bus Clock takes 1.621 us. That's a tiny faction of a wavelength of the 40kHz signal and is below what can be resolved. I can live with the results - see the scope pictures below.


I toggle the GPIO line (top trace) where I start/stop the timer for debugging.


This shows the sensitivity of the trigger. That small echo is cause by the surface of the scope.


This is the table that I used to change the threshold on the fly. The units are in mV and seconds. It is a staircase threshold set outside the ringing of the transmit pulse. The values can be change to make the range finder more or less sensitive to echoes.


const uint8_t ADC0_Threshold[]=
{
 SONAR_ADC8_THRESHOLD(500UL),
 SONAR_ADC8_THRESHOLD(1200UL),
 SONAR_ADC8_THRESHOLD(1400UL)
};

const uint16_t Threshold_SetTime[] = 
{
 SONAR_TPM1_COUNT(600e-6),
 SONAR_TPM1_COUNT(1000e-6),
 SONAR_TPM1_COUNT(2000e-6)
};

This is the back of the chair at 10cm (4"). That's the point where the interrupt is re-enable. I might tweak back another 30us where that happens, but the number is close. 600us/2 x 340m/s = 10.2cm

Firmware progress 2 - Acoustics & Mechanical original post date: 09/16/2015

This is the break out board for the left hand side connected to the main PCB via a long ribbon cable.

This is the captured waveform. The receive waveform is quite a bit different due to the mechanical difference as the sensor PCb is only hanging on one edge, so there is little mechanical damping of the PCB.


So I mount the Sensor PCB in the Stickvise:

Mounting left side PCB in stick vise
This is what I got:

This little experiment tells me that those are cause by the vibration of the PCB!

I tried to isolate the transducer from the pcb by not mounting them flush. Here is what the waveform now looks like (without the stickvise). So while those extra vibrations are eliminated, the transducer takes longer to stop ringing.


So I went back to flush mounting the transducers. Replace the header connecting the boards while under the clamp so that the sensor PCB is mounted flush to the breakout PCB. I then glued the two PCB together with superglue.


Now added a 4.7K resistor across the receiver at the two solder jumper point. The resistor electrically damps out the receiver, so it helps quite a bit at the expense of losing a bit of sensitivity.


It is not perfect, but with a bit of tweak in that table values, I can make this work.

I changed the resistor to 22K as the sensitivity with the 4.7K as poor. The blind spot is increased to 1ms which is about 17cm (6.7"). The maximum range is at 5m and the signal was getting very weak. I have consistent result that agrees with the scope for both channels.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.