Ultrasonic sensing -- trying to get a "smooth" output for A/D conversion

Discussion in 'The Projects Forum' started by Daniel McMath, Apr 10, 2016.

  1. Daniel McMath

    Thread Starter New Member

    Dec 28, 2015
    3
    0
    Through studying other posts on this forum (and elsewhere), I've built a circuit like the attached diagram. I ping for about 80usec, then listen for the response -- pretty simple stuff. On the o-scope, the readings are easy to pick out (see CurrentOutput for what the trace looks like). But variations in real-world situations make for a lot of variety in the kind of returns. If I'm watching the scope, I can absolutely pick out returns at close ranges (where there's a lot of reverb) and long ranges (where the signal response is very weak). But teaching a computer to spot the returns is harder.

    - The first iteration just used, basically, threshold detection. I just used the 4th OPAMP in the chain (IC1D) as a comparator. If the output of IC1C was less than a threshold voltage, I'd trigger the output. The microcontroller (an Arduino Mega) just watched for the comparator output to toggle. The trick is that ... well, it works poorly. At close ranges, the reverb response overwhelms the return signal, so the whole response is below the threshold voltage. So if the threshold is set low enough to trigger only on the actual response at short ranges, it's not sensitive enough to trigger on a return at longer ranges.

    - The second iteration is what is shown in the attached circuit. The output of IC1C goes to an A/D. Instead of doing a digital threshold comparison, I'm sampling the actual amplifier output signal. In a perfect world, I should be able to watch the low points and see that the slope is going up during the reverb portion, then down when the ping response arrives. This is, after all, what I'm doing when I watch the signal myself on the scope. The problem is that my microcontroller is slow -- I can only get a sample every (on average) 22usec, while the signal needs better than double that to actually see the fluctuations smoothly. So what I'm actually reading is almost arbitrary -- taking random samples down the length of the wave form, sometimes getting high points, sometimes low, so it's pretty tough to really make sense of a response. (I think Nyquist would have something to say about this, but I don't have a faster A/D handy, so ...)

    - Not directly circuit related, but potentially good background: I tried a sneaky trick on the software side to fix that problem. Basically, I pinged 10 times, stored all of those returns, and picked out the minimum reading from each time slice. That way, theoretically, if each sample time is a little random, I'd be able to pick out the bottom of the curve. Sweet idea, almost worked.

    - Now what I'm trying for is a smooth signal, which should make for a really easy thing to read on a relatively slow A/D converter. The first attached o-scope picture is what I'm getting -- the 40khz reverb and return (CurrentOutput). The second has a neat red line on it which is what I'd really like to get out of this circuit (DesiredOutput). The neat red line would give me an easy-to-sample A/D point that I could process in code almost trivially -- if the slope is going up, it's still reverb. If the slope is going down, it's a return. Yay! It doesn't need to be that perfectly smooth, but I need to smooth out a lot of the 40khz waveform to get the major shape of the curve.

    I am not a EE, so I'm kind of messing around blind here. I tried a full wave rectifier, but that only takes the absolute value of the stuff that's negative. I've biased my amps at 12V, so I don't really get any negative voltages. I tried shifting the amp bias to 0 (grounding the + inputs on IC1), and the amp stopped providing useful output; no more signal. (Not at all sure why.) I've tried various combinations of low pass filters, but I think I'm just not experienced enough to arrange the bits correctly. Maybe a low-pass filter is the right answer, but maybe all I'm doing with a filter is filtering all of the signal, so I get nothing out the far side at all.

    Thoughts? How can I get the 40khz line to give me a neat red smooth line?

    Thanks in advance. Hope I've provided enough information to make this useful for everyone.

    Dan
     
  2. crutschow

    Expert

    Mar 14, 2008
    13,042
    3,243
    You could use a simple diode envelope detector.
    An LTspice simulation of one is shown below consisting of a diode and an RC filter.

    The R3C1 time-constant is a trade-off between response to the signal variations and ripple rejection.
    If necessary, you could add a higher-order active filter at the detector output to further reduce the ripple while still giving a good signal response.
    If you know the highest signal variation frequency you have and the ripple voltage you can tolerate, I can help with that.

    The output is high impedance (100kΩ) so it needs to go to a high impedance load, such as an op amp non-inverting buffer.

    upload_2016-4-10_11-37-49.png
     
    Last edited: Apr 10, 2016
  3. Daniel McMath

    Thread Starter New Member

    Dec 28, 2015
    3
    0
    Wow, that looks shockingly simple, thank you.

    ... Let me breadboard that up ...

    ... Ok, that almost works, straight out of the box, without even making sure I was using the right parts. I grabbed an unlabeled capacitor and a 60 kOhm resistor, and I got a signal that looks astoundingly good. I may have to order parts to make sure I get the right ones. For the moment, I'm going to see if I've got anything closer to what you've specified.

    Crutschow, you're a life saver. :)

    The only thing I wish I knew now is *why* that works.
     
  4. Daniel McMath

    Thread Starter New Member

    Dec 28, 2015
    3
    0
    Ok, wired it up with a 2000pF cap and a 100kohm resistor, tested the code with that circuit modification, and the results are outstanding. Super-simple! Thanks for the help! :)
     
  5. crutschow

    Expert

    Mar 14, 2008
    13,042
    3,243
    It's simply a rectifier with a capacitor to store the peak signal value (minus the diode drop) and a resistor to discharge the capacitor as the signal level drops.
     
    Last edited: Apr 11, 2016
Loading...