Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Programming PIC16f877 to calculate the distance between an object and a sensor

Status
Not open for further replies.

qatar.engineer

Junior Member level 1
Joined
Nov 9, 2006
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,452
HI
i need help in programming pic so that it can calculate the distance from the object to the senser
thanks
 

Re: help in pic16f877

If you want help,you must give some details about your project?
Which language do you use?
What kind of sensor do you use?
What do you want? Do you need help to write the program or you are looking for similar projects?
 

Re: help in pic16f877

qatar your you used srf04, I leave pictures here you

S320110.JPG



s320110d.JPG



s320110e.GIF








Code:
'BasicX-24
'***********************************************************
'* Programa de Ejemplo del SRF04 conectado al BasicX-24
'*
'* Copyright 2002 - Devantech Ltd 
'* Prohibido el uso comercial de este software
'* Solo para uso privado y educacional
'*
'* Escrito por Gerald Coe - Febrero 2002
'*********************************************************** 
Sub Main()
   Const EchoPin As Byte = 14 ' Indica el pin para Pulse of echo
   Const TrigPin As Byte = 13 ' Indica el pin para Pulse of trigger
   Dim Range As Integer
   Call PutPin(EchoPin, bxInputTristate)
   Call PutPin(TrigPin, bxOutputLow)
   do
      Call PulseOut(TrigPin, 10, 1) ' Pulse 10 us
      Range = PulseIn(EchoPin, 1) \ 54 '  54 for cm y 137 for inches
      Debug.Print "Range is "; CStr(Range) 
      Call Delay(0.1) ' 100mS delay
    
   loop
End Sub

s320110c.GIF
 
Re: help in pic16f877

It will be quite tedious to do computation.
I suggestion you make your PIC software adjustable.
Make a variable resistor input using ADC Input port,
or make DIP switches to configure your hardware real time.
Real time calibration of sensor distance is much easy.
MODERATOR - SIGNATURE LINKS ARE NOT ALLOWED
 

Re: help in pic16f877

I would try using the CCP module, to measure the time between the rising edges of the pulses, your "pulso the dispario" and "pulso de eco".
That gives you the time delay between the two. From that you can easily calculate the distance.
However, you have to be very careful that the pulses are "clean", that is wihout any fast transitions, spikes, etc., because these would make the CCP interpret them as valid, very short pulses.

If you do not want to use the CCP, simply monitor the two lines in a software loop and then finally do the calculations.
But I recommend the CCP because it is more accurate and takes less effort.

After you have the time delay it is a matter of multiplying that with the speed of sound in the air. See the Microchip website for an appnote on Math routines.
 

Re: help in pic16f877

hi guys
here an article about rang meter with pic micro
 

Re: help in pic16f877

coshkun said:
If you want help,you must give some details about your project?
Which language do you use?
What kind of sensor do you use?
What do you want? Do you need help to write the program or you are looking for similar projects?
Hi
thanks for your helping
my project is an eod robot that detect the mines and dispose them but for know we are working know in connect the senser whic is srf04 with pic16f877 and we dothe connection but iwe do not knowhow to write the program in assmbly to get the distance when an object is near it i want help in how to start wrting the program
thanks

Added after 7 minutes:

goslock said:
qatar your you used srf04, I leave pictures here you

Code:
'BasicX-24
'***********************************************************
'* Programa de Ejemplo del SRF04 conectado al BasicX-24
'*
'* Copyright 2002 - Devantech Ltd 
'* Prohibido el uso comercial de este software
'* Solo para uso privado y educacional
'*
'* Escrito por Gerald Coe - Febrero 2002
'*********************************************************** 
Sub Main()
   Const EchoPin As Byte = 14 ' Indica el pin para Pulse of echo
   Const TrigPin As Byte = 13 ' Indica el pin para Pulse of trigger
   Dim Range As Integer
   Call PutPin(EchoPin, bxInputTristate)
   Call PutPin(TrigPin, bxOutputLow)
   do
      Call PulseOut(TrigPin, 10, 1) ' Pulse 10 us
      Range = PulseIn(EchoPin, 1) \ 54 '  54 for cm y 137 for inches
      Debug.Print "Range is "; CStr(Range) 
      Call Delay(0.1) ' 100mS delay
    
   loop
End Sub
HI
can you please tell me that what Language is written by? because i do not understand it?
 

Re: help in pic16f877

hello Qatar, the language that this writing is BASIC.

in this Link **broken link removed** are several examples with SRF04, 08, 10, in different programming languages.

The SRF10 has but reach that the previous ones and is connected just as SRF08, approximately 3 - 6 mts.

in this Link you found information of the SRF10

SRF10

s320114e.jpg
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top