measuring da distance!

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Thanks Mard77! I think you agreed with my understanding and now I have two option to choose for the transmission of the signal...

Now after outputing those 5 cycle, I have to wait for some 'us'...so how many microsecond (us) should I wait before timing the round trip of the wave??? I read somewhere: "do nothing for twice the pulse length duration to prevent false start" well I'm not sure if I understood well

Also, which pin of the MCU should I use for the reciever?? Is the ADC pin channel 1 ok? And if so how does it function? (I mean the detection of da echo)

Is there another alternative? Well I haven't read the link given by tgo...1158...maybe I'll have an idea...

Regards,
 

Markd77

Joined Sep 7, 2009
2,806
If you want to wait for twice the duration of the 5 cycles that would be 250μs. That would make the minimum distance you can measure about 40cm. You can experiment with lower times later and see if it still works.
Basically the transmitter will make the whole structure of the box it is in, including the receiver, vibrate so you need to wait a bit for it to die down.
Using the ADC direct might work, it's probably not the best way.
I guess you would just keep checking it and if it rises above a value of 4 or 5, stop the timer. If you use too low a value then electrical noise will probably trigger it too early.
The minimum time for an ADC sample is TAD (1.6μs minimum) X 12 = 19.2μs during which time sound will have travelled about 6cm so your best possible resolution would be 3cm.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
i'm a bit slow as i'm busy with another lab too but guess from tomorrow i'll be really active on this one

If you want to wait for twice the duration of the 5 cycles that would be 250μs. That would make the minimum distance you can measure about 40cm. You can experiment with lower times later and see if it still works.
ok, but I think 40cm as minimum measurable distance is too large...I would like, if possible, to be able to measure a range of around 5cm-200cm (or 300cm)...so how to determine the range? does the range depend on the type of ultrasonic sensors??
Basically the transmitter will make the whole structure of the box it is in, including the receiver, vibrate so you need to wait a bit for it to die down.
OK! so how many [us] would be suitable in order to measure the minimum possible distance and in the same time allow the vibration to die down?

Using the ADC direct might work, it's probably not the best way.
I guess you would just keep checking it and if it rises above a value of 4 or 5, stop the timer.
Since it's not the best, what (which module) would you suggest for the detection of the echo by the receiver??

If you use too low a value then electrical noise will probably trigger it too early.The minimum time for an ADC sample is TAD (1.6μs minimum) X 12 = 19.2μs during which time sound will have travelled about 6cm so your best possible resolution would be 3cm.
ok!

Thanks so much

regards, Eric
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I read somewhere one can use the CCP - Cature mode to measure the time of the signal...well will have to read to understand...while waiting for suggestion
 

Markd77

Joined Sep 7, 2009
2,806
ok, but I think 40cm as minimum measurable distance is too large...I would like, if possible, to be able to measure a range of around 5cm-200cm (or 300cm)...so how to determine the range? does the range depend on the type of ultrasonic sensors??

OK! so how many [us] would be suitable in order to measure the minimum possible distance and in the same time allow the vibration to die down?
It depends on a lot of things, probably the best thing to do is get everything working with a conservative value, then try reducing the time until you get the lowest reliable range.
Since it's not the best, what (which module) would you suggest for the detection of the echo by the receiver??
The CCP module in capture mode is probably a good choice but requires the additional circuitry to amplify the signal.
 

kubeek

Joined Sep 20, 2005
5,795
I think that capturing the wave with an ADC an then finding the five-pulse pattern would be the most accurate way of doing it. You would need just some additional RAM to stuff the data into and then just go through the wave with some algorithm.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
It depends on a lot of things, probably the best thing to do is get everything working with a conservative value, then try reducing the time until you get the lowest reliable range.
sounds reasonnable...so which value [us] can i use for stater?

The CCP module in capture mode is probably a good choice but requires the additional circuitry to amplify the signal.
additional circuitry for the transmitter again...#crying# lol
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@Mard77: the circuitry to amplify the signal...you mean for the transmitter??? i need to make sure as we already agreed on the amplifier for the receiver...

regards,
 

Markd77

Joined Sep 7, 2009
2,806
There's no harm starting at 250μs, it's within the distance range you want to be able to measure and once everything is working it should be trivial to reduce it in software to find the point it starts getting unreliable.

I've been thinking of a circuit, I'll test it later with a better simulator. The left part is a precision rectifier, the right part is just used to compare the output to an adjustable voltage to set the threshold.

 

Attachments

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@Markd77: thanks again...
Ok! I'll use 250us for stater...
So the left part will be connected to MCU pin and the right one to the transmitter, right?
You have explained what the left and right part does...but can you explain why we need now an amplifier for the transmitter?

One little question: why in your simulations, you use 25Khz at the input and not 40khz?

Kindly regards,
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
So basically, as I'm thinking of using PIC16F877 I can use CCP1 (PWM) for da generation of the pulses and CCP2 (capture mode) for mesuring the time, right?

Also how should I edit my original schematic (in post #1) given that we haVe now included two (2) for the receiver and transmitter?

I will be reading on capture mode of CCP and how to measure time (listen to da echo with it)...

Regards,
 

Markd77

Joined Sep 7, 2009
2,806
It was an idea for the input amplifier, but if you are going to use the other one, just ignore it.
I only used 25kHz because it's the highest that simulator goes, it doesn't make much difference to get the general idea.
Have a go at drawing the new schematic and then we will have a look.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
It was an idea for the input amplifier, but if you are going to use the other one, just ignore it.
You are confusing me a bit...the amplifier schematic that you just shown above! Is it for the transmitter or receiver? I'm asking coz you saying if I'm going to use the other one I should ignore this one

I only used 25kHz because it's the highest that simulator goes, it doesn't make much difference to get the general idea.
OK!

Have a go at drawing the new schematic and then we will have a look.
If you have noticed I have NEVER drawn a schematic because I don't have the software to draw circuit diagram and schematics...I was even about to ask which software I can download in order to draw schematics and including all the PICs mcu range...

That's why I always describe how I intend to build my circuit without providing a schematic...I am conscious this is not good...

But I would like to focus more on the software part now...and getting all the components required to build this by tomorrow...

Please clarify me about the amplifier above as I quote...

Regards,
 

Markd77

Joined Sep 7, 2009
2,806
Input amplifier = receiver.
The transmitter part from post 1 should be fine. Which post has the receiver circuit you will be using?
I can't recommend a schematic drawing software because I can't find one I like yet.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I haven't been able to get the PIC16F877 so will have to use the PIC16F690! here are my changes:

. PORTC (RC0-6): seven segment multiplexing
. RB4, RB5, RB6: transistor enable for hundreds, tens and units respectively
. RA1 used for ADC for receiver
. RA2 used for pulse generation
. Rb7 used for pushbutton

I decided to use the ADC for listening to the echo as I cant use pin RC2 for CCP capture mode since its going to be use for multiplexing...dont want to use 2 PORTS for multiplexing so as not to complicate my software!

Attached is the receiver amplifier im going to use, i also attached the schematic in the original post 1 as i need to ask a question: as you can see i have encircled the 33k value of the receiver...

i would like to know if i should keep this or remove it since i am going to use the receiver amplifier attached??

Also im using the chip UA741CN for the op-amp so im not too sure what to do with pin 1 (offset null1) and pin 2 (offset null2) im ok with the other pins.

please allow me to ask one more thing, in the sensor attachement i will like to know if the number 1 and 2 represent what? i mean which one is positive and which is negative between 1 and 2

I am building the whole circuit on breadboard now...

kindly regards, Eric
 

Attachments

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I think that capturing the wave with an ADC an then finding the five-pulse pattern would be the most accurate way of doing it. You would need just some additional RAM to stuff the data into and then just go through the wave with some algorithm.

would you please explain how you would use ADC to capture/listen to the echo??

regards
 

kubeek

Joined Sep 20, 2005
5,795
would you please explain how you would use ADC to capture/listen to the echo??

regards
Well, you need to set the ADC to sample the input at 100khz or so and store it in some place. IIRC you were talking about 3 meter max, so lets say you need to store 5 meters of data.
Sound travels at cca 35cm per ms, so that is 15ms to the object and 15ms back, so 30ms of data. With 100khz sampling you get 100 samples per ms, so you need to store 3000 samples, probably 16bit each. That means a 8kB RAM should be enough, I don´t know PICs, but I am pretty sure there should be some serial interface like I2C or SPI availble for the RAM to attach to. Look here for some nice chips, they send samples for free.

After you have stored the data, you need to find where your pulses are and find the distance. Finding the right time should be easy, because you are looking for a series of lowish an highish samples which are aproximately the same time apart.

This also lets you do some test captures first, feed the acquired data into computer and play with the algorithm until you get the best resolution and accuracy, without the need to change the receiver hardware.
 
Top