Shop OBEX P1 Docs P2 Docs Learn Events
Need help with command Pulsin — Parallax Forums

Need help with command Pulsin

eecs189eecs189 Posts: 10
edited 2006-03-08 06:18 in BASIC Stamp
For my senior design project, we are building an ultrasound range finder. We have tested the transmitter and the receiver, and they function correctly. We verified that it works by using an oscilloscope. However, when we try to measure the pulse width using the BS2 command, PULSIN, it won't give us a reading. Here's our code:

' {$STAMP BS2}
' {$PBASIC 2.5}

'
[noparse][[/noparse] Variables ]
time VAR Word
dist VAR Word
value VAR Word

'
[noparse][[/noparse] Main Code ]

Start:

DEBUG CR, "Start", CR
DEBUG "Waiting for switch", CR
GOSUB UserWait

DEBUG "TX ON", CR
PULSOUT 10, 100
PULSIN 12, 1, time
DEBUG DEC ? time

time = time * 2
dist = 343 * time
DEBUG DEC ? dist

HIGH 14
PAUSE 100

GOTO Start

'
[noparse][[/noparse] Subroutines ]

UserWait:
INPUT 0
RCTIME 0, 1, value
IF value = 0 THEN UserWait
RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-08 05:27
    What are you seeing on your scope? (width of the incoming pulse)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • eecs189eecs189 Posts: 10
    edited 2006-03-08 05:35
    Yes, we saw a pulse. My partner froze the screen and was able to measure the period of the pulse.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-08 05:51
    Then you should be able to determine whether it is in the range the BS2 can measure. I'm not sure what you're doing with RCTIME -- that may be what's slowing your program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • eecs189eecs189 Posts: 10
    edited 2006-03-08 05:55
    The RCTIME is for a push button switch to turn on the transmitter.
  • eecs189eecs189 Posts: 10
    edited 2006-03-08 06:18
    The pulse that we measure was below the maximum pulse width. Ours was approximately 2 millisecond, whereas the maximum that pulsin can read for BS2 is around 131 ms
Sign In or Register to comment.