PDA

View Full Version : Parallax Ping Issue



jkarpiak
- 22nd November 2012, 19:05
I am attempting to interface the Parallax Ping ultrasonic sensor to a Pic16F876A. Here is the code:


Define LOADER_USED 1
Define OSC 20
dist var word
loop:
TRISB.7=0
low PORTB.7
PULSOUT PORTB.7,5
TRISB.7=1
pulsin PORTB.7,1,dist
pause 100
goto loop
end


I am using PBP 2.50B and Microcode Studio Plus v3. I pre-programmed the pic with the bootloader file provided im Microcode Studio Plus and using the ICD when executing the program.

When I observe the trigger and echo pulses with a oscilloscope I note that the width of the echo pulse is indeed proportional to the distance to the detected object . The problem is that the echo pulse isn't the 5V TTL pulse expected but only about 0.2 volts. Thus the width of the echo pulse isn't being measured and the variable dist is always set to zero. In my week long search of various forums the only two possibilities I have seen for this is that the sensor is either underpowered or the pin isn't being put into the input state. Now the documentation says that the Pulsin command makes the pin an input but just to be sure I added the TRISB.7=1 line just to be sure. I also verified that the voltage supplied to the ping sensor is 5V and it doesn't drop when it is in operation. I have also tested it on different pins and changed out the pic. Nothing works.

I have also tested the sensor using a Basic Stamp and operation is as expected. The echo pulse is a full 5V.

If the pic pin is being set to input then what reason could their be for the ping sensor to not be able to drive it to a logical high?

Any ideas? I am at my wits end.

Johnny K.
A frustrated physics teacher and robotics club leader

mackrackit
- 22nd November 2012, 20:57
Try something like this


INCONSTANT CON 890
INDISTANCE VAR WORD
TIME VAR WORD

START:
HIGH PORTB.3
PULSOUT PORTB.3,2
PULSIN PORTB.3,1,TIME
INDISTANCE = INCONSTANT ** TIME
LCDOUT $FE,1,DEC3 INDISTANCE," INCHES"
PAUSE 100
GOTO START

jkarpiak
- 23rd November 2012, 01:51
Thank you so much. It works!!! (although I have no idea why)

Johnny k.



Try something like this


INCONSTANT CON 890
INDISTANCE VAR WORD
TIME VAR WORD

START:
HIGH PORTB.3
PULSOUT PORTB.3,2
PULSIN PORTB.3,1,TIME
INDISTANCE = INCONSTANT ** TIME
LCDOUT $FE,1,DEC3 INDISTANCE," INCHES"
PAUSE 100
GOTO START