Reading servo signal from JR receiver

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
barthirst
Posts: 4
Joined: Sun Jul 11, 2004 1:01 am
Contact:

Reading servo signal from JR receiver

Post by barthirst »

Hi Everyone, I recently purchased a parallax stamp and having lots of fun. I have my first 'real' application I’m trying and after banging my head against the wall all morning and searching code I thought I'd post here just in case a kind soul might know what my problem is.<p>Question is this: I have a standard JR remote control transmitter / receiver (TX / RX) setup and I’m tying to read the servo command pulses from the receiver using the PULSIN command on the stamp. When I attach an I/O line to the signal cable from one of the servo channels it appears I’m getting garbage. I attached a servo in-line to load the circuit properly, and the servo moves fine, but still getting garbage on the I/O line. My code looks something like this:<p><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr><pre>
'{$STAMP BS2}
'{$PBASIC 2.5}<p>pulse VAR Word
counter VAR Word<p>pulse = 0<p>FOR counter = 1 TO 100<p> PULSIN 15,1,pulse
PULSIN 15,0,pulse
DEBUG "counter = ", DEC counter, " pulse = ", DEC pulse, CR<p>NEXT<p>DEBUG "All Done."<p>END
</pre><hr></blockquote><p>and output like so:<p><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr><pre>
counter = 1 pulse = 1
counter = 2 pulse = 1
counter = 3 pulse = 3435
counter = 4 pulse = 1
counter = 5 pulse = 7
counter = 6 pulse = 1
counter = 7 pulse = 2
counter = 8 pulse = 1
counter = 9 pulse = 2
counter = 10 pulse = 1
counter = 11 pulse = 4
counter = 12 pulse = 3
counter = 13 pulse = 3435
counter = 14 pulse = 1
counter = 15 pulse = 1
counter = 16 pulse = 1
counter = 17 pulse = 2
counter = 18 pulse = 1
counter = 19 pulse = 3
counter = 20 pulse = 3429
...
counter = 85 pulse = 1
counter = 86 pulse = 3433
counter = 87 pulse = 4
counter = 88 pulse = 3429
counter = 89 pulse = 2
counter = 90 pulse = 1
counter = 91 pulse = 3
counter = 92 pulse = 1
counter = 93 pulse = 3
counter = 94 pulse = 2
counter = 95 pulse = 3436
counter = 96 pulse = 1
counter = 97 pulse = 1
counter = 98 pulse = 1
counter = 99 pulse = 2
counter = 100 pulse = 3438
All Done.
</pre><hr></blockquote><p>The pulses should be squarish coming from the RX, but without a scope I’m having difficulty fine tuning my circuit & code to read them. Any help appreciated.<p>Thanks,
Bart
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: Reading servo signal from JR receiver

Post by dyarker »

A servo moves based on the width of the pulses, which come in a steady stream. 1mS to 2mS every 20mS if memory serves. 1.5mS for servo center.<p>I don't know Stamp code so can't help anymore.<p>Cheers,
Dale Y
barthirst
Posts: 4
Joined: Sun Jul 11, 2004 1:01 am
Contact:

Re: Reading servo signal from JR receiver

Post by barthirst »

Thanks Dale. <p>I think murphy's law is getting me.. i'm looking at the output I posted, and it doesn't look garbagey at all, in fact it looks like something to work with. However I made that output I can't seem to reproduce it! What i'm getting is _way_ more erratic than that.
wd5gnr
Posts: 104
Joined: Wed Dec 19, 2001 1:01 am
Contact:

Re: Reading servo signal from JR receiver

Post by wd5gnr »

I doubt the Stamp can read fast enough to get both sides of the square. So you are actually skipping some parts for example:
<blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr><pre>
--___-----_____-----____
A B C D
</pre><hr></blockquote><p>You might be reading A and D, for example. You also may be getting noise along the servo line?<p>A lot of people use this chip with the Stamp for just this purpose.
barthirst
Posts: 4
Joined: Sun Jul 11, 2004 1:01 am
Contact:

Re: Reading servo signal from JR receiver

Post by barthirst »

Al, thanks for the tip. Also your website is excellent with lots of cool products!<p>To add a little closure to this thread: I did get something working. Apparently I had the servo signal wire _way_ too far away from the I/O pin. I plugged the signal wire directly into the I/O pin breadboard port, and viola, started getting a discernable reading. I had to filter it a bit in the code, but finally something to look at:<p><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr><pre> <p>' {$STAMP BS2}
' {$PBASIC 2.5}<p>time VAR Word<p>Main:
DO
PULSIN 15, 1, time<p> IF (time > 500) AND (time < 1100) THEN 'filter out bogus readings<p> DEBUG HOME
DEBUG DEC time<p> ENDIF<p> LOOP
</pre><hr></blockquote><p>This seems to work fine with pulses showing up between 533 & 1033 for servo movement range.<p>Now I can start coding!
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: Reading servo signal from JR receiver

Post by dyarker »

Curious, is sample rate on that pin 533000 samples per second?
Dale Y
barthirst
Posts: 4
Joined: Sun Jul 11, 2004 1:01 am
Contact:

Re: Reading servo signal from JR receiver

Post by barthirst »

Not sure. How would i be able to measure?<p>Bart
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests