Shop OBEX P1 Docs P2 Docs Learn Events
DEMO: QuickStart - Push-ON / Push-OFF — Parallax Forums

DEMO: QuickStart - Push-ON / Push-OFF

Beau SchwabeBeau Schwabe Posts: 6,568
edited 2011-07-22 09:46 in Propeller 1
{{

******************************************
* QuickStart Push-On Push-Off Demo  v2.0 *
*                                        *
* Author: Beau Schwabe                   *
* Copyright (c) 2011 Parallax            *
* See end of file for terms of use.      *
******************************************

Revision History:
  Version 1.0   - (06-06-2011) - original file created
  
  
  Version 2.0   - (07-06-2011) - 1-pin Sigma-Delta-ADC implementation for better noise immunity.

                               - Push-On / Push-Off implemented for easier BYTE reads of the
                                'buttons' that are pressed.   

Theory of Operation:
                                                                                                    
This program implements a 1-pin Sigma-Delta-ADC for each of the I/O pins.  Each ADC is capable of
detecting two distinct thresholds.  This creates a hysteresis to the 1.4V threshold of the I/O
providing greater noise immunity to external influences.


   3.3V ──── VDD

   2.2V ──── ADC threshold 2

                         I/O threshold ──── 1.4V

   1.1V ──── ADC threshold 1
 
     0V ──── GND
     
                                                                                                    
The Idea of a 1-pin Sigma-Delta-ADC is to sample the pin as an input, and then very briefly make
the pin an output in the opposite state. i.e. if the input reads a "0", then the output is made a
"1" and vise versa.  The resting state is a condition where the output state of the ADC is a "1" or
"0" every other iteration.  If the input is pulled to GND or VDD, then the output of the ADC would
be two consecutive states that are the same.  In the case with the QuickStart, since the buttons
would be pulled to ground, the two consecutive states would both be 1's ... opposite of the GND
detected by the input.  In another implementation, you could pull to VDD and have two consecutive
0's instead, but the way the QuickStart is designed, the Pull-down is to GND.  
                    
The ADC's function in this example is to keep track of how many times the I/O voltage needed to be
'bumped' in the same direction.  Under normal circumstances, the ADC's returned value would be a "1"
indicating the I/O value is somewhere between threshold 1 and threshold 2.  If you externally pull
the I/O to GND, then the ADC's value would be a "2".  Likewise a "0" if you pulled the I/O to VDD.
The distinction between a "1" and a "2" from the ADC is the key in order to determine a button press
or not.  This while at the same time creates the necessary hysteresis that helps to reject noise.


Please Note:

When programming the QuickStart, make sure that the surface that the QuickStart is sitting on is NOT
conductive.  This includes surfaces you may not think are conductive, such as polyurethane which
can be highly electrostatic.  This can cause programming problems under these conditions.
  

}}
Video Demo 1 - [video]http://www.youtube.com/user/ICPolyman#p/a/u/2/oPELStFtclI[/video]
Video Demo 2 - [video]http://www.youtube.com/user/ICPolyman#p/a/u/1/5fPtIo82M1Y[/video]

OBEX Link - http://obex.parallax.com/objects/762/

