Go Down

Topic: Ultrasonic Sensor (Read 1 time) previous topic - next topic

FlavoFraz

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!

CrossRoads

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.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

FlavoFraz

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

Thanks for the help.

CrossRoads

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.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

AWOL

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

I am so doubting this.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johnwasser


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

I am so doubting this.


MHz. kHz.  Pretty much the same thing, right?  :-)
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

CrossRoads

What's a factor of 3 among friends 8)
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

AWOL

Quote
What's a factor of 3 among friends


sp. "103"
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

FlavoFraz

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.


AWOL

Quote
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

FlavoFraz

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?

AWOL

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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

CrossRoads

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.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview