Shop OBEX P1 Docs P2 Docs Learn Events
counting variable — Parallax Forums

counting variable

ArchiverArchiver Posts: 46,084
edited 2001-03-26 02:25 in General Discussion
I am using an optical slotted switch (interrupter) as an encoder to
generate pulses from a slowly rotating disc attached to a wheel.· The
disc has 32 slots cutout along its diameter.· As the slots move thru
the optical slotted switch, pulses are generated. The wheel moves in
one direction for a certain number of slots or it will move in the
opposite direction for a number of slots.· It is designed to never
complete a full rotation.· The rotation is slow because the wheel has
reduction gears on it.· If I want, I could design a disc with twice
as many slots for a more accurate positioning, but 32 slots is good
for right now.· As you can imagine, the pulses generated by this
wheel come very slowly.· My question is this: If I want to stop this
wheel after any given number of pulses in either direction, how would
I construct the program?· I know that I need to use a count variable,
but I am unsure how to use it.· Please show me a sample program using
the count variable. Thank you.

Ken

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-03-26 02:21
    You won't know which direction it is going with only one opto interupter.
    Some fuel systems I work with use 3 opto's to detect direction (reverse flow
    generates an error). 3 opto's is probably the answer, but the code would
    take a bit of work. Perhaps some external logic control before the stamp
    might be worth a thought.
    Otherwise a microswitch lightly dragged by the wheel in either direction
    could be a simple answer. The switch would be on in one direction and off in
    the other. If you could do this, the code would require you to first sense a
    change in the opto state, then check the direction of the microswitch. Sorry
    dont have time to help with code at the moment.
    Chris


    Original Message
    From: <bunkleybot@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, March 26, 2001 7:54 AM
    Subject: [noparse][[/noparse]basicstamps] counting variable



    I am using an optical slotted switch (interrupter) as an encoder to
    generate pulses from a slowly rotating disc attached to a wheel. The
    disc has 32 slots cutout along its diameter. As the slots move thru
    the optical slotted switch, pulses are generated. The wheel moves in
    one direction for a certain number of slots or it will move in the
    opposite direction for a number of slots. It is designed to never
    complete a full rotation. The rotation is slow because the wheel has
    reduction gears on it. If I want, I could design a disc with twice
    as many slots for a more accurate positioning, but 32 slots is good
    for right now. As you can imagine, the pulses generated by this
    wheel come very slowly. My question is this: If I want to stop this
    wheel after any given number of pulses in either direction, how would
    I construct the program? I know that I need to use a count variable,
    but I am unsure how to use it. Please show me a sample program using
    the count variable. Thank you.

    Ken





    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-26 02:25
    Wire the interrupter to a port and increment a counter every time you get a
    0 or 1 value.

    Pulses = 0

    Loop:

    'MOTOR ON

    IF IN0 = 1 THEN Count

    GOTO Loop

    Count:

    Pulses = Pulses + 1

    IF Pulses = 32 THEN Exit_Loop

    GOTO Loop

    Exit_Loop:

    'MOTOR OFF

    Original Message

    I am using an optical slotted switch (interrupter) as an encoder to
    generate pulses from a slowly rotating disc attached to a wheel. The
    disc has 32 slots cutout along its diameter. As the slots move thru
    the optical slotted switch, pulses are generated. The wheel moves in
    one direction for a certain number of slots or it will move in the
    opposite direction for a number of slots. It is designed to never
    complete a full rotation. The rotation is slow because the wheel has
    reduction gears on it. If I want, I could design a disc with twice
    as many slots for a more accurate positioning, but 32 slots is good
    for right now. As you can imagine, the pulses generated by this
    wheel come very slowly. My question is this: If I want to stop this
    wheel after any given number of pulses in either direction, how would
    I construct the program? I know that I need to use a count variable,
    but I am unsure how to use it. Please show me a sample program using
    the count variable. Thank you.
Sign In or Register to comment.