measuring da distance!

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Oct 14, 2011.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    Hi All!

    Here's what i'm working on:

    Basically, using a PIC16F series, i'm trying to make a utrasonic distance measurer that will output 5 cycles at 40Khz on one I/O then wait for some microseconds then look for the reflection while measuring the time. As soon as the signal is seen, look up the result in a table and display it on 3 digit LED display.

    I did some readings on the ressources that you guyz provided some times back and have some ideas about how to solve the problem BUT would need further helps from you guyz!

    First, as usual, I would like to discuss the hardware implementation.
    And here's how I'm planning to go for it:

    This time around I'm planning to breadboard the circuit with PIC16F877 and use pins RD0-6 for the multiplexing of the 3 seven segments (common cathode), pins RC0, RC1 and RC3 for the transistors (enable), the required pins for ICSP and most importantly the attached schematics for the transmitter and receiver sensors (with pins RA1 and RC2)

    Note: this schematic comes from one of your provided ressources, and i think it can be easily breadboarded compared to some crazy schematics I have seen.

    Ok, i don't wana make this too long so I stop here for the hardware part and will talk about the software one in my next post while having your comments on the hardware!

    Your comments will be greatly appreciated

    Kindly regards, Eric
     
  2. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    According to the readings, i think the solution can be summarized as follows:

    knowing the speed of sound in the air (~340m/s), send a short ultrasonic pulse at 40khz in the air and listen to the echo and knowing the time of the forth n back travel of the wave => time can be converted to distance => that's the distance from sensor to object and then displays it.

    what im trying to do now is to break the problem with details (pseudo code)of how to actually implement the above summary.

    here's what i came up with:

    1) generate a 40khz burst signal from PIC PWM output and after 5 cycles burst is completed, wait for some microseconds (as required) then a variable that measure the time is activated;

    2) sense the echo with the piezzo receiver (PIC ADC) and as soon as one is detected stop the time measurement;

    3) convert measured time into distance (cm) and display it;
    4) if no object is detected after some times (to be determined) or if out of range, maybe display something representing 'out of range or no object detected'

    Did i forget something?? but i still have to detail each line above in order to have a clear picture how to code it...

    And i have some questions for the above...

    your comments are welcome!!

    regards
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,357
    Your receiver is not going to work as shown. The signal received is of very low power and needs to be amplified. A circuit with high Q tuned to the ultrasonic frequency is required for it to work.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    OK, the hardware: I happen to have a product out there that does something very similar (except it finds bubbles inside tubes and not a distance) that uses a PIC and some crystals similar to these things. These things are easier since they work at 40Khs and mine was at 3MHz.

    I drove my transmitting crystal direct off my PIC using 4 output pins in parallel. No caps diodes inductors, just went direct. Other end of transducer goes to ground.

    For the receiver you'll need an amplifier as the signal out of the receiver will be way too low to trip a digital pin.

    I did find a link to something someone did, and his receiver amp looks reasonable.
     
  5. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    Thanks a lot for your replies...

    attached is a block diagram showing that an amplifier is needed just as you said...

    can you provide an suitable amplifier schematic for the receiver while im searching for one as well?

    But otherwise, the schematic is ok, right?

    regards,
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It seems a little unusual to me, it has what looks like a voltage doubler on the output. Presumably the lower rail is supposed to be ground, but is unmarked.
     
  7. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    using the SRF04 Ultrasonic sensor, this is what I base all my distance measurements on using a 40 Khz ultrasonic sensor and transducer pair....

    Sound travels 1 inch every 73.746us
    Timer uses 625Khz clock Frequency (5Mhz/8)
    625Khz is 1.6us per clock tick
    Max range of sonar is Approx. 9m (354 inches/ 899cm)
    Distance of echo roundtrip is 354 *2 = 708 inches
    708 * 73.746us /1.6us = 32633 'ticks at max range
    32632 / (354) = 92 --> = inches
    32632 / (899) = 36 --> = cm
     
  8. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    it seems to me like Mard77 is not too happy with the amplifier provided by ErnieM....what about the one attached that i found ???? which of the 2 should i choose??

    well, i don't know if it goods and i will follow what you are suggesting me anyways...

    BTW, thanks Bmore for your distance calculation...will be talking about it soon as soon as i'm done with the hardware
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I haven't used a PIC for ultrasonic ranging, so PM'ing me twice in one day about it won't help you get a useful answer.

    If you insist on PM'ing me, I'll have to place you on the ignore list. If I had everyone sending me PM's like you do, I would get nothing done except read PM's, which I simply won't let happen.
     
  10. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    Sorry Sir!!!

    That will NEVER EVER happen again I promised...

    BTW, I also apologise for PM'ing the rest of the members if you did not appreciate it!

    Again I'm sorry sarge!!!
     
  11. tgotwalt1158

    Member

    Feb 28, 2011
    111
    18
  12. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    Wow!!!

    I sincerely don't know how to thank you tgotwalt1158...

    Just from a quick look I really can tell that that link will really help...
    Its quiet late where I am so I will have a deep look at it tomorrow...

    You put a smile on my face after being 'shouted at' about PMs...

    Thx a millions
     
  13. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Hmm, both circuits have the voltage doubler part, but in the second one it is labelled peak detector.
    There doesn't seem much need for one anyway because the PIC can easily detect a short pulse, especially if you put it on an interrupt on change pin, I'd just cut out that part of the circuit.
     
  14. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    @ Mard77: guess you are talking about the the ultrasonic amplifier from tgotwalt1158 link, right? So if I have to use it, I will have to ignore that cap connecting amplifier to peak detector, right?

    One more thing, on my original post I attached a schematic that I'm planning to use But you guyz suggested to add an amplifier in order for the receiver to work...

    But also, from where I took it (a cheap ultrasonic range finder by mikroe-example.com) they said the following:

    "Using a transistor and a resonator circuit, the ultrsonic transmitter will get around 20 volts and the sense range will be extended up to 200cm. Second to sense the echo, the piezzo receiver can provide a few dozenz of millivolt, AND THIS WILL BE ENOUGH FOR A Pc ADC with 4 mV resolution WITHOUT EXTRA HARDWARE."

    What are your opinions on the above?

    Regards,
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    If you find a similar sub circuit in two examples you may want to see what it is doing before you remove it. Here it is forming a safe bridge between an analog signal going + and - about ground and a digital signal that should only go 0V to some max voltage.
     
  16. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    @ErnieM: what do you think of my post #14 about using PIC ACD without extra circuitry with my original schematic for the receiver??
     
  17. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    When I saw they they had the same circuit section I had a moment of doubt so I had a little investigate. It's converting a 0-5V wave to 7.5V steady, which is what would be expected with a voltage doubler (it loses a bit of voltage in the diodes).
    [​IMG]
     
  18. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    Ok!

    i will then use the circuit that ErnieM originally refered us to as every is happy with it now!

    i still have one little question though: which pin from the MCU should I use for the receiver? i mean the output from the receiver amplifier!!

    As for the transmitter, i must use the PWM (CCP1) pin, right?

    Thanks all!
     
  19. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You could do, but you could also turn on and off a normal pin.
    @4MHz clock frequency
    1000000 instructions per second
    1000000/40000=25
    so you could just turn the pin on for 12 cycles and off for 13 cycles then repeat.
     
  20. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,042
    33
    @ Markd77: you got me lost a little bit...

    I have to 1) output 5 cycles at 40khz on one I/O pin; 2) wait for some microseconds; 3) then listen to the echo while measuring the time; 4).....

    I still don't really understand the '5 cycles' part?? and since we dealing with frequency (40khz or 25us) don't you think using PWM feature will be easier but then about the 5 cycles burst???

    Talking about using a normal pin, as you suggesting, and if I got you well...do you mean i have to create a cycle with the high half cycle of 12us and the low half cycle of 13us??? so basically making a square wave with timeon= 12us and timeoff= 13us?? and since i need 5 cycles, i will have to repeat this 5 times???

    thanks!!!
     
Loading...