Need help with command Pulsin
eecs189
Posts: 10
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
' {$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 Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax