Shop OBEX P1 Docs P2 Docs Learn Events
Decoding a BCD input — Parallax Forums

Decoding a BCD input

StevezilaStevezila Posts: 35
edited 2009-08-24 17:32 in BASIC Stamp
Can anyone advise me in the best way to decode BCD inputs from a 0-9 digit BCD thumbwheel switch? Actually I need to have two thumbwheel switches to represent a given time between 1 and 5 seconds with 1/2 second intervals. eg. 1.5 2 2.5 3 3.5 ect. The first thumbwheel would be the whole number and I only need to be concerned with the first three pins on the switch 1,2,4. On the second switch I really only need to look at the 1 and 4 pins because it is either a half second or not. I suppose that I could do an If statement to evaluate each of the pins, something like If 1=1 and 2=1 and 4=0 then timer=3 seconds but is this the best way to do this. I will need to evaluate two of sets these·of thumbwheels plus I have·7 or so inputs and 3 outputs already planned so I think I'm running out of pins on my BS2 unless I evaluate my timers and then use those pins for other inputs/outputs. Please advise


Thanks·· confused.gif

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-08-21 02:59
    Stevezila

    Can You be more specific with the hardware inputs?

    I'm afraid to post any code with out knowing this first. as I would be picked apart piece by piece, Cut to shreds for a simple typo.

    __________$WMc%_______

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············································ BoogerWoods, FL. USA
  • agfaagfa Posts: 295
    edited 2009-08-21 04:20
    If you're concerned with the·number·of I/O pins used, you could·select 1 to 5 seconds in .5 second intervals with just one BCD thumbwheel.· You can test the value of a·series of·I/O pins using INA, INB, INC, IND, INL, INH,·or INS instead of testing individual I/O values.
  • StevezilaStevezila Posts: 35
    edited 2009-08-21 14:31
    Thanks for the replies.

    I am trying to take the value of·two BCD thumb wheel switches·and come up with a decimal number that I can·put into the value of·a "wait" command. I have two seperate counters that I need to do this for.For this application an operator sets values on two seperate sets of thumbwheels to adjust the time·for a "wait" before the program continues·with a range of between 1 and 5 seconds with adjustments in 1/2 second increments. the reason for two thumbwheels is·so that the operator has a better "Picture" of the adjustments they·are making 3.5,4.7 ect.·They make thumbwheels in a decimal configuration- 9 pins with a common- and BCD config. 4 pins with a common. Not sure how best to do this but I am concerned about not having enough I/O using a BS2.·as I have other inputs /outputs as well.

    Comments and advise appreaciated

    Thanks
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-08-21 20:15
    Why not use a single hexadecimal switch (4 bits, 16 positions) to set a number of half-seconds, from 0 to 15?

    If you're really shy of inputs, you could use a single pin on the Stamp.· Put resistors to ground from the 4 bits of the switch; tie the other ends of the switch contacts together, add a capacitor, and measure the resulting RC time constant with a single Stamp I/O pin.· For example, if you used resistors of 100, 200, 400, 800 ohms, there would be 16 possible RC time constants, depending on which contacts were open and which were closed in each of the 16 switch positions.· The program could then decide how many half-seconds were meant.

    By my calculations, there are exactly 1.73433 gazillion other ways to do this if you don't happen to like this way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • agfaagfa Posts: 295
    edited 2009-08-21 22:18
    Stevezila

    This link will expand on the method Carl suggested.· http://www.emesystems.com/BS2rct.htm#switches

    Take a look at the rest of this site.· Lots of good stuff.

    agfa
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-22 02:31
    The simplest way to decode two BCD decimal switches is to use BRANCH or LOOKUP commands.
  • StevezilaStevezila Posts: 35
    edited 2009-08-23 07:16
    Hey thanks for the replys!

    First I think that using a hex switch is·probably better than using two switches and second using the RC method I'm really going down on the use of inputs.



    agfa thanks for the link, really cool site



    Thanks again
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-23 19:06
    It’s you nickel and your decision. But I thought that you were designing for the operator and not for the designer “convenience” by using two switches to start with. I think good engineering practice would be to keep the user happy. But that is my personal take on it.
    I would stay away from RC circuits – too component tolerance dependent and you are shifting from software solution to hardware.
    Have you considered multiplexing your devices?
    Most applications are not that “real time” sensitive, but you would have to multiplex more than two BDC switches ( in you case only 3 + 2 wires which is not much saving) to make it effective.
    ·
  • StevezilaStevezila Posts: 35
    edited 2009-08-24 17:32
    Thanks that is a good point but it will be a lot easier if i eliminate the second switch and I understand how to make it work this way. I'm not sure how to multiplex the two switches and really the second switch would only use one digit to display the half second setting.



    Thanks
Sign In or Register to comment.