BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:24 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PULSIN
PostPosted: Wed Apr 27, 2011 5:48 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Hi,

I am trying to use the Parallax's PING with the BAPro24.
Here is my code :

Code:
time   VAR   word
Main:
   low P0
   PULSOUT P0, 20
   PULSIN P0, 1, time
   serout s_out,i9600,[dec time,13]
   PAUSE 100
goto main


Pulsout has to be 10µs. I only get 0 ?
I measure the 2 pulses with my oscilloscope and the code below works fine with the BS2

Code:
CmConstant   CON   2260
InConstant   CON   890
cmDistance   VAR   Word
inDistance   VAR   Word
time   VAR   Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP


Thanks for your help

Chris


Attachments:
28015-PING-v1.6.pdf [393.46 KiB]
Downloaded 40 times
Top
 Profile  
 
 Post subject: Re: PULSIN
PostPosted: Wed Apr 27, 2011 6:26 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
FYI - There are a few different threads on the Ping sensor up on the Lynxmotion forums. There is also a top topic( http://www.lynxmotion.net/viewtopic.php?f=4&t=4714 ) with links to a bunch of different topics talking about code for different sensors or the like.

But here is some code from one of those threads:
Code:
wdist var word

main:
low p4
pulsout p4, 5
input p4
pulsin p4, 0, toolong, 40000, wdist
wdist = wdist / 148   ;convert for inches
serout s_out, i9600, ["Distance: ", sdec wdist, 13, 10]      ;display result in terminal
goto main

toolong:      ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, ["Timeout, sensor is not working", 13]
goto main

The main differences I see is that they added the input P4 line between the pulseout and the pulsein lines. Also they used the long form of the command with a timeout...

Kurt


Top
 Profile  
 
 Post subject: Re: PULSIN
PostPosted: Wed Apr 27, 2011 9:29 am 
Offline
Guru

Joined: Sun Dec 20, 2009 10:52 pm
Posts: 76
Thanks Kurt,
"input P0" was what missing on my code.
As usual you are of great helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO