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

Multiple pushbuttons on one pin using adaptive ADC

13

Comments

  • Cluso99Cluso99 Posts: 17,474

    @"Phil Pilgrim (PhiPi)" said:
    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

    Used this method for reading 8 DIL switches on spare pins on a micro back in the 80's :)

  • RaymanRayman Posts: 11,842

    I was just wondering one could use two diodes to split the problem in two, lower part count and make space between levels bigger...
    But, you'd have to switch back and forth between sourcing and sinking...

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 22,931
    edited 2021-02-10 02:05

    If you must do it in analog over a cable, at least make it current-driven instead of voltage-driven:

    -Phil

  • TubularTubular Posts: 4,292

    But whats the advantage of the external reg vs an internal current source? I think Chip got scared by the current source operation up near the positive rail, but given enough headroom the P2's current sources should be fine for something like this.

    I'm planning to use either the 10 or 100uA current source to resolve a slow A/B encoder using similar technique

  • But whats the advantage of the external reg vs an internal current source?

    As you said, headroom. An external source can be driven from a higher voltage. Plus, IIRC, I think Chip was concerned about temperature dependencies in the P2's internal current sources. Anyway, the LM317L is cheap as dirt.

    -Phil

  • cgraceycgracey Posts: 13,406

    @"Phil Pilgrim (PhiPi)" said:

    But whats the advantage of the external reg vs an internal current source?

    As you said, headroom. An external source can be driven from a higher voltage. Plus, IIRC, I think Chip was concerned about temperature dependencies in the P2's internal current sources. Anyway, the LM317L is cheap as dirt.

    -Phil

    Phil, what is the weak point of that 5-button scheme that I last posted?

  • @cgracey said:
    Phil, what is the weak point of that 5-button scheme that I last posted?

    None, if the buttons are immediately proximal to the Prop. It's the cable that bothers me. Of course, I don't know how long or short it can be. Maybe it's short enough and in an environment bereft enough of noise that it won't be a problem. But, as a general principle, I believe a current interface is more reliable than a voltage interface when distances are a factor. The circuit I illustrated could probably sustain accuracy over a twisted-pair cable hundreds of meters long, assuming a high-enough voltage driving it.

    -Phil

  • cgraceycgracey Posts: 13,406
    edited 2021-02-10 05:22

    @"Phil Pilgrim (PhiPi)" said:

    @cgracey said:
    Phil, what is the weak point of that 5-button scheme that I last posted?

    None, if the buttons are immediately proximal to the Prop. It's the cable that bothers me. Of course, I don't know how long or short it can be. Maybe it's short enough and in an environment bereft enough of noise that it won't be a problem. But, as a general principle, I believe a current interface is more reliable than a voltage interface when distances are a factor. The circuit I illustrated could probably sustain accuracy over a twisted-pair cable hundreds of meters long, assuming a high-enough voltage driving it.

    -Phil

    I see. Our cable length will be 1-2 meters. The cable impedance will be a thousandth of the resistor impedance. I think noise is the biggest threat. Twisted pair should inhibit noise, though. We will see pretty soon.

    Phil, maybe you could use a P2 setup.

  • I used this resistor chain teamed up with an adc back in the early 90s for vending machines but in another design I also used diodes instead. At low current I got 600mV drop for each diode. The switches shorted a series node to ground.

  • LtechLtech Posts: 269

    Why not use symmetrical mode?

    Thinking on professional audio balancing.
    Noice on one wire are opposite to the decoding on the other wire.
    A microphone give mVolt, and archive -60dB noice level with shielded cable.
    No need to be 600 Ohm.
    This is one pin extra on P2

  • TonyB_TonyB_ Posts: 1,625

    How many cycles will it take to read four or five buttons on one pin?

  • I wonder if all you guys have too much time or are bored due to the COVID lockdown... :D

    Yes, this trick is nice to show what can be done with the smart pins of the P2. It might be used in a real product if somebody runs out of pins and has to read a lot of switches, up to 8 DIP switches for example (if you need more, a matrix would be better). In this case the switches are close to the CPU and we don't have to worry about the resistance of long wires or EMI problems.

    If I had to read a lot of pushbuttons (keyboard) over long wires I'd use a separate controller and transfer the data over a serial port.

    I wrote "might" and "if" because the probability is rather low now that we have 64 IOs.

  • cgraceycgracey Posts: 13,406
    edited 2021-02-10 15:07

    @TonyB_ said:
    How many cycles will it take to read four or five buttons on one pin?

    Six cycles at 5,000 clocks each, with 1mV precision, using short interrupt routines.

    30MHz divided by (6 x 5,000) = 1KHz updated rate. Maybe divide that by 8 for 8-unanimous debounce filtering and you get 125Hz transitions. That's at only 30MHz clock rate.

  • cgraceycgracey Posts: 13,406

    @Ltech said:
    Why not use symmetrical mode?

    Thinking on professional audio balancing.
    Noice on one wire are opposite to the decoding on the other wire.
    A microphone give mVolt, and archive -60dB noice level with shielded cable.
    No need to be 600 Ohm.
    This is one pin extra on P2

    Could you draw what that would look like? I can't quite picture it, but I imagine it's pretty simple.

  • RaymanRayman Posts: 11,842
    edited 2021-02-10 17:52

    Check this out:
    https://sites.google.com/site/wayneholder/wayneplexing-buttons

    Like charliplexing for buttons...

    Oh wait, never mind... only works on one button at a time...

    Still, reply #5 here shows 64 switches from 16 inputs:
    https://www.eevblog.com/forum/beginners/charlieplexing-switches/
    Just need a diode for every switch... This one says can be multiple switches pressed...

  • Not that I think this will be implemented, but I just wanted to finish what I started with the current source idea. I wanted to output current in the industrial standard range of 4-20mA. These two circuits do just that, using standard precision resistor values:

    Plotting the voltage on the 150R current sense resistor yields the following graph:

    Clearly, the parallel topology is the better choice.

    -Phil

  • cgraceycgracey Posts: 13,406

    Thanks, Phil. That looks pretty good. Current is better than voltage. I was using current from a pin (1mA), but I was not getting linearity. Probably need to try again. BTW, do you check your messages?

  • Hey Chip, msg received and responded.

    Thx,
    -Phil

  • Cluso99Cluso99 Posts: 17,474

    @"Phil Pilgrim (PhiPi)" said:
    Not that I think this will be implemented, but I just wanted to finish what I started with the current source idea. I wanted to output current in the industrial standard range of 4-20mA. These two circuits do just that, using standard precision resistor values:

    Plotting the voltage on the 150R current sense resistor yields the following graph:

    Clearly, the parallel topology is the better choice.

    -Phil

    This parallel one looks nice and linear Phil :)

  • Cluso99Cluso99 Posts: 17,474

    Alternately a 10c PADUK micro would do fine too, but of course you have to program it :(
    A regulator is only a few cents.

  • msrobotsmsrobots Posts: 3,324

    I think the idea is to do it with a P2 not a second micro.

    Mike

  • Cluso99Cluso99 Posts: 17,474

    @msrobots said:
    I think the idea is to do it with a P2 not a second micro.

    Mike

    True.
    But you also have to be careful that it works everywhere, as otherwise you get bad press (which is often worse than no press) because you skimped on the design.
    Phil is cautious about the wire length, as am I. Originally I thought it was on the same pcb.

  • cgraceycgracey Posts: 13,406

    Looks like we can do GIFs in posts now. We need to get monospaced code working, too.

  • @cgracey said:
    Looks like we can do GIFs in posts now. We need to get monospaced code working, too.

    '' Already works, just missing the Spin highlighter still
    PUB abcd()
    ifnot xyz
      wrpin(asdf,ghjk)
    
  • cgraceycgracey Posts: 13,406

    @Wuerfel_21 said:

    @cgracey said:
    Looks like we can do GIFs in posts now. We need to get monospaced code working, too.

    '' Already works, just missing the Spin highlighter still
    PUB abcd()
    ifnot xyz
      wrpin(asdf,ghjk)
    

    Oh, that's good. I thought it was still weird.

    Hey, have you used the new flexible baud feature yet in PNut_v35h?

  • cgraceycgracey Posts: 13,406
    edited 2021-02-16 22:40

    Here is the program that made the 5-button animation.

    Ah, you must comment out the QUIT at the end of the REPEAT loop to get the animation to run. If it QUITs, it exits to the code that starts reading the buttons, which is also useful.

  • jmgjmg Posts: 14,595

    @cgracey said:
    I see. Our cable length will be 1-2 meters. The cable impedance will be a thousandth of the resistor impedance. I think noise is the biggest threat. Twisted pair should inhibit noise, though. We will see pretty soon.

    A challenge here could be initial calibrate of this, especially for volume production ?
    With just 27mV step at the mid-region, setting of a 'no-button' point may need to be continual. (That has the risk a pressed/stuck button will skew things.)
    One time calibrate, would need to presume the time and temperature ADC drifts were << 27mV. That may be an ask on a P2 ADC ?
    What does the P2 data sheet give as worst case drifts ?

  • jmgjmg Posts: 14,595
    edited 2021-02-18 02:12

    @cgracey said:
    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.

    There is also the calibrate of current source to consider.
    A quick Spice workup shows current source does have a significant gain, over a series R, as the steps are then nominally identical, and you can use a wider span of the ADC.
    ( If current is set ~ 80% span, and source feed R is set for max dV, the current source gives a dV improvement of ~ 3.1282x, more that I would have guessed )

    If you ran a continual open-button auto-calibrate loop, the current source tolerance and drift would then not matter, and you could tolerate cheaper/more easily sourced resistors. (or, add another button)
    100uA may be worth testing, as that is still well above ADC input current and should allow more of the 3v3 span to be used, an ESD series R too.
    The combined effects of current source 'bend', and ADC input current will pull the steps away from the theoretical identical sizes, but those effects should be P2 consistent.

  • Honda does this on their new Gold Wing to reduce the number of I/O pins needed for all the buttons.

  • Beau SchwabeBeau Schwabe Posts: 6,445
    edited 2021-02-17 07:10

    Chip,

    Here is some more "alien tech" for you ... I had to step once again into the Wayback machine to my web site where I had posted this for the Basic Stamp .... This thing doesn't even have a micro, just uses a decade counter/divider IC. Whatever frequency you give it translates to the baud in standard 8N1 format

Sign In or Register to comment.