BS2 PULSIN questions
Hi,
I'm obviously new here, but am also new to electronics so please be gentle.
One of the things I was trying to do last night but failed miserably at was to use the PULSIN command to collect a servo signal from a standard FM/PPM R/C receiver. I did verify that the receiver works by driving a servo, but when I connected the input pin to my BS2 (the receiver was powered separately from the STAMP board), I couldn't seem to get any data from it. I presume my issue is syntax, but i'm not sure.
In effort to help myself, I reviewed the help files and pasted some example code to try that and while I did start getting values come in it was obviously garbage. I realized it was garbage when it started printing to the screen when I would even touch the input pin (in this case, pin 7). So, I seem to have accidentally developed some form of bio touch thingamabob, but hardly what I intended on doing
So, can anyone provide any input on how I might successfully collect PWM/PPM data? Once I get·some clean data, I plan on trying to just do some experiments with making some changes to the data and firing it back out via PULSOUT to motors or something.
Thank you!
·
I'm obviously new here, but am also new to electronics so please be gentle.
One of the things I was trying to do last night but failed miserably at was to use the PULSIN command to collect a servo signal from a standard FM/PPM R/C receiver. I did verify that the receiver works by driving a servo, but when I connected the input pin to my BS2 (the receiver was powered separately from the STAMP board), I couldn't seem to get any data from it. I presume my issue is syntax, but i'm not sure.
In effort to help myself, I reviewed the help files and pasted some example code to try that and while I did start getting values come in it was obviously garbage. I realized it was garbage when it started printing to the screen when I would even touch the input pin (in this case, pin 7). So, I seem to have accidentally developed some form of bio touch thingamabob, but hardly what I intended on doing

So, can anyone provide any input on how I might successfully collect PWM/PPM data? Once I get·some clean data, I plan on trying to just do some experiments with making some changes to the data and firing it back out via PULSOUT to motors or something.
Thank you!
·
Comments
·· Check Mike's comments above.
·· Pulsin is definitely the way to read the signals from the radio receiver.
· I've attached a little test program I used on a 4-channel job. I've shortened it so only the first 10 or so lines run. You can play with the rest of it when you get the signals into the Stamp.
··· Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
You were exactly right. I assumed that since the receiver was powered that I wouldn't need anything additional for the pin to make use of the pulse. Like I said, i'm new! That's my excuse and i'm sticking to it. I will try that this evening and expect that it will make all the difference in the world. Thanks.
D
Thank you for the reply and the sample code. I will check it out this evening and let you guys know what happens. I really appreciate the help. I wish I knew this stuff was so much fun years ago...
D
Thank you,
D
When the stamp (I'm assuming a BS2)measures pulsewidth, the counts it measures are in units of 2 usec. Therefore, when you see 473 on the debug screen, thats 473 * 2 usec = 946 usec, which is pretty close to 1 msec. Similarly, 1026 * 2 usec = 2.05 msec which is at the opposite extreme.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
The strange thing is though: 1.5ms (~ 750) isn't anywhere near center for this servo for whatever reason. I actually had to subtract 120 from it to center. After doing so though, it did allow for full throw on both sides
Thank you!
D
Post Edited (Neptune77) : 5/29/2008 3:27:08 PM GMT
On one of the servos I have, that represents about 180 degrees of rotation from full clockwise to full CCW. So, I'd say I have (1000-500)/180 or 2.8 units per degree, with an offset of 500. To position it halfway (ie 90 deg) I send a pulsewidth of: (90*2.8)+500 = 750 . Based on your servo's actual mechanical range, you can adjust the equation.
I'd be a bit cautious about starting down the road to talking about servos in terms of "steps". These little servos were originally designed for the R/C model business where the response was gauged in analog fashion by the operators eye and the joystick on the control unit. It was never meant to give exceptional repeat accuracy (which is why there's a trim pot on the controller at center). When we use the term "steps", its usually with respect to stepper motors which are an entirely different beast.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Anyway, I·am aiming·to write a little code that will count how many times the value changes from·full stick·deflection to full deflection in the opposing direction. This will help me understand how transmitter resolution falls into the mix. Also, it will help me see the effects of what I did by subtracting 120 to center the stubborn·servo, as far as assymetrical throws are concerned.
I've read that my particular transmitter offers 10-bit resolution, or what I've also heard people call 1024 steps (2^10). My understanding·of this is when I count the number of value changes across the .94mS - 2.1mS range, that there should be ~ 1024 changes to respresent the 10-bit resolution of the radio. If I see that with my counter I will have confirmed that and will have hopefully learned my lesson for the·evening [noparse]:)[/noparse]·Of course, I just realized that the BASIC stamp might not be capable of displaying enough precision to prove this point?
I would suspect that the offset that I forced on the servo would·result in·an·assymetrical number·of stick·"steps" in one direction versus the other. However, visually it would seem that in spite of the offset that I programmed in, the servo throws are identical either direction.·Any bets on what the results will be?
Thanks again,
Damon
Post Edited (Neptune77) : 5/29/2008 8:17:00 PM GMT
This snippet of code works fine for getting a PWM servo input then outputting to 2 separate·servos depending on whether the signal is over or under 1.5mS. However, if I enable the line in red then the servos twitch erratically. Any ideas why that would be? I would assume the BASIC stamp can handle inputs from multiple sources in the same loop, but who knows...
' {$STAMP BS2}
' {$PBASIC 2.5}
RePulse·· PIN·· 13·· ' pulse output pin
FrPulse·· PIN·· 15
Throttle·· VAR·· Word
PitIn·· VAR·· Word·· ' PulseIn value
Main:
· PULSIN 3, 1, PitIn·· ' Measures positive pulse
· 'PULSIN 7, 1, Throttle
· 'IF (PitIn > 0) THEN·· ' If PWM value not 0
··· DEBUG HOME,
········· DEC PitIn * 2, " units ", CLREOL·· ' Displays raw PWM input values in mS
· IF (PitIn * 2) > 1500 THEN
··· PULSOUT RePulse, PitIn·· ' If PWM input greater than 1.5mS drive rear motor to go forwards
· ENDIF
· IF (PitIn * 2) < 1500· THEN
··· PULSOUT FrPulse, PitIn·· ' If PWM input less than 1.5mS drive front motor to go backwards
· ENDIF
· 'IF (Throttle > 0) THEN·· ' If PWM value not 0
··· DEBUG DEC Throttle * 2, " units ", CLREOL
··· PitIn = PitIn + Throttle
· 'ENDIF
· 'ELSE
··· 'DEBUG CLS, "Out of Range"·· ' Error message if PWM = 0
· 'ENDIF
· GOTO Main
· END
-Phil
Is there any chance that this could be that I didn't actually hook up an input to PIN 3? I would assume that the chip would simply ignore it if there were no signal, but instead it's causing all this havok. Is it possible that I need to have something there in order for it to run smoothly?
In case you're wondering, the reason that I don't have an input there is because I don't have the additional servos yet. I was trying to "code ahead"
Thanks,
Damon