Shop OBEX P1 Docs P2 Docs Learn Events
How long does PULSIN take? — Parallax Forums

How long does PULSIN take?

Armored CarsArmored Cars Posts: 172
edited 2004-12-15 20:08 in BASIC Stamp
When in manual mode my car is really jerky, how long does PULSIN take so I can adjust PAUSE accordingly?

MANUAL:
··· DO
····· PULSIN 2, 1, mansteer
····· PULSIN 3, 1, mandrive
····· IF mansteer<400 THEN GOFWD
····· PULSOUT 0, mansteer
····· PULSOUT 1, mandrive
····· PAUSE 20
··· LOOP

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2004-12-14 20:08
    What version of stamp are you using?

    If you are running Pbasic...hit F1 and look up PULSIN.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    http://www.geocities.com/paulsopenstage

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."

  • Armored CarsArmored Cars Posts: 172
    edited 2004-12-14 20:17
    Im using a BS2 and I did look, all I found was a chart which stated the maximum pulse width, which Im assuming is not how long it takes since a 140 ms pause is much longer that how fast my car was jerking.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-14 20:27
    I believe 'PULSIN' waits for the beginning of the pulse up to 131 mSec, then waits for the end of the pulse up to 131 mSec.

    And 140 mSec is like 1/10 second. I believe you can 'percieve' that short a time -- but not enough to say "is much longer than how fast my car was jerking".

    One way to minimize this would be to only do a single PULSIN per loop. Thus:

    CheckMan VAR BIT

    MANUAL:
    · DO
    ··· CheckMan = ~CheckMan
    ··· IF CheckMan THEN
    ····· PULSIN 2, 1, mansteer
    ····· PULSIN 2, 1, mansteer
    ··· ELSE
    ····· PULSIN 3, 1, mandrive
    ····· PULSIN 3, 1, mandrive
    ··· ENDIF
    ··· IF mansteer<400 THEN GOFWD
    ··· PULSOUT 0, mansteer
    ··· PULSOUT 1, mandrive
    ···' ·PAUSE 20
    · LOOP

    Now, if you are driving pins 2 and 3 with the output of a Servo reciever, it is probably repeating at a 20 mSec rate -- but you don't know when you start to sample it.· It could be 40 mSec worst case.· If the Servo pulse has already started before you start to sample it, you may read it as 'too short'.· Outputting a 'too short' servo pulse could make you jerky.

    One solution could be to read the servo signal twice, and take the second signal as the one you'll keep.· That should·guarantee that the second signal gets both the start·AND end of the pulse.· Then you probably don't need a 'pause' at all, because reading the servo signal will take that much time.

    OK, I've now updated the code above to do the 'read servo input signal twice'.· You still want to read only steering, or only drive, each time through the loop, but you can update both servos each time through the loop.· This should work.

    Post Edited (allanlane5) : 12/14/2004 8:36:46 PM GMT
  • Shawn LoweShawn Lowe Posts: 635
    edited 2004-12-14 22:46
    Check out Tracy Allens website: www.emesystems.com. He probably has a good write up on the time of execution of the pulsein command.
    Shawn Lowe
  • Armored CarsArmored Cars Posts: 172
    edited 2004-12-15 19:12
    I think Ill use relays to switch the servos to manual control, but I have another question.
    After about a minute of using the code

    MANUAL:
    DO
    PULSIN 2, 1, mansteer
    PULSIN 3, 1, mandrive
    IF mansteer<400 THEN GOFWD
    PULSOUT 0, mansteer
    PULSOUT 1, mandrive
    LOOP

    mandrive will start to equal mansteer. I didn t have enough wires to run anything to pin 3, but after awhile it starts copying pin 2.

    What this code is doing is taking the pulse from an RC reciever and sending it to the servos.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-15 19:24
    If pin 3 is 'open', i.e. nothing connected to it, you have what is called a 'floating input'. These can pick up RF from the air really easily -- typically 60 HZ AC flourescent lamp noise.

    And WHAT DO YOU MEAN you are doing a 'pulsin' on a pin with nothing connected? That's going to time-out every time! That's a 131 mSec delay in your program every loop. If you HAVE no input signal, don't try to READ an input signal.

    At least tie the pin to ground with a 22 Kohm resistor, to give yourself a 'soft' ground signal.
  • Armored CarsArmored Cars Posts: 172
    edited 2004-12-15 20:08
    I went ahead and added the extra PULSIN because I would be using it once I got the wires to hook it up, I didnt realize it took any longer. That was the problem though, thanks.
Sign In or Register to comment.