Comments

  • LeonLeon Posts: 7,620
    edited 2011-07-06 13:06
    I just tried it, it works very well.

    It should be supplied with that program so that the board does something interesting when it's first plugged in.
  • WhitWhit Posts: 4,191
    edited 2011-07-06 13:06
    Cool Beau!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-07-06 13:56
    Leon and Whit,

    Thanks!

    All feedback is welcome.

    I agree, some sort of program should be pre loaded. We'll see about including something.
  • ercoerco Posts: 20,259
    edited 2011-07-06 15:16
    Very cool, Beau. Could you also preload your antigravity projector and tractor beam programs with the Quickstart board?

    Oops, was I not supposed to mention those?
  • TubularTubular Posts: 4,717
    edited 2011-07-06 18:11
    Interesting. This might have applications as a kind of shield driver at the input threshold level. Saves a pin over the usual sigma delta technique I'm using now to output the switching threshold...

    Beau I have a related question - is it possible to buffer and "output" the switching threshold voltage (~1.4v) from the input fets on the die? I think with prop 2 we might be able to output Vdd/2, and also a DAC level, but these aren't quite the same as they don't 'track'. I'm very thankful at least we have the positive feedback counter mode in the meantime.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-07-06 19:48
    Tubular,

    I understand the benefits of having an I/O threshold reference. If I understand you correctly, the link below is an earlier variation of the 1-pin Sigma Delta ADC that tracks the I/O threshold voltage.


    http://forums.parallax.com/showthread.php?105674-Hook-an-antenna-to-your-Propeller-and-listen-to-the-radio!-%28New-shortwave-prog&p=993273&viewfull=1#post993273
  • RaymanRayman Posts: 14,876
    edited 2011-07-08 05:52
    That looks pretty good. I'm a little suspicious that the actual dischage path to ground is not across the touchpad, but through your body...
    Have you tried it while not touching ground with your left hand?
  • LeonLeon Posts: 7,620
    edited 2011-07-08 06:08
    The finger tip bridges the contacts, connecting the central pad to ground via the skin.
  • RaymanRayman Posts: 14,876
    edited 2011-07-08 07:13
    I think there are 3 possible paths... One is along the surface of your skin between pads. Another is from one pad across your skin, through yor finger tip, and then through the skin again into the other pad. Another is in one pad across your skin, through your body, and then through your skin somewhere else to ground.

    Your internal body resistance is usually quite small compared to your skin resistance...
  • LeonLeon Posts: 7,620
    edited 2011-07-08 07:24
    Your first two seem to be the same. The resistance to ground through the body will be very high, I'd have thought.
  • RaymanRayman Posts: 14,876
    edited 2011-07-08 07:27
    First one, current doesn't go through your skin, just along the surface... Your body is mostly salt water and a pretty good conductor compared to your skin, which is a good insulator (unless soaked in salt water).
  • LeonLeon Posts: 7,620
    edited 2011-07-08 07:30
    But how is the body connected to ground?
  • RaymanRayman Posts: 14,876
    edited 2011-07-08 07:41
    If you're holding the USB connector with your left hand...
  • LeonLeon Posts: 7,620
    edited 2011-07-08 07:45
    Of course! :) I was thinking of conduction via the feet. Mine works OK without me having a ground connection.
  • RaymanRayman Posts: 14,876
    edited 2011-07-08 14:13
    Well, I just tried it on my Quickstart board and although it works better than the original, it's not 100% for me.. Some of the buttons seem to do the right thing, while a couple of them just light up when I touch them and then go out when I let go, instead of toggling...

    Touching my left hand to ground doesn't seem to have any affect...

    I just did a little experiment though that has me questioning how this is all working... I held a metal screwdriver with my fingers and just touched the center pad and that way all the buttons behave the right way.

    Then, I took Scotch tape to cover up the ground pads on one the switches that wasn't working right, and then it works right.

    I did this while not touching ground anywhere... This is a little puzzling to me.

    Only thing I can think of is thay my body is acting like an antenna and this code picks up on stray RF signals due to it's high input impedance.

    Anyway, tape off the ground pads if your switches aren't working!
  • LeonLeon Posts: 7,620
    edited 2011-07-08 14:43
    My skin is very dry because of some surgery I had many years ago, that might make a difference.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-07-08 20:35
    "Well, I just tried it on my Quickstart board and although it works better than the original, it's not 100% for me.. Some of the buttons seem to do the right thing, while a couple of them just light up when I touch them and then go out when I let go, instead of toggling" ... David Carrier also noticed something similar to thisthis. What happens if you moisten your fingers before hand?... I know something you don't want to do, but I would be curious all the same.

    "I just did a little experiment though that has me questioning how this is all working... I held a metal screwdriver with my fingers and just touched the center pad and that way all the buttons behave the right way." - At very close range you can have capacitive coupling that might cause it to respond this way.



    Another couple of thoughts ...

    - What kind of lighting do you have? ...noisy fluorescents? ...try moving to another location if that's the case.

    - On average, what is the relative humidity?

    - Also... what is the surface that the QuickStart is sitting on? I had problems on a polyurethaned table.
  • AribaAriba Posts: 2,690
    edited 2011-07-08 21:08
    I also see that the buttons don't toggle the LED if you touch a bit longer. I tought this is intentional.

    Here is a very simple code which makes the same and works quite reliable for me:
    _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
    Pub Main | b,old
      dira[16..23]~~                'LED pins = ouputs
      dira[0..7]~                   'Button pins = inputs
      outa[0..7]~~                  'prepare button pins with High
      b~                            'init button states
      repeat 
        dira[0..7]~~                'switch button pins to High
        dira[0..7]~                 'and back to inputs
        waitcnt(160_000+cnt)        'wait 2ms
        b := ina[0..7] ^ $FF        'read button inputs
        if b <> old                 'if button state changed
          outa[16..23] ^= b         'toggle LED
          old := b                  'remember current state
        waitcnt(160_000+cnt)        'wait 2ms
    

    Andy
  • RaymanRayman Posts: 14,876
    edited 2011-07-09 05:42
    Andy, I tried it and it has similar issues as Beau's... Maybe works a little less well, but your's is definitely simpler...

    Beau, Ok I did some testing of the idea of just touching the center part of the button with your code. It works everywhere in my house absolutely perfectly. But, way out in my backyard it doesn't work hardly at all. So, I think it's picking up on the 60 Hz radiation field in the house.

    So, I'm tempted to cut the ground connections on all the pads... Actually, I just decided that's what I'm going to try.
  • RaymanRayman Posts: 14,876
    edited 2011-07-09 08:57
    Ok, check it out. I used a knife to cut the ground connection to side tabs. Then I put some liquid bandage over the cuts.

    Now, it works perfectly.

    Well, as long as I don't touch ground with my left hand anyway. If I do touch ground with my left hand, then it still works, but in a different way, the LED changes state only when pushed and then goes back when release. This has me a little puzzled at the moment...
  • LeonLeon Posts: 7,620
    edited 2011-07-09 09:32
    Perhaps users need dry skin like mine for it to work properly. I had most of my colon removed to get it, but that might be a bit drastic. :)
  • RaymanRayman Posts: 14,876
    edited 2011-07-09 10:01
    Wish I had another unmodified board to make sure what's different now, but my fix seems to be working well.

    The original demo code now works good as long as I hold ground (usb connector) with my left hand.

    This version of Ariba's code works well with left hand touching ground or not:
    con
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
    Pub Main | b,old
      dira[16..23]~~                'LED pins = ouputs
      dira[0..7]~                   'Button pins = inputs
      outa[0..7]~~                  'prepare button pins with High
      b~                            'init button states
      repeat 
        dira[0..7]~~                'switch button pins to High
        dira[0..7]~                 'and back to inputs
        waitcnt(160_000+cnt)        'wait 2ms
        b := ina[0..7] ^ $FF        'read button inputs
        outa[16..23] := b           'set leds
        waitcnt(cnt+clkfreq/100)    'wait a minute
    
  • AribaAriba Posts: 2,690
    edited 2011-07-09 11:22
    Another test, this one works really well here.
    First I check every button separatly because I've seen some crosstalk between adjacent buttons sometimes.
    Then I check every button 2 times with a delay of 8..9ms so I hope to eliminate the 50/60 Hz stray signal.
    _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
    Pub Main | b,ms
      ms := clkfreq/1000
      dira[16..23]~~                  'LED pins = ouputs
      dira[0..7]~                     'Button pins = inputs
      outa[0..7]~~                    'prepare button pins with High
      inb[0..7]~~                     'old states of buttons
      repeat
        repeat b from 0 to 7
          dira[b] := 1                'switch button pin High
          dira[b] := 0                'and back to input
          waitcnt(1*ms + cnt)         'wait 1ms
          if ina[b]==0                'touched?
            waitcnt(8*ms + cnt)       'wait 8ms
            dira[b] := 1              'read again on other 50/60Hz halfwave
            dira[b] := 0
            waitcnt(1*ms + cnt)
            if ina[b]==0              'still touched?
              if ina[b] <> inb[b]     'if state changed
                outa[16+b] ^= 1       'toggle LED
          inb[b] := ina[b]            'remember current state
    
    Andy
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-07-22 09:46
    Andy,

    "...I check every button 2 times with a delay of 8..9ms so I hope to eliminate the 50/60 Hz stray signal...." - I like your way of thinking here. I wonder if looking at the buttons in 'quadrature' using a delay of ~4ms would be useful in an inverted logic way of looking at the problem.
Sign In or Register to comment.