Shop Learn
Multiple pushbuttons on one pin using adaptive ADC - Page 2 — Parallax Forums

Multiple pushbuttons on one pin using adaptive ADC

24

Comments

  • cgraceycgracey Posts: 13,378
    edited 2021-02-06 06:46

    @Ariba said:
    The idle count is around 4000. For sure you can make it higher with 100uA feedback instead of 1mA.

    Off the top of your head, is there a certain type of capacitor that is known for having tight accuracy? Most caps seem to just aim for a minimum capacitance, so their tolerances are in the double digits.

    I remember COG0 caps are tight, but I am not sure of their cost.

  • Cluso99Cluso99 Posts: 17,434

    I think Beau's circuit is a single inverter oscillator so the frequency would vary depending on the feedback resistance/capacitance. The second inverter is necessary to provide some distance from the switches. If it was right at the pin it could probably be removed and just use a 1G version. A 6-pin SOT363/SC88 (0.65mm pitch) or SOT26 (0.95mm pitch) 74LVC2G14 or similar would be fine.

  • @"cgracey" said:
    So, you would measure the high pulse and the low pulse to get the key being pressed.

    Yes, to read row (high pulse) and column (low pulse). The 120k is there so that the oscillator doesn't stall, and you can also use this as a reference point to track any temperature variations.

  • cgraceycgracey Posts: 13,378
    edited 2021-02-06 13:06

    I've got a new scheme worked out where the buttons are tied together in series and each button has a resistor across it, which it shorts out when pressed. One end of the circuit is grounded and the other end goes to the P2 pin.

    Now, I drive the ADC pin high in 1mA mode, sourcing current into the resistor stack. The button sequence pattern creates a completely linear ramp. We should be able to do six buttons this way, with a 40mV spread between combinations. It is necessary, though, on power-up, to have all buttons untouched, so that an initial calibration can be made. This is going to take a little more thinking, but it looks really promising.

  • Cluso99Cluso99 Posts: 17,434

    @cgracey said:
    I've got a new scheme worked out where the buttons are tied together in series and each button has a resistor across it, which it shorts out when pressed. One end of the circuit is grounded and the other end goes to the P2 pin.

    Now, I drive the ADC pin high in 1mA mode, sourcing current into the resistor stack. The button sequence pattern creates a completely linear ramp. We should be able to do six buttons this way, with a 40mV spread between combinations. It is necessary, though, on power-up, to have all buttons untouched, so that an initial calibration can be made. This is going to take a little more thinking, but it looks really promising.

    Nice :)

  • Funny... :D

    I'd like to note that 1k, 2.2k 4.7k and so on is a bad choice for 1R 2R...
    I've found some E24 resistor values that match better: 750R, 1k5, 3k0
    6k0 can be made with two 3k0 in series or two 12k in parallel

  • cgraceycgracey Posts: 13,378
    edited 2021-02-06 21:38

    @ManAtWork said:
    Funny... :D

    I'd like to note that 1k, 2.2k 4.7k and so on is a bad choice for 1R 2R...
    I've found some E24 resistor values that match better: 750R, 1k5, 3k0
    6k0 can be made with two 3k0 in series or two 12k in parallel

    Excellent. I have been trying to figure out what sequence would be most available using discrete resistors.

    Maybe we just need to order two resistor values, 1k5 and 12k:

    R1 = two 1k5 in parallel = 750
    R2 = single 1k5 = 1,500
    R3 = two 1k5 in series = 3,000
    R4 = two 12k in parallel = 6,000
    R5 = single 12k = 12,000
    R6 = two 12k in series = 24,000

    We need to go lower, actually, because we want the 1mA source to pull the open resistor chain to maybe 3v. That would mean a series resistance of 3k. If R6 were 1k5, then the total resistance would be a little less than 3k, for 3V in the all-open state. 3V / 64 = 46mV per step, which is great.

    I need to do some temperature tests to make sure that 1 milliamp that the pin delivers is sufficiently stable.

  • Cluso99Cluso99 Posts: 17,434

    @cgracey said:

    @ManAtWork said:
    Funny... :D

    I'd like to note that 1k, 2.2k 4.7k and so on is a bad choice for 1R 2R...
    I've found some E24 resistor values that match better: 750R, 1k5, 3k0
    6k0 can be made with two 3k0 in series or two 12k in parallel

    Excellent. I have been trying to figure out what sequence would be most available using discrete resistors.

    Maybe we just need to order two resistor values, 1k5 and 12k:

    R1 = two 1k5 in parallel = 750
    R2 = single 1k5 = 1,500
    R3 = two 1k5 in series = 3,000
    R4 = two 12k in parallel = 6,000
    R5 = single 12k = 12,000
    R6 = two 12k in series = 24,000

    We need to go lower, actually, because we want the 1mA source to pull the open resistor chain to maybe 3v. That would mean a series resistance of 3k. If R6 were 1k5, then the total resistance would be a little less than 3k, for 3V in the all-open state. 3V / 64 = 46mV per step, which is great.

    I need to do some temperature tests to make sure that 1 milliamp that the pin delivers is sufficiently stable.

    Chip,
    If you're using smt, then a 4 pack of 1K5 gives 750 and 3K easily (routing wise), and then add an 0603 or 0402 to do the single 1K5. Do the same for the 12K.

  • TwyyxTwyyx Posts: 49
    edited 2021-02-07 01:14

    I've been staring at this circuit for about 30 minutes now. It is full of A-HA! moments for an intermediate builder. Thanks @"Beau Schwabe" !
    What happened to the old site? Seems such a pity for it to only be on wayback.

  • @Twyyx said:
    What happened to the old site? Seems such a pity for it to only be on wayback.

    Thanks ! ... For one, I maintained that site more than 25 years ago. That was many lifetimes ago considering everything I have been doing since then.

    I came up with that circuit before the Basic Stamp II was even available.

  • cgraceycgracey Posts: 13,378
    edited 2021-02-07 12:16

    Using the P2 pin to source 1mA didn't work very well, because the amount of current it sources is somewhat a function of voltage. I was measuring ~850uA at a 0.8V drop from 3.3V, but sourcing all the way to GND drew just over 1mA. This is too non-linear to measure the buttons.

    So, I'm back to the original idea of measuring voltage that is a function of resistance, except I'm tying all the pushbuttons in series and putting precision resistors across each of them which are shorted when pressed. One end of the chain is at GND and the other is pulled up to VIO with a precision resistor. The ADC just measures the voltage and checks against a list of thresholds to determine the button pattern. This seems to work fine for 5 buttons, but I think 6 is too risky.

    I ordered some 0.1% through-hole resistors to wire up the buttons with for final testing. This will keep the button circuit simple to assemble. You just run wires between the arcade pushbuttons and solder a resistor across each one, though some need two resistors in series or parallel, since not every resistor value is available. The resistors are expensive at $0.50 each, quantity 10.

    Pull-up resistor = 2.2k
    PB1 resistor = 1.2k
    PB2 resistor = 600 (two 1.2k in parallel)
    PB3 resistor = 300 (two 150 in series)
    PB4 resistor = 150
    PB5 resistor = 75

  • TubularTubular Posts: 4,290
    edited 2021-02-07 12:30

    Hey Chip what about making use of the 10x zoom around midpoint (~1400 to 1900mV), and placing a precision 1k5 between the 75 ohm and ground, to bias the buttons up above 1.5v into your 10x range?

    That should get you working with 1mA source.

  • cgraceycgracey Posts: 13,378

    @Tubular said:
    Hey Chip what about making use of the 10x zoom around midpoint (~1400 to 1900mV), and placing a precision 1k5 between the 75 ohm and ground, to bias the buttons up above 1.5v into your 10x range?

    That should get you working with 1mA source.

    The problem is that I can't calibrate it to know the offset and scale. With full-range mode, I can use the VIO and GIO calibration settings to measure where power and ground are. In magnification mode, it's all relative.

  • TubularTubular Posts: 4,290
    edited 2021-02-07 12:52

    i wonder whether you could use a high and low DAC level output near midrange, combined with ADC reading of the same pin. Sort of like a GIO and VIO calibration, only for zoomed in ranges

    You'd first measure those dac levels in calibrated 1x mode, then zoom in and measure the same but in 10x range. You'd be changing input impedance with the change in range, so there would be some effect on the originating signal, but perhaps this would be good enough ?

  • @cgracey said:

    I ordered some 0.1% through-hole resistors to wire up the buttons with for final testing. This will keep the button circuit simple to assemble. You just run wires between the arcade pushbuttons and solder a resistor across each one, though some need two resistors in series or parallel, since not every resistor value is available. The resistors are expensive at $0.50 each, quantity 10.

    Is the delta between steps so narrow now that 0.1% resistors are important ?

  • cgraceycgracey Posts: 13,378
    edited 2021-02-07 13:12

    @VonSzarvas said:

    @cgracey said:

    I ordered some 0.1% through-hole resistors to wire up the buttons with for final testing. This will keep the button circuit simple to assemble. You just run wires between the arcade pushbuttons and solder a resistor across each one, though some need two resistors in series or parallel, since not every resistor value is available. The resistors are expensive at $0.50 each, quantity 10.

    Is the delta between steps so narrow now that 0.1% resistors are important ?

    No, but 1% in the wrong directions could cause problems, so the next step is 0.1%.

    We will need one 0.1% 2.2k pull-up resistor on the P2 Edge board side, plus 10uF coupling caps for video and audio. The precision resistor can be had in 0402.

  • cgraceycgracey Posts: 13,378
    edited 2021-02-07 13:14

    @Tubular said:
    i wonder whether you could use a high and low DAC level output near midrange, combined with ADC reading of the same pin. Sort of like a GIO and VIO calibration, only for zoomed in ranges

    You'd first measure those dac levels in calibrated 1x mode, then zoom in and measure the same but in 10x range. You'd be changing input impedance with the change in range, so there would be some effect on the originating signal, but perhaps this would be good enough ?

    The trouble is going to be that the 10x mode is not going to be exactly-enough 10x to rely on full-scale calibration.

    The ADCs really shine in AC situations, not DC.

  • Cluso99Cluso99 Posts: 17,434
    edited 2021-02-07 15:24

    Chip,
    If you look back at my post #7 and #11 the second line of the spreadsheet produced better results when using the fixed resistor at 15K, with the others from bottom up as 1K, 2K, 4K, 8K.
    Of course you can scale these to suit. I tried various fixed resistors in the spreadsheet but the 15K which is equal to the total of the others produced a best minimum delta of 0.057V, even though the total spread was smaller.
    The spreadsheet was not self explanatory. The line in bold immediately under the labels is the value for fixed (the top pull-up), and then the switches SW1-4. When a switch is active it’s value becomes 0R shown simply as 0. If the switch is inactive then it’s value is shown in the cell (copied from the top value line. The I just sum all 5 values, and the 4 switch totals and do a 3V3 times the ratio giving a volts out. The last column is the difference between successive values so you can see the smallest.
    Have you tried a spreadsheet with the caps as suggested by ???
    Also did you consider a gate oscillator, or pair where one modulates the other to give a variable mark space ratio. This might be easy to time the high and low sections of the frequency with the smart pins. 74LVC1G14 and 74LVC2G14 are cheap and tiny SOTs. Perhaps the frequency might be easier to determine???
    I could knock up a circuit using 74LVC gates (not Schmitt triggers tho) if you could do the code. Would have to wait until after tomorrow tho.

  • Cluso99Cluso99 Posts: 17,434

    BTW you’re probably not going to see much difference between 1% and 0.1% these days.

  • Cluso99Cluso99 Posts: 17,434

    Here is the spreadsheet. Note the fixed value doesn't change the minimum difference much from 1800-2700.

  • cgraceycgracey Posts: 13,378

    Ray, the 2200 ohm pull-up resistor does roughly match the sum of the series resistors. It's off by 125 ohms, but that won't matter. As long as we know the value, we will nail it with the math. I just went with resistor values that are commonly available.

  • Cluso99Cluso99 Posts: 17,434

    @cgracey said:
    Ray, the 2200 ohm pull-up resistor does roughly match the sum of the series resistors. It's off by 125 ohms, but that won't matter. As long as we know the value, we will nail it with the math. I just went with resistor values that are commonly available.

    Yes, that's what the spreadsheet showed. If you take the smallest deviation, that translates to about 120 levels, so 7 bits. The ADC should do just fine.

    BTW If you wanted to use RN4 resistor networks you could use 150R (for 75R & 300R) - parallel and series pairs), 300R (for 150R & 600R), and 1200R (for 1200R & 2400R).

  • Cluso99Cluso99 Posts: 17,434

    Chip,
    Did you try out the cap idea of @Ariba ?

    Also @Rayman post #14 looked nice and linear. Could be built with 3xRN4 and 1 0402/0603.

    BTW the title needs changing to Four/Five...

  • cgraceycgracey Posts: 13,378
    edited 2021-02-08 15:08

    @Cluso99 said:
    Chip,
    Did you try out the cap idea of @Ariba ?

    Also @Rayman post #14 looked nice and linear. Could be built with 3xRN4 and 1 0402/0603.

    BTW the title needs changing to Four/Five...

    I tried out Andy's cap idea, but my results were not so linear as his.

    We are going to be operating these buttons over a 1-meter cable now, so the parasitic capacitance has increased and I'll need to go with a DC technique. The series'd buttons with resistors across each is most favorable now, since it's also easiest to wire up.

    The R-2R idea gets tricky at the MSB switchover point, where the voltage step can become small. Also, it doesn't lend itself to easy wiring of separated buttons.

  • As the design concept settles and we narrow down the resistor values, we will have a small kit of parts that lets you build a few sets of these in the #64025 P2 Button ADC Kit. Chip seems to have nailed down the 1% resistors to two sizes and we'll add in some pushbuttons.

    Coming soon to the shop!

    Ken Gracey

  • Late to the party, I know, but I've been ardently following this thread. IMO, you're asking for trouble applying a purely analog solution to a digital problem, especially over a long cable. So I would like to propose an alternate solution. Why not use a cheap 8-bit micro to generate four mutually orthogonal signals that can be switched into a summing junction as shown below:

    The summing junction feeds into one of the P2's ADCs. But it's all AC, so it doesn't rely on any kind of calibration to be successful. The P2's amazing signal processing capabilities can then be used to sort out the signals to determine which switches are ON..

    -Phil

  • Or even better and more reliable still, let the 8-bit micro figure out which buttons were pressed and send a serial signal to the Propeller:

    Four fewer components, since the micro has internal pull-ups!

    -Phil

  • cgraceycgracey Posts: 13,378

    Here are the code and schematic for the 5-buttons-on-1-pin app shown in the Zoom meeting today.

  • TubularTubular Posts: 4,290

    its good that you are returning via twisted pair, might just work : )

  • cgraceycgracey Posts: 13,378
    edited 2021-02-09 23:22

    @"Phil Pilgrim (PhiPi)" said:
    Late to the party, I know, but I've been ardently following this thread. IMO, you're asking for trouble applying a purely analog solution to a digital problem, especially over a long cable....

    The cable impedance is maybe 1/1000th of the intentional resistor resistance. And we use a separate GND wire just for the buttons, so that the Vdrop from the 12V power consumption doesn't cause any offset or noise. This is, in effect, a current loop.

    The wiring for the buttons is very easy to realize, since they are all wired in series with resistors across their terminals. Two wires over the RJ-45 is all it takes, one P2 pin and a GND connection. The 2200-ohm pull-up resistor is on the P2 side. No need for a local 3.3V power supply on the other end of the cable to support a micro. And no extra tools/knowledge needed.

Sign In or Register to comment.