Ultrasonic Sensor

I've been using ultrasonic sensors to calculate position from one Arduino to the other.
My ultrasonic tx runs at 40MHz(optimal freq.).
The problem is the functions pulseIn() and AnalogRead() need atleast 10usec and 100usec to read the signal.
I was using a 4bit binary counter to send 12 pulses(which = .3usec).
But to obtain atleast 10usec, I would need to send atleast 400 pulses.
Unless I buy an 8 bit and use ripple carry or a 12 bit binary counter, I'm not sure how I can achieve 10 usec.

Anything that can be done with the Arduino or software coding?
Any help would be appreciated.

Thank you!

Can you put these
pulseIn() and AnalogRead()
inside while loop?

starttime = micros();
endtime = starttime;
while (endtime-startime <=10){
do whatever pulseIn() does
endtime = micros();
}

(all time related elements are type 'unsigned long')

thus stay in the loop until 10 uS have elapsed.

My signal is still at 0.3usec.
I would need a function that could read at that speed.

Thanks for the help.

Ok, I had it backwards then.

So you need to read at 0.3uS, which is 300ns, which is < five 65nS clock pulses. Think you're gonna be outta luck doing that in software.

My ultrasonic tx runs at 40MHz(optimal freq.).

I am so doubting this.

AWOL:

My ultrasonic tx runs at 40MHz(optimal freq.).

I am so doubting this.

MHz. kHz. Pretty much the same thing, right? :slight_smile:

What's a factor of 3 among friends 8)

What's a factor of 3 among friends

sp. "103"

Yikes...I just noticed the mistake.
It runs at 40KHz which makes a big difference.
But I'm still having a hard time getting the signal from the sensor being read by the arduino.

I'm trying to stop a timer when the signal is read.

When I hookup the ultrasonic receiver to the oscilloscope I see a voltage in the range of millivolts.
I'm assuming if I set pulseIn(port#, HIGH), that it wouldn't obtain the signal because the voltage is below 2V which is considered LOW.

When I hookup the ultrasonic receiver to the oscilloscope I see a voltage in the range of millivolts

So you'll need some amplification, or a means of nudging those millivolts over the logic threshold.

ok great!

So let's say I put my threshold to 100 millivolts for example.
What function would I need to use to see if the port is high or low?
analogRead?

You need to find out what the digital '1' threshold (it is usually expressed as a fraction of the supply voltage in the AVR datasheet) is, and offset your received signal by slightly less than it.
Obviously, you'll need to use direct port manipulation to get the speed.

Use a simple comparator - put your pulse on the +pin, put the -pin just above ground level, whenever the pulse exceeds the -pin the output will go high.
Read it with a regular digital pin.

Running on an Uno? U1A does the same thing, comparing Vin/2 against 3.3V.