Pages: [1]   Go Down
Author Topic: Ultrasonic Sensor  (Read 1099 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks for the help.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25804
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
My ultrasonic tx runs at 40MHz(optimal freq.).
I am so doubting this.
Logged

"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.

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8701
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
My ultrasonic tx runs at 40MHz(optimal freq.).
I am so doubting this.

MHz. kHz.  Pretty much the same thing, right?  :-)
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What's a factor of 3 among friends smiley-cool
Logged

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.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25804
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What's a factor of 3 among friends

sp. "103"
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25804
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25804
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Pages: [1]   Go Up
Jump to: