pulsout pulsin on same pin - timing?


Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2007
    Posts
    70

    Default pulsout pulsin on same pin - timing?

    Hello. I am trying to use Parallax ultrasonic Sensor PN 28015

    For some reason, I cannot get the code to work. I have searched for quite a bit and found examples of people using similar code with the same and similar(devantech sf04) devices.

    I am using a PIC16f887 at 8mhz external oscillator. This should give a pulsout cycle of 5us.

    In the attached image you can see the interface info for the sonar sensor. It appears that I send a pulse of 5us, wait ~750us then read back a result upto 18.5ms. Any idea if my current code fulfills these goals?

    I have hooked the devices upto an o-scope and verified their operation. I can see the return pulse begin 750us after the end of a trigger pulse. I read in the pic basic docs that the pulsin waits 65555 cycles for a pulse to time. Is this all working with my current code?

    When I trigger the device, the sensors LED lights, but I always get back a 0.

    Here is my code.
    Code:
    DEFINE OSC 8                 ' Set oscillator to 8mhz
    DEFINE DEBUG_REG	PORTC    ' Set PORTC as debug serial out port
    DEFINE DEBUG_BIT	6        ' PORTC.6 Set Debug-Out pin bit
    DEFINE DEBUG_BAUD	9600    ' Set Debug baud rate
    DEFINE DEBUG_MODE	0     	' Set Debug mode: 0 = true, 1 = inverted
    
    TRISB.0 = 0                 ' setup port b.0 as output initially
    ANSEL = 0                   ' disable all AD convertors
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    Ping            var     PORTB.0
    
    ' -----[ Variables & Constants]--------------------------------------------
    rawDist         VAR     Word                    ' raw measurement
    Trigger         CON     2                      ' trigger pulse = 10 uS       (at 8mhz this is 5us per pulsout)
    IsHigh          CON     1                       ' for PULSOUT
    IsLow           CON     0
    ' -----[ Initialization ]--------------------------------------------------
    reset:
    PAUSE 100
    DEBUG      "Parallax Ping Sonar Test  ", 10
     
     
    ' -----[ Program Code ]----------------------------------------------------
    Main:
    
       if PORTA.0 = 1 then                          ' wait for keypress
        GOSUB Get_Sonar                             ' get sensor value
           debug DEC rawDist                        ' output raw distance data
          PAUSE 100           
       endif
     goto main    ' loop forever
    END
      
      
    ' -----[ Subroutines ]-----------------------------------------------------
    Get_Sonar:
    'high 4
    low ping                                     ' make trigger 0-1-0
      PULSOUT Ping, Trigger                      ' activate sensor by sending 10us pulse
    
      PULSIN  Ping, 1, rawDist                   ' measure echo pulse
    
      
      RETURN
    Attached Images Attached Images  
    Last edited by vacpress; - 14th January 2009 at 07:17.

Similar Threads

  1. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  2. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  3. Pulsin to pulsout with up than 4MHZ crystal ?
    By RCtech in forum mel PIC BASIC
    Replies: 5
    Last Post: - 18th May 2006, 19:23
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

Members who have read this thread : 0

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

Posting Permissions

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