Shop OBEX P1 Docs P2 Docs Learn Events
counting a 2 switch logic circuit — Parallax Forums

counting a 2 switch logic circuit

gc3076gc3076 Posts: 44
edited 2006-02-17 21:35 in BASIC Stamp
I am still a newbee to the BS2 programming and can't believe what a powerful learning tool this form is, amazing !

I am trying to complete, what I am assuming would be a pretty simple task. I would like to keep a running incremented / decremented real time count of a 2 switch logic circuit.··

Suggested approaches or sample sites would be appreciated................

SW1······ ·SW2

0··············· 0······· no change of state, count remains 0

0··············· 1

····· then·············incremented count, +1

1·············· 0

1·············· 0

····· then··········decremented count, -1

0············· 1








·

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-13 17:49
    Start with a variable, X = 0
    If Button2 pushed Then X = X + 1
    If Button1 pushed Then X = X - 1

    ·
  • gc3076gc3076 Posts: 44
    edited 2006-02-13 18:26
    I see the the below logic but am finding·it hard to get through in my head how to code the momentary change in logic state.

    x=0
    x=x+1
    x=x-1

    Here is the thing, I am using 2 stationary hall-effect sensors mounted closely together ·and 1 rotating magnet. I am not sure how to code the below logic.

    1. A_hall goes high then B_hal goes high, increment counter (CW) or x=x+1

    2. B_hall goes high then ·A_ hall goes high, decrement counter (CCW) or x=x-1

    Help !!!!!!!!


    Post Edited (gc3076) : 2/16/2006 8:27:36 PM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-02-13 20:02
    Post Edited (gc3076) : 2/14/2006 11:44:24 AM GMT
  • gc3076gc3076 Posts: 44
    edited 2006-02-16 20:29
    Sorry to be a pest but I am struggling here any ideas ??
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-16 20:44
    · I figured that you were using buttons, or something, but you're actually trying to do an encoder wheel of some sort (??).· I don't think you can make that happen with two sensors and one magnet.
    · An optical encoder wheel·has two sensors and a number of alternating dark and white (or dark and clear) vanes.· The sensors have to be positioned so that neither will transition at the same time.

    http://www.active-robots.com/products/motorsandwheels/wheel-encoders.shtml

    Post Edited (PJ Allen) : 2/16/2006 8:51:41 PM GMT
  • SN96SN96 Posts: 318
    edited 2006-02-16 21:05
    There needs to be some kind of flip flop system (John Kerry Effect?) in the code. Then there is the issue of a/b b/a getting confused. say you are on an a/b sequence, and then "a" is miss read by the sensor, you would then be on a b/a sequence again. I don't know on this one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-16 21:36
    Folks -

    A flip-flop is easily accomplished in software by exclusive ORing a bit with 1. This can be seen in the following truth table:

    /code

    Exclusive OR
    Bit with One
    1
    0 1

    1 0
    code/

    Then you can use the following:

    flip_flop var bit

    flip_flop = flip_flop ^ 1

    ON flop_flop, GOTO Routine1, Routine2

    I'm not sure what you were trying to accomplish however.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • gc3076gc3076 Posts: 44
    edited 2006-02-16 22:24
    The Oring sounds like an interesting approach.

    I am trying to use the 2(qty) hall sensors, mounted·closely together (stationary) and 1(qty) magnet rotating with a spinning jack screw. I want to keep count of the jack screws rotations and display the·total result of the +·\ - rotations· that happened on a LCD.

    -5 CCW + 6 CW = 1 rotation

    Cheers,

    g.c.
  • gibbmangibbman Posts: 98
    edited 2006-02-17 01:38
    Mike (SN96) said...
    There needs to be some kind of flip flop system (John Kerry Effect?) in the code. Then there is the issue of a/b b/a getting confused. say you are on an a/b sequence, and then "a" is miss read by the sensor, you would then be on a b/a sequence again. I don't know on this one.
    Oh joy, politics on a Parallax forum! My guess is that the a/b b/a confusion factor is more of a W effect. Excuse my disassembling....
    With good nature,
    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    In the end, it seems that it's all about getting the LEDs to blink....
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-17 04:37
    Have a look at Scott Edwards' rotary encoder program for the BS1 -- it might lead to an answer.

    http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv8.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • gc3076gc3076 Posts: 44
    edited 2006-02-17 19:37
    Ok, I think I am moving away from the Hall-effect sensor to complete this task. What do you think about a rotary encoder as shown in the example Jon has mentioned. I want this to count revolutions and show CW/CCW direction.



    6CW-10CCW= 4 revolution result

    Will the below/enclosed encoder count CW/CCW revolutions ?



    Post Edited (gc3076) : 2/17/2006 7:46:17 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-17 20:49
    gc3076 said...
    Will the below/enclosed encoder count CW/CCW revolutions ?
    Yes, but...
    Actually --·you're going to get several "clicks"/pulses·per revolution (hence, "16 or 32"), not one pulse per revolution.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-17 21:35
    gc3076 -

    Now that you've been a bit more specific about what you're intending to do, what you need is a quadrature encoder. There are Hall Effect quadrature encoders, as well as optical ones, and other types as well.

    Allegro makes a nice small Hall Effect one which I've used quite successfully before. You can find it here: http://www.allegromicro.com/sf/3425/

    Thanks to Dr. Tracy Allen, here are some excellent applications notes on the use of quadrature encoders with the PBASIC Stamp:
    http://www.emesystems.com/BS2fsm.htm#twobit

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
Sign In or Register to comment.