Thumb counter interface with microcontroller

Discussion in 'The Projects Forum' started by Chris11jed, Jan 14, 2014.

  1. Chris11jed

    Thread Starter New Member

    Dec 15, 2013
    16
    0
    Hi all,

    Hope I'm posting in the right place, if not please forgive me...

    I have a question about a project I'd like to get some ideas for.

    I have some 3-digit thumb wheel counters I got from work after they were about to be thrown away. See attached images.

    I want to use them in a project. The project will see them used as a user interface between a PIC16F887 microcontroller and some water pumps. There are five of them. One will be used to set an "interval" counter (e.g. count to the set number and then run the pumps). The other four tell the PIC how long in seconds to run the four pumps.

    My question to anyone/all is how would be the best way to interface these thumb wheel counters to the PIC.

    The counters have a resistance from 0Ω to 999000Ω, that is '000' = 0Ω, '001' = 1KΩ, '100' = 100KΩ, '999' = 999KΩ. This I have measured between two wires connected to the counters.

    I have thought about using the PIC's ADC. Where I'd connect from the +5V supply, a resistor say 4KΩ, then the thumb wheel counter and then to ground. The ADC would be connected between the 4KΩ and the thumb wheel counter. (+5V)----|(4KΩ)|---(ADC-input)----|(Thumb-wheel-counter)|---(GND)

    My problem is that I would like to know if this would be okay, or is there a better way?

    I have done some quick voltage divider sums and at low counts, say '001' to '010' the jumps between volts to the ADC are at 1/10th of a volt to a volt. This is okay. However when you start getting up in the count number the jumps in voltage between numbers starts to get thin, e.g. '500' to '999' 1/10th to 1/100th of a volt.

    Knowing the ADC has a 10-bit resolution, the thinner the jump between higher numbers the more I feel there is for numbers to be mixed up or sensed by the PIC as the wrong number. Or that the PIC will sense the higher numbers as one because of the 1/100th of a volt divisions is too much for the ADC resolution/input.

    I could break the resistance between all 3-digits and have 10KΩ per unit. That is 1st digit (units) = 0-10KΩ, 2nd digit (tens) = 0-10KΩ and 3rd digit (hundreds) = 0-10KΩ. And then add all the ADC reads to get a 3-digit number. However with five counters and 3-digits per counter, that's a lot of pins to use. The 0-999KΩ 3-digit method is what I would like to use.

    So with all that information, I hope someone can put forward some ideas and suggestions. If I'm on the right track, cool :cool: If I'm way off, please tell me :rolleyes:

    The other idea I had was to use the resistance of the counter and a capacitor and connect them to a pin that would count the time it takes to charge and discharge the cap. I'm not fully aware how to do that, circuit wise and programming wise, so if that's the best way... help ;)

    Thank you for your time and any/all help
    Chris
     
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    There's something perverse about this, because you're taking a digital input (the thumbwheel positions) and turning it into an analog level, then planning to digitize it again.

    With 1000 separate states, you may not be able to get each one accurately sensed, but you certainly shouldn't be using a simple voltage divider--as you say, it is nonlinear, and you lose resolution at the higher resistance end. What you want is a constant current fed through the device, so the voltage goes up in proportion to the resistance. I think 5 microamps is what you want. So with 1K you'd read 5mV, and with 999Kohms you'd get 4.995V. If you ran the processor on 5.12V (or at least make the reference of its A/D 5.12V) that would give you a reading of 999 at 4.995V. But then, the output of your resistance-to-voltage device would be at a variable impedance which the A/D converter wouldn't like, so you'd need a buffer amplifier, and then what would the accuracy be? I can see this design working much better in theory than in reality.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    What you have are thumb-wheel switches with 1-of-10 selector output.
    Then someone added a resistor pack on the output to create a voltage divider to give you 1-of-10 output voltages.

    You can measure this voltage with an ADC to give you the position of the switch.

    Use three ADC channels to measure each of the three thumbwheel switches separately.
     
  4. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Welcome to AAC.

    Is that a C in the display or a poor 0? The former would suggest a hexadecimal counter: 0-9, A-F.

    I see ten connections but if it were a 1-of-10 selector switch, wouldn't there be a common connection (11 connectors total)? Or would that be on the backside of the board?

    Could the OP change the resistor pack to get a better range? Better being a relative term.

    In any event, you can spend a lot of time making these work using ADC, but if it were me, I'd get some cheap BCD switches from eBay. You then read four digital signals from each switch, BCD code, which will always be precise. Now this means 12 I/O pins on your PIC, but you can add small signal diodes and use 7 I/O's instead (4 inputs from switches in parallel, 3 outputs to power common pin, one at a time). Alternately, you can use a I/O expander IC such as the MCP23017.

    This is just how I'd do it. Using what you have with ADC will require less money and hardware.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    Replacing your thumbwheel switches with ones that provide BCD output is an alternative solution.

    You can multiplex the three switches and thus require 4 + 3 = 7 interface pins whereas going the analog route requires 3 pins.

    I am certain there is an 11th pin which we cannot see from the photograph.
     
  6. Chris11jed

    Thread Starter New Member

    Dec 15, 2013
    16
    0
    Thanks to everyone for your replies.

    I've added some more pics to help clear up the thumb-wheel counter.

    The light blue thing is the resistor(s), which can be taken off I suppose.

    In the pic where you see "1 2 3 ... 11" the "2" corresponds to the other pic from behind where I have added in yellow the first "?". That is, "1" is not soldered then, "2" = ?, "3" = 8, "4" = 7 etc.

    I'd agree with getting a BCD version, however I have these and would like to use them as they're free...

    That is an option, thank you for your advise. I'm almost certain that might be the best. Even if it adds a few more pins/lines from the micro.

    Granted! :D :rolleyes: I'm with you there, but these babies were free and a beggar can't be a chooser, as the saying goes. If I had my way they'd definitely be BCD, much easier.

    Thanks for all advice, keep em coming if there's more...
    Chris
     
  7. crutschow

    Expert

    Mar 14, 2008
    13,052
    3,244
    Can you remove the resistors and just use the switch outputs to give a digital word? Or perhaps you can directly wire to the switch contacts and just ignore the resistors. For example you may be able to connect the contacts to a CD40147 (10-line to 4-line (BCD) priority encoder) which would give a BCD output from the 10 contacts of each switch. You can then use a multiplexer to further minimize the number of lines to the PICs if you want.
     
  8. ScottWang

    Moderator

    Aug 23, 2012
    4,855
    767
    I built some long time ago, it will be able to setup the values of resistors from 1Ω~999999Ω, it's very useful, but there is a resistance in the switches that it less than 1Ω.

    And there are not the counter, there just three thumb wheel switches.

    You can using them as voltage divider, and you need the ADC to read the voltage, or take off all the resistors, and using them as multiplexers, ten pins put together and using 3 common pins to selecting the switch which you want to scan(input).

    [​IMG]
     
  9. Chris11jed

    Thread Starter New Member

    Dec 15, 2013
    16
    0
    Hi all,

    I have thought of this solution. I have a CD40147 about somewhere, I've also got a CD4514BC (4-bit latched/4-to-16 Line Decoder) which will handle up to 16 devices, allowing me to multiplex the lot!;) I have tried to de-solder the resistors and although fidgety it can be done. And as you suggest I can (with resistors removed) common all decimal lines to the 10 lines of the CD40147, then multiplex each unit with the CD4514. Thank you very much for this inspiration. :cool:

    To ScottWang, thank you for the pics and writing your thoughts on what i might do. Also very helpful and well received.

    I think I might see what ebay has and get some BCD units. These decimal units I have (although free) are a bit of work. Although not impossible from some suggestions here, I think I'll take a bit of time to do this properly (suggestion from crutschow seems the way to go as stated above) and in the meantime I will shop for cheap BCD versions, multiplexing them.

    I thank everyone for all your time and effort. I have always found the "All About Circuits" forums very helpful as a quick resource and am impressed by the results of my first post here. A big Thank You to all....

    Happy project building and chip programming to all...
    Chris
    :cool::)
     
Loading...