Discussion in "8051 Discussion Forum" started by    shama3ey    Oct 25, 2009.
Sun Oct 25 2009, 10:00 PM
#1
Hi all,

I'm trying to make my microcontroller generate a pulse of 40 KHZ to send to my sonar sensor attached to the UC ... how can that be done? both in code and in hardware?

I'm using Parallax Ping))) sonar which is TTL compatible in which I believe don't need an A/D converter.

Plz help
Sun Oct 25 2009, 10:44 PM
#2
The Parallax Ping))) sonar will take care of producing the 40KHz signal.

You have to send a short pulse about 5 uS long to the Parallax "signal" pin
as a trigger to start a scan.

After 750uS the Parallax board pulls "signal" pin high.
It remains high for a period that indicates the distance to the target.

The signal is TTL compatible so you don't need an A/D converter.

As Trigger and Echo are on the same pin (oddly) it is important to know exactly
how the Sonar board drives the signal pin, and it is not clear from the PDF.

I recommend you look for examples of the board in use, on the internet.
I may be harder to do with an 8051 than with a PIC because of the way their
ports work.
EDIT:
As it turns out it is probably easier to use the 8051


http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf


[ Edited Sun Mar 14 2010, 10:12 PM ]
 shama3ey like this.
Tue Oct 27 2009, 03:17 PM
#3
so do you think its possible to use (say P1.4) to generate the pulse to the sensor and use a different pin ( say P1.5) to read the input of the sensor after detecting something?
Wed Oct 28 2009, 09:04 PM
#4


so do you think its possible to use (say P1.4) to generate the pulse to the sensor and use a different pin ( say P1.5) to read the input of the sensor after detecting something?

shama3ey


I'm sure you can, I'm just not sure how

It may be easy, but you would have to experiment.
There are similar units around with separate trigger and echo pins, that are cheaper.
Google "SRF04"

Parallax say that once they stop selling a product they remove
all documents, downloads etc from their site.
I'm not impressed with their customer support.



[ Edited Wed Oct 28 2009, 09:11 PM ]
Fri Nov 06 2009, 02:52 AM
#5
Ok based on the PING manual, I wrote some psedu code to operate the sensor.. but I don't know how interpret it in terms of codes since I don't know how to generate delay loops that runs exactly for a specific time... So can you help me implement this?

#include <reg51f.h>

sonarO = 0x90; //P1.0
unsigned char distance;
unsigned char time;
void sonar()
{

sonarO = 0xff;
//wait 7 uS
sonarO = 0x00;
//wait 750 uS
//reset timer used to avoid overflow
//while(get time when sonarO goes high || quit loop if time passed time =18.5 ms);
//Speed_of_Sound * Time_Passed / 2 = Distance_from_Object
//distance = 344 m/s * Time Passed in S / 2

distance = 344 *( time/2);

}


[ Edited Fri Nov 06 2009, 02:53 AM ]
Fri Nov 06 2009, 10:36 AM
#6
i give you pseudo code to follow..
sonarO connected to INT0 pin P3.2 not P1.0 to make things easier.


sonarO = 0; //make it o/p pin and o/p low on P3.2
sonarO = 1; //
5uS delay// or whatever u want to keep
sonarO = 0;// pulse complete L-H-L
//no delay required, prepare your controller for calculating time..
sonarO = 1;//make it i/p pin to read the pulse width
TMOD = 0x09; //Timer0, 16bit gate controlled(P3.2)
TR0 = 1;//Timer will only run when Pin becomes high.
while(sonarO==0);//wait till pin is low
while(sonarO==1);//wait for pulse to finish
//timer stopped automatically as soon as P3.2 goes low
TR0 = 0;//completely stop timer.

now value in your TH0-TL0 will have width of pulse in clock cycle, to convert it into uS multiply it by time of single clock cycle e.g. for 12Mhz clock cycle is 1uS.

copy this in a variable divide it by 2 to get one side delay. Now you can easily convert it to distance.
 shama3ey like this.
Tags ultrasonic distance measurement sensorparallax ping)) sensor 80518051 distance measurement
Fri Nov 06 2009, 12:40 PM
#7
so in psedu code you wrote, I only need to find a way to delay for uS, and take the values in TH0-TL0 and multiply them with the time of a single clock cycle, then use the distance formula

distance = 344 *( time/2);

so for a 11.059 MHz crystal, the time for single clock cycle is still 1uS?

When you say one side delay you mean what?

and to calculate the time, I calculate whats in TH0 then add it to whats calculated from TL0?

Appreciate your patience I'm trying to learn and you are doing great job
Fri Nov 06 2009, 12:48 PM
#8
[quote]so for a 11.059 MHz crystal, the time for single clock cycle is still 1uS?
[/code]

no its 1.085uS calculated from (1/fosc) *12

When you say one side delay you mean what?

shama3ey


sound burst first goes and then come back so it travels the distance twice so we need distance of one way only. hence divide by 2.

and to calculate the time, I calculate whats in TH0 then add it to whats calculated from TL0?

shama3ey


well in C its fairly simple.
unsigned int temp;
temp = TH0;
temp = (temp<<8) | TL0;

so temp will have the 16-bit count. you can use it in calculations.
Fri Nov 06 2009, 12:54 PM
#9
Thank you very very much...

So now I multiply the value in temp by 1.08uS to get total time traveled then divide it by 2 to get the time of one side correct?
Fri Nov 06 2009, 01:00 PM
#10
correct.. now you're at your own for now. (till i come back online )
see ya Ali ile

Get Social

Information

Powered by e107 Forum System

Conversation

Sun Oct 13 2019, 02:02 AM
Aline Hutchinson
Hey there,
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM
zexalo
Thu Oct 03 2019, 09:53 AM
thanhle12345
Thu Oct 03 2019, 07:37 AM
ramon_vsc
Fri Sep 20 2019, 04:53 PM
youssoufba
Thu Sep 19 2019, 11:57 AM
Taiphan000
Tue Sep 17 2019, 04:21 AM

Online

Guests: 38, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38097
Newest member: ilylily07
Forum Activity
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Thu Oct 17 2019, 09:38 PM
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Oct 17 2019, 08:35 PM
Do you understand how this code works?If so, addin...