Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Timing — Parallax Forums

BS2 Timing

CanYouC3DCanYouC3D Posts: 6
edited 2004-08-15 18:32 in BASIC Stamp
Hi All
·freaked.gif
Help!!

·I have a program that needs to read the status of five pins (P5 – P1) and then increment a counter for each pin if they are high an this has to happen in 5mSec.

And I’m stuck with a BS2 because timing of my shiftout and shiftin data.
·
A Stamp User From the Startyeah.gif

Post Edited By Moderator (IT Guy (Parallax)) : 8/14/2004 5:20:12 PM GMT

Comments

  • CanYouC3DCanYouC3D Posts: 6
    edited 2004-08-14 01:22
    opps!! I should have said BS2 Timing
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-14 01:22
    This is pretty easy:
    ·
    counter = counter + IN1 + IN2 + IN3 + IN4 + IN5
    


    PS: You're likely to get more help in these forums if you add an appropriate subject title to your post.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-08-15 18:16
    Oh, Jon, you left out so much!

    First, you MUST set those pins as inputs.
    Next, it looked to me like the poster wanted a separate
    count per input pin.

    Next, you COULD read all 5 pins at the same time.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-15 18:32
    Remember... the BASIC Stamp resets ALL pins to inputs.· They only have to be made inputs via code if the program has previously made them outputs, and that does not seem to be the case here.· A common beginer's mistake is to declare pins as inputs when they've never been made outputs; it's just a waste of valuable code space.

    CanYouC3D was not clear in the increment values, his post reads to me as if he wants one count per pin high.· If, on the other hand, he does want them have differnt values -- and even more conveniently a binary switch is being used, this will do it:

    counter = counter + (INL & %00111110 >> 1)
    


    This is safe code; it masks the other pins on INL so they do not affect the counter.· And just in case the goal is to have a delay that is five milliseconds multiplied by the inputs P1-P5 (binary), this is simple:

    delay = 5 * (INL & %00111110 >> 1)
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.