Shop OBEX P1 Docs P2 Docs Learn Events
BS2 PULSIN questions — Parallax Forums

BS2 PULSIN questions

Neptune77Neptune77 Posts: 8
edited 2008-05-30 12:48 in BASIC Stamp
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 tongue.gif

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

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-28 14:15
    You probably connected only one wire between the receiver and the Stamp board (the signal wire). You always need a reference signal (ground) and you probably did not provide that. Basically, you need to connect the "ground" of the receiver to the "ground" of the Stamp board. Without this, the Stamp input is "floating" in reference to its ground and just acts as an antenna. As you noticed, it makes a fair touch sensor as it picks up induced voltages in your body.
  • stamptrolstamptrol Posts: 1,731
    edited 2008-05-28 14:18
    ·Neptune,

    ·· 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
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-28 14:37
    Hi Mike!

    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




    Mike Green said...
    You probably connected only one wire between the receiver and the Stamp board (the signal wire). You always need a reference signal (ground) and you probably did not provide that. Basically, you need to connect the "ground" of the receiver to the "ground" of the Stamp board. Without this, the Stamp input is "floating" in reference to its ground and just acts as an antenna. As you noticed, it makes a fair touch sensor as it picks up induced voltages in your body.
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-28 14:38
    Hi!

    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


    stamptrol said...



    ·Neptune,

    ·· 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,


  • Neptune77Neptune77 Posts: 8
    edited 2008-05-29 02:39
    Thanks for the advice guys. I was able to get the data input into the stamp, but I had another question I hope you might help with. I was a little surprised to see that the range was 473 - 1026. It just seems a bit arbitrary to me. I guess I assumed it would be 0-255, or 0-512 or something like that. Can anyone explain to me the significance of the range that I am seeing? For the record, the transmitter's trim is currently centered.

    Thank you,

    D
  • stamptrolstamptrol Posts: 1,731
    edited 2008-05-29 11:56
    What you're measuring is the pulsewidth of the signal from the radio. For use with servos, thats in the range 1 msec to 2 msec. When the servo sees a pulse width of 1.5 msec, it will hold at its center position.

    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
    ·
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-29 14:04
    OK, that makes sense. I suppose I will simply multiply the output x 2 so that the output makes more of connection in my mind. So, in order to see how many steps the servo is taking in that range, I would need to somehow code a way to count each step? Not trying to be spoon fed and I am trying to conceive of a way to do just that, but any suggestions are greatly appreciated.

    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
    stamptrol said...
    What you're measuring is the pulsewidth of the signal from the radio. For use with servos, thats in the range 1 msec to 2 msec. When the servo sees a pulse width of 1.5 msec, it will hold at its center position.

    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,

    Post Edited (Neptune77) : 5/29/2008 3:27:08 PM GMT
  • stamptrolstamptrol Posts: 1,731
    edited 2008-05-29 19:25
    Just for an example, say your range was 500 to 1000.

    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
    ·
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-29 20:11
    Thanks. In this case, I was using step as meaning value change. I will try to take greater care in my term usage, but please understand that I am very new at the technical side of this stuff.

    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
    stamptrol said...
    Just for an example, say your range was 500 to 1000.

    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,

    Post Edited (Neptune77) : 5/29/2008 8:17:00 PM GMT
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-30 05:45
    All right, so i'm having some new issues, but I'm really trying here.

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-05-30 05:59
    It may well be that the additional statement is adding too much delay between pulses to your servos. Typically, you want to send a pulse every 20ms or so. If you exceed this by too much, the servos can behave as you observe.

    -Phil
  • Neptune77Neptune77 Posts: 8
    edited 2008-05-30 12:48
    In this event, is it my poor coding, or is it the limit of the BASIC stamp? This seems like a very simple set of functions, but i also know these chipcs can only do so many calculations/s. Any ideas on how to improve the situation. As soon as remark out that line, output for the other 2 motors is fine.

    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
    Phil Pilgrim (PhiPi) said...
    It may well be that the additional statement is adding too much delay between pulses to your servos. Typically, you want to send a pulse every 20ms or so. If you exceed this by too much, the servos can behave as you observe.

    -Phil
Sign In or Register to comment.