Parallax Ping Issue


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default Parallax Ping Issue

    I am attempting to interface the Parallax Ping ultrasonic sensor to a Pic16F876A. Here is the code:

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Parallax Ping Issue

    Try something like this
    Code:
        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
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2012
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Parallax Ping Issue

    Thank you so much. It works!!! (although I have no idea why)

    Johnny k.


    Quote Originally Posted by mackrackit View Post
    Try something like this
    Code:
        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

Similar Threads

  1. Humidity problem with ping sensor
    By celequanta in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th July 2012, 03:06
  2. Generating ping sounds
    By bodgetts in forum General
    Replies: 9
    Last Post: - 23rd January 2012, 07:14
  3. Parallax GPS Receiver
    By emavil in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th February 2009, 09:35
  4. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  5. Ping Darrel Taylor - Timer0 Instant Interrupt
    By JEC in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2007, 11:20

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts