Capacitive Touch Button by using ADC channel (the CVD system)


+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 43
  1. #1
    Join Date
    Aug 2004
    Posts
    34

    Default Capacitive Touch Button by using ADC channel (the CVD system)

    I would like to use one touch button (or pad) with pic and I read the pdf file of Microchip AN1298 about that matter.
    The document gives the following instructions to do the job;
    * 1. Set 2nd channel to output, set high (VDD)
    * 2. Select 2nd channel on ADC (charges CHOLD to VDD).
    * 3. Set sensor line to output, set low (GND)
    * 4. Select sensor line as input (TRISx = 1)
    * 5. Select sensor channel on ADC (V-div sensor:CHOLD)
    * 6. Begin ADC conversion
    * 7. Reading is in ADRESH:ADRESL
    I decided to write a program for 12F676 considering these explanations.
    Here is the program . Could you pls someone check the program and let me know if there are some mistakes or missed points. Because the program does not work as I want.

    Code:
    @ DEVICE pic12F675                                                     
    @ DEVICE pic12F675, WDT_ON             
    @ DEVICE pic12F675, PWRT_ON             
    @ DEVICE pic12F675, PROTECT_OFF         
    @ DEVICE pic12F675, MCLR_off            
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT  
    
    DEFINE OSCCAL_1K 1  
    
    DEFINE OSC 4
    
    DEFINE ADC_BITS 8    
    'DEFINE ADC_CLOCK 1    
    DEFINE ADC_SAMPLEUS 10 
    CMCON = 7
    RAW VAR byte 56
    OPTION_REG=%01001111
    GPIO=0
    TRISIO=0
    ANSEL = %01011111
    ADCON0=%00001001
    WPU=0
    START:     
           ANSEL.2=1         'GPIO.2 Analog selected  This is secondary channel 
           GPIO.2=1          'GPIO.2=HIGH this is for charging the C_hold capacitor 
           OUTPUT GPIO.2     'GPIP.2 is output now
           ADCON0=%00001001  'AN2 (GPIO.2) selected for ADC purpose
           PAUSEus 10   
           
           TRISIO.4=0        'AN3=is output , this is sensor pin
           GPIO.4=0          'AN3 is LOW yapıldı This for discharging the sensor capacitor 
           TRISIO.4=1        'AN3= is input now 
           ANSEL.3=1         'AN3 is analog input now
           ADCON0=%00001101  'ADC =AN3 redierected to AN3 and  C_hold voltage is divided (CVD )
           pauseus 10        'wait 10 us 
           ADCIN 3,RAW
           ANSEL.2=0         'GPIO.2 is Digital for re-use it on next cycle 
          
           OUTPUT GPIO.4          'Sensor pin is Output now 
           
           GPIO.5=1               'GPIO.5=HIGH , sensor pin is HIGH 
           PAUSE RAW              'wait as HAM value (ms)
           GPIO.5=0               'GPIO.5=LOW Output is LOW now. 
           pause 10
           GOTO START

  2. #2
    Join Date
    Jul 2011
    Location
    Hawaii
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Ero

    GPIO.2 must remain an input all the time. Tie this input to Vcc. Tell the ADC to select GPIO.2 input pin as an analog input to charge the C_hold cap.

    - Martin

  3. #3
    Join Date
    Aug 2004
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Thank you for the reply. I will do them.

    Ero

  4. #4
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    ero, Martin, or anybody

    I've been trying to do this with a PIC16F819, with only mediocre results. My 819 has a 10 bit A2D, while I see that you are trying it with a 8 bit A2D, so theoretically, your results should be even worse than mine, if that's possible. so, I'm interested in what your typical RAW value is, what it drops to with a finger press, and if it stays relatively constant while your finger is near, because mine does not.

    I started out not tying any of the A2D inputs directly to VCC, and my program began with the A2D pins TRIS being outputs. It worked, sort of, but the A2D value was not constant while my finger was near the pad. Then, I read Martin's suggestion, tied my 'dummy' A2D channel to VCC, modified the code, and ... same thing.

    I've got my PIC16F819 on a olimex 18 pin dev board. I have two copper tape pads, about 1 inch square, covered with electrical tape, on pins 2 and 18.

    my debug statement spits out usually 30 for my untouched S2_AVE (which is not really an average) and when i put my finger on the sensor, it jumps (rings) between 1 and 37. :-(

    I tried putting 10uS delays all over my sense subroutine, tried a longer or no pause before running the A2D, and I tried messing with the A2D clock source, which now doesn't match the define statement.

    oh yeah, I tried to manually control the A2D, but that didn't work. I think I'm pointing to the wrong bits

    If anybody is still with me, here is my down-n-dirty, non-averaging, non-optimized, soon to be pitched, code.
    I'd love to hear any suggestions.

    Code:
    							'    PIC BASIC PRO 2.6 & MPLAB v8.40 PIC16F819 
    '    ================
    
    
    @ __CONFIG  _HS_OSC & _MCLR_OFF  &  _LVP_OFF & _WDT_OFF & _PWRTE_OFF  & _BODEN_OFF
    
    DEFINE DEBUG_REG PORTB        ' asyncronous RS-232 output on PORTB...
    DEFINE DEBUG_BIT 7        ' bit 7
    DEFINE DEBUG_BAUD 19200        ' 19200 Baud, 
    DEFINE DEBUG_MODE 0        ' 1 = inverted,  0 = true,like for using max232, or pickit2
    DEFINE DEBUG_PACING 1000    ' 1mS delay 
    
    DEFINE  ADC_BITS        10    ' Set number of bits in result
    DEFINE  ADC_CLOCK       3    ' Set clock source (3=rc)
    DEFINE  ADC_SAMPLEUS    50    ' Set sampling time in uS
    
    DEFINE OSC 20    
    
    PORTA = 0
    PORTB = 0
    
    TRISA = %00000100        ' dummy channel = PortA.2 = tied to VCC
    TRISB = %00000100           ' pushbutton input   
    
    
    PUSHB          var PORTB.2        ' Pushbutton    (OLIMEX 18 pin PIC dev board - active low)
    REDLED        var PORTB.3        ' Indicator LED (OLIMEX 18 pin PIC dev board)
    YELLOWLED     var PORTB.5    
    GREENLED     var PORTB.6
    
    
    S1_AVE        var word 
    S2_AVE        var word 
    S1value        var word 
    S2value        var word 
    counter        var word 
    
    ADGO    VAR ADCON0.0
    ADDONE    VAR ADCON0.2
    
    DEBUG REP $00\8,13,10,"Starting Up"
    
    
    ADCON0 = %10010000            '10 = A2D freq FOSC/64
                        '010 = point to the dummy channel, AN2
                        '0 = status bit
                        '0 = unused
                        '0 = "ADON", 1 = on
                    
    
    ADCON1 = %11000000              '1 = right justified
                        '1 = A/D clock divide by 2 is used
                        '00 = unused
                        '0000 = all analog inputs
    
    
    PAUSE 1000
    
    
    counter = 0
    
    GOSUB SENSE1
    GOSUB SENSE1
    GOSUB SENSE1
    S1_AVE = S1value
    
    GOSUB SENSE2
    GOSUB SENSE2
    GOSUB SENSE2
    S2_AVE = S2value
    
    
    
    mainloop:
    
    GOSUB SENSE1
    
    IF S1value < (S1_AVE-3) THEN
        GREENLED =1 
    ELSE 
        GREENLED =0
    ENDIF
    
    
    GOSUB SENSE2
    
    IF S2value < (S2_AVE-3) THEN
        YELLOWLED =1 
    ELSE 
        YELLOWLED =0
    ENDIF
    
    
    IF PUSHB = 0 THEN
        DEBUG DEC S1_AVE, ", ",DEC S1value,", ", DEC S2_AVE, ", ",DEC S2value,13,10
    ENDIF
    
    
    counter = counter +1
    
    IF counter > 3000 THEN
        TOGGLE REDLED
        counter = 0
    ENDIF
    
    
    GOTO mainloop
    
    
    ' *   Microchip AN1298: CVD Touch Sensing using two ADC channels
    ' *
    ' *  1. Set 2nd channel to output, set high (VDD)
    ' *  2. Select 2nd channel on ADC (charges CHOLD to VDD).
    ' *  3. Set sensor line to output, set low (GND)
    ' *  4. Select sensor line as input (TRISx = 1)
    ' *  5. Select sensor channel on ADC (V-div sensor:CHOLD)
    ' *  6. Begin ADC conversion
    ' *  7. Reading is in ADRESH:ADRESL
    
    
    
    SENSE1:
    'setup and read the first sensor (PORTA1, AN1, pin 18)
    
    'TRISA.2 = 0           'Set Dummy channel to digital output
    'PORTA.2 = 1         ' Dummy channel goes high
    ADCON0 = %10010000    ' set A/D to dummy channel  
    PAUSEUS 10        ' let it charge
    PORTA.1 = 0         'Sensor line gets set low
    TRISA.1 = 0        'Sensor line gets set to digital output
    TRISA.1 = 1        'Sensor line gets set to digital/analog input
    ADCON0 = %10001000     'Point A/D to sensor line
    PAUSEUS 10        'wait for voltage to stabilize
    ADCIN 1, S1value    ' Read channel 1 to variable 
    
    'ADGO = 1        'turn on A/D
    'WHILE ADDONE = 1
    'WEND
    'S1value = ADRESL
    
    TRISA.1 = 0           'return sense line to be digital output
    RETURN
    
    
    SENSE2:
    'setup and read the 2nd sensor (PORTA3, AN3, pin 2)
    
    'TRISA.2 = 0           'Set Dummy channel to digital output
    'PORTA.2 = 1         ' Dummy channel goes high
    ADCON0 = %10010000    ' set A/D to dummy channel  
    PAUSEUS 10        ' let it charge
    PORTA.3 = 0         'Sensor line gets set low
    TRISA.3 = 0        'Sensor line gets set to digital output
    TRISA.3 = 1        'Sensor line gets set to digital/analog input
    ADCON0 = %10011000     'Point A/D to sensor line
    PAUSEUS 10        'wait for voltage to stabilize
    ADCIN 3, S2value    ' Read channel 3 to variable 
    
    'ADGO = 1        'turn on A/D
    'WHILE ADDONE = 1
    'WEND
    'S2value = ADRESL
    
    TRISA.3 = 0           'return sense line to be digital output
    RETURN
    
    
    END

  5. #5
    Join Date
    Aug 2004
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Max Power,

    I need to make a correction. 12F675 having 10 bit ADC channels but I was using them as 8 bit. Because in that job I do not need 10 bit conversation.

    I made a system which is working without any problem. But it was not so easy to do that. Because as I told on my first message the system does not work with stability. Let say if you touch the touch point it is not coming the same result all the time. There is like a loop and after that loop you obtain again the same result.
    For instance the ADC value is depend on what you use as touch point (cable , cupper plate etc) The capacity of that equipments are changing the ADC value.
    I was using one short (about 25 cm) thick cable (single line inside). With that cable I was getting $85 value without touching to the cable. If I touch the ADC value was going down as zero ("0") This was the trick for me to catch the touch moment. BUt as I told you it was not stabil. Finally I decided to use also one loop to eliminate the false signals. Finally my siystem is working very well without any problem. I made both TOGGLE system and also NON-TOGGLE system.
    Here is the codes for Toggle system;
    * : TOGGLE *
    '************************************************* ***************
    @ DEVICE pic12F675
    @ DEVICE pic12F675, WDT_ON
    @ DEVICE pic12F675, PWRT_ON
    @ DEVICE pic12F675, PROTECT_OFF
    @ DEVICE pic12F675, MCLR_off
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT

    DEFINE OSCCAL_1K 1

    DEFINE OSC 4

    DEFINE ADC_BITS 8
    'DEFINE ADC_CLOCK 1
    DEFINE ADC_SAMPLEUS 10
    CMCON = 7
    RAW VAR byte 56
    TOP VAR WORD
    SINIR VAR BYTE
    I VAR BYTE
    BUYUK var byte
    KUCUK VAR BYTE
    poz var bit
    OPTION_REG=%01001111
    GPIO=0
    TRISIO=0
    ANSEL = %01011111
    ADCON0=%00001001
    WPU=0
    GPIO.2=1
    SINIR=132 'This is the sensibility value can reach up to 136 according to my touching cable and it can be changed for the different material.
    BUYUK=0
    KUCUK=255

    START:
    GOSUB TUSBAK
    '------------------------do not use these lines I was used them to see the ADC values-------------------------------
    IF RAW>BUYUK THEN BUYUK=RAW
    IF RAW>0 and RAW<KUCUK THEN KUCUK=RAW
    WRITE $10,BUYUK
    WRITE $11,KUCUK
    '-------------------------------------------------------------------------------------------------------------------
    IF RAW<SINIR and POZ=0 THEN 'this is the lines to eliminate the false loop
    TOGGLE GPIO.5
    I=0oz=1
    BIR: gosub tusbak
    IF RAW<SINIR then
    I=0
    GOTO BIR
    ELSE
    I=I+1
    IF I<SINIR then BIR
    ENDIF
    pause 50
    I=0
    goto start
    endif

    pause 10
    poz=0
    GOTO START
    TUSBAK: 'means check if there is a touch
    GPIO.2=0
    ANSEL.2=0
    HIGH GPIO.2
    ADCON0=%00001001 ' The direction of ADC channel is now GPIO.2 and C_hold is charging by the signal coming from AN2.
    ANSEL.0=0 'sensor pin is digital
    TRISIO.0=0 'sensor pin is now output pin
    GPIO.0=0 'sensor pin is LOW and it was discharged
    TRISIO.0=1 'Sensor pin is again input
    ANSEL.0=1 'sensor pin is analog input now
    ADCIN 0,RAW
    BAK:
    TRISIO.0=0
    ANSEL.0=0
    GPIO.0=0
    RETURN
    I hope everything is clear now.

    Ero

  6. #6
    Join Date
    Dec 2010
    Posts
    401


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    I've made a touch controlled dimmer with touch up/touch down controls using this method. There is a lot of variability in the measurement, but empirically I determined a range of values that the result always falls within when touched. I then implemented a "tell me three times" loop to eliminate noise. I'm happy with the result and there are several complete units in use with no complaints.

    I can't post the code because I sold the rights to it, but the only tricks to making it work are in the paragraph before this one.

  7. #7
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Mister_e had an elegant piece of code that worked flawlessly;

    http://www.picbasic.co.uk/forum/show...?t=2671&page=1

    Hope it works for you.

    Regards,

    Anand

  8. #8
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    I remember struggling with a16f690 for a good while wrt cap touch (albeit a different method to the one being discussed here )...I then bought a £1.00 12f1822 & was up and running with cap touch within about 20 minutes!

    moral of the story (for me at least) - get the right pic for the task at hand!

  9. #9
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Thanks everybody. I love this forum.
    Looks like I will get a 12F1822 for my low pin count micro, and a 16F1823 for my higher pin count micro. I was kind of put off by the lack of examples here.

    Hank, I'm so glad you chimed in. I've been reading your posts about your relaxation osc. and the 16F690 with great interest, and I watched your youtube video. the 690 seemed like an easy way to get multiple channels. I've done a few single channel, relaxation osc, cap sensors using a comparator and a timer in the 16F628A, but I was always limited to 1 channel. Then, I got the 16 channel mux and SOIC breakout board from sparkfun and I made a 16 key piano - thats probably my most fun project yet. I really should post the code, it could be so much better.

    You were up and running in 20 min?!? jeez, what am I waiting for! did you use PBP? 2.6 or 3? or... (shudder) C code? :-) what did you program it with? pickit2 pickit3? I might pick your brain a little more later.

    Thanks again.

  10. #10
    Join Date
    Feb 2011
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Max,

    If you like the 12f1822 then you will like the 16f1825 & 1829 -- via newark.com
    May I suggest the 16f1825 @14pins $1.61 and - and 16f1829 @20pins $1.84
    Code:
    PIC16F1825  1,4,20 - 14 dip - 32MHz-31kHz 8k 1kram 256ee 12I/O             $1.61
    PIC16F1829  1,4,20 - 20 dip - 32MHz-31kHz 8k 1kram 256ee 18I/O             $1.84
    The handy image is a cut and paste job from the data sheets
    Attached Images Attached Images  
    Last edited by ofuzzy1; - 8th September 2011 at 05:15. Reason: clarity

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Damn, it's ridiculous how cheap PIC are right now... geez...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,259


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by mister_e View Post
    Damn, it's ridiculous how cheap PIC are right now... geez...
    Especially considering what peripherals they do have now...

    Ioannis

  13. #13
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by Max Power View Post
    Hank, I'm so glad you chimed in. I've been reading your posts about your relaxation osc. and the 16F690 with great interest, and I watched your youtube video. the 690 seemed like an easy way to get multiple channels. I've done a few single channel, relaxation osc, cap sensors using a comparator and a timer in the 16F628A, but I was always limited to 1 channel. Then, I got the 16 channel mux and SOIC breakout board from sparkfun and I made a 16 key piano - thats probably my most fun project yet. I really should post the code, it could be so much better.

    You were up and running in 20 min?!? jeez, what am I waiting for! did you use PBP? 2.6 or 3? or... (shudder) C code? :-) what did you program it with? pickit2 pickit3? I might pick your brain a little more later.
    The 20 minutes on the 12f1822 was probably becuase I'd had to go through the ordeal of getting the 16f690 to work with capacitive touch (& for all even now I'm just one rung up from n00besque territory, back then I wasn't even that!)....and it's not the most beginner friendly! (perhaps it was a rite of passage, to 'grasp' the cap touch basics?!) Seriously, it's incredibly easy to get 4 channel cap touch working on a 12f1822, 16f1824,1827, 1829 etc, what I strongly recommend though is getting the PIC to send info to you PC so you can see the cap module output into TMR1 count

    To your other questions, I was using picbasic V2.6, pickit2 - I'll try & post something soon(ish) to get you started.

    As it goes i was searching the globe yesterday trying to track down a PIC16LF1829 (XLP variant) - nobody seems to stock them, 'microchip direct' do...but they charge about £15 delivery ($23!) - stuff that!
    Last edited by HankMcSpank; - 8th September 2011 at 20:25.

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by Ioannis View Post
    Especially considering what peripherals they do have now...
    Badly want a 8 pin USB device...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,259


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    And may I ask what will you do with the rest 4 pins?

    Ioannis

  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    USB device are often simple... could be anything... at very least Lots of tranceiver possibilities... IR/SPI/I2C/DMX/MIDI/Serial/RF...DAC/ADC? ICSP? ICD? name it

    Sorry guys to be OT
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #17
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,259


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    I was thinking a Capacitive entry something with USB. On a 8-pin would be really small...

    Ioannis

  18. #18
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Hank I'd love to see how you set it up. Thanks

  19. #19
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by Max Power View Post
    Hank I'd love to see how you set it up. Thanks
    Alrighty, a couple of salient points about capacitive touch.

    1. You need an oscillator.

    2, You need something to count the 'pulses' from that oscillator

    3. You need something set as an accurate time 'window' to count the pulses within

    4. You need something to notice when the oscillator 'count' has diverged from the 'normal' count.

    For step 1, the series of chips I mention (12f1822, 16f1824 etc), have a built in capacitive touch module, which makes it very easy (vs say the 16f690)

    To set it up....
    Code:
    CPSCON0 = %10001100 'set the CPS module highest frequency for vcc mode + timer0clock sourced from CPS module. (BIT 1)
    CPSCON1 = %00000000 'select CPS Ch0 - which is pin 7 on a 12lf1822  (or whichever pin you care to use)
    ...simple as eh? (the cps oscillator is now running) whatever CPS pin you choose to use needs to be an input & analogue, so for Ch0 on a 12lf1822 it's RA0....

    Code:
    TRISA.0 = 1
    ANSEL.0 = 1
    ok, next step 2 ....you need something to count the pulses (a timer), in the above snippets I set the CPS module oscillator output pulses to feed into Timer0.

    (note: the prescaler setting will depend on your sensor &* enviromentals ...best to dabble & see what oscillator 'count's you're getting between' successive interrupts
    Code:
    OPTION_REG = %10000111 'use timer0 as interrupt (timebase) TMR0 Prescaler on (bit3) 256:1 prescale value (bits 2-0) 
    T1CON = %11000001 'enable timer 1 (bit 0) & source the clock from the CPS module (bit 6 & 7 =11
    next step 3, we need an accurate set time window ...this is where DT's fab interrupt's come in....
    Code:
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _Timer0_Int,   pbp,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
     
    TMR0 = 0                 'clear down TIMER0
    @ INT_ENABLE  TMR0_INT  'enable timer0 interrupts
    We're almost there- last step! In the interrupt routine, you basically keep a check of the count between 'interrupt's, when the count drops by say 20% (the count goes down when you touch your sensor), then that's a switch press.

    (note: all the stuff below are my variables...call 'em what you like!)
    Code:
    Timer0_Int:
    @ INT_DISABLE  TMR0_INT   ' stop timer0 interrupts while we're in here
    CPS0_PRESENTCOUNT = TMR1     ' take a snapshot of Timer0's present count.
    CPS0_THRESHOLD = CPS0_LASTCOUNT - ((CPS0_LASTCOUNT/100)*2)   ' this sets the 'trigger' up for a 20% diversion (finger press)
    CPS0_LASTCOUNT = CPS0_PRESENTCOUNT ' store away the present timer0count for the next time we come into the interrupt routine
    if CPS0_PRESENTCOUNT <  CPS0_THRESHOLD then 'if the present incoming timer0 count is 20% below the last count, then a finger has been placed on the sensor - go do 'stuff'
    blah blah   
     
    TMR0 = 0 ' clear timer0 down
    @ INT_ENABLE  TMR0_INT  ' re-enable interrupt
    @ INT_RETURN
    (sorry about the formating - looks ok before I post it....horrible after I do!
    Last edited by HankMcSpank; - 9th September 2011 at 15:34.

  20. #20
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    I wish the 'edit' period was open for a little longer here (hint!), I've just noticed an error in that last part (cut/pastes are a hack from a much larger program)

    Code:
    Timer0_Int:
    @ INT_DISABLE  TMR0_INT   ' stop timer0 interrupts while we're in here
    CPS0_PRESENTCOUNT = TMR0     ' take a snapshot of Timer0's present count.
    CPS0_THRESHOLD = CPS0_LASTCOUNT - ((CPS0_LASTCOUNT/100)*2)   ' this sets the 'trigger' up for a 20% diversion (finger press)
    CPS0_LASTCOUNT = CPS0_PRESENTCOUNT ' store away the present timer0count for the next time we come into the interrupt routine
    if CPS0_PRESENTCOUNT <  CPS0_THRESHOLD then 'if the present incoming timer0 count is 20% below the last count, then a finger is on the sensor,go do 'stuff'
    'your stuff goes here'
    endif
     
     
    TMR0 = 0 ' clear timer0 down
    @ INT_ENABLE  TMR0_INT  ' re-enable interrupt
    @ INT_RETURN
    One thing to point out, depending on how reactive you want the 'sensor touch' to be trapped, you may need quite a high interrupt rate, which can bring the PIC to it's knees using the interrupt method above - not a problem if your PIC isn't doing much else, but really hampers things if it's a busy little thing!

    Edit: Damn my speed typing, re this entry...

    Code:
    T1CON = %11000001 'enable timer 1 (bit 0) & source the clock from the CPS module (bit 6 & 7 =11
    remove the above entry in my explanation post above - it relates to timer1! (which I was using too, but not needed in my example above, since I was using timer0)
    Last edited by HankMcSpank; - 9th September 2011 at 15:47.

  21. #21
    Join Date
    Aug 2011
    Location
    Guadalajara, México
    Posts
    28


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Returning to the mister_e's idea of the USB 8-pin chip, I wish to see that too!
    You can do a lot even with NO extra I/O pins: http://www.thinkgeek.com/interests/retro/c208/

    Last edited by ScaleRobotics; - 9th September 2011 at 17:04. Reason: could not resist linking image
    My English doesn't sucks, it's just fugly...

  22. #22
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Hank, awesome. you -seriously-made my day. I'm picking up the 12F1822, and 16F1823s this afternooon, and I should be up and running in no time. will I have to modify my DT file like you did a while back? I can't find that post right now.

  23. #23
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    You can read multiple touch buttons (and perform other functions at the same time) with a PIC16F690/88/887 type device. This example does the keyboard scanning (30+ keys), polyphonic tone generation, PWM, etc. with a single PIC all concurrently.

    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  24. #24
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Ok, my process abpove was right, but the code snippets were riddled with errors (on account I used Timer1 in my code)...I actually spotted one more, so pay no attention to the code snippets above! Here's another attempt below, not saying it's error free (on account again, it's a hack), but use it as a starter, then come back if you've problems...

    (this is for a 12f1822, but the concept is the same for its larger brothers...as are most of the registers - this was just a direct copy of my fuse settings....they may need tweaking to suit your own config)

    Code:
    @ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_SWDTEN & _MCLRE_OFF & _CP_ON & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
    @ __CONFIG _CONFIG2, _LVP_OFF
    '
    DEFINE  OSC 8                'tell picbasic what speed the oscillator is
    '
    INCLUDE "DT_INTS-14.bas"     ' 
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    '
    Osccon = %01110010     'sets the internal oscillator to 8Mhz
    '
    TRISA.0  = 1    . 'make pin 7 (RA1) CPS0 analogue
    ANSELA.0 = 1      'make pin 7 (RA1) CPS0 as input
    '
    OPTION_REG = %10000111 'use timer0 as interrupt (timebase) TMR0 Prescaler on (bit3) 256:1 prescale value (bits 2-0)
    '
    CPSCON0 = %10001101    'set the CPS module highest frequency availabe (fo vcc mode) + timer0 clock sourced from CPS module. (BIT 1)
    '
    CM1CON0 = 0   ' COMPARATOR OFF
    CM1CON1 = 0   ' COMPARATOR OFF
    '
    CPS0_PRESENTCOUNT  var word
    CPS0_THRESHOLD   var word
    CPS0_LASTCOUNT   var word
     '
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _Timer0_Int,   pbp,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
     '
    TMR0 = 0                 'clear down TIMER0
    @ INT_ENABLE  TMR0_INT  'enable timer0 interrupts
    ' 
    main:
    pause 100
    goto main
    '
    '**************************************************************************************************
    Timer0_Int:
    @ INT_DISABLE  TMR0_INT   ' stop timer0 interrupts while we're in here
    CPS0_PRESENTCOUNT = TMR0     ' take a snapshot of Timer0's present count.
    CPS0_THRESHOLD = CPS0_LASTCOUNT - ((CPS0_LASTCOUNT/100)*2)   ' this sets the 'trigger' up for a 20% diversion (finger press)
    CPS0_LASTCOUNT = CPS0_PRESENTCOUNT ' store away the present timer0count for the next time we come into the interrupt routine
    if CPS0_PRESENTCOUNT <  CPS0_THRESHOLD then 'if the present incoming timer0 count is 20% below the last count, then a finger has been placed on the sensor - go do 'stuff'
    blah blah   
     
    TMR0 = 0 ' clear timer0 down
    @ INT_ENABLE  TMR0_INT  ' re-enable interrupt
    @ INT_RETURN
    end
    One unknown, is the timer0 prescaler - you may need to tweak this (the OPTION_REG = %10000111 entry) to keep your oscillator under a count of 255 between successive timer0 interrupts (else timer0 will overflow & you'll have one helluva time trying to trap a finger press!). Actually it's better to use timer1 as the timer to count the CPS oscillator output pulses....since it's 16 bits and gives you more room to play with, but I can't be bothered to rejig the above....just consider iot as a framework to start from!

    one thing I *strongly* recommend, is getting some debiuug/serout/hserout/pickit2uart tool going down onto your PC screen ...just so you can see/confirm what you CPS oscillator counts are ....or you'll be grabbing int the dark.
    Last edited by HankMcSpank; - 9th September 2011 at 17:42. Reason: I

  25. #25
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Oh, and btw...I still consider myself a learner, so any hilarious lines or approach in my code - kindly go easy!! (just thought it worth sharing to save some of you all a bit of time)

  26. #26
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Talking about different chips with CSM capability, lately I have been using the 16F1938/9 chips. They have more programming memory than the chip mentioned above, the 16F1825/9. I was running out of programming memory in my projects with the 16F727.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  27. #27
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Clearly I was having a bad day yesterday ...as Max Power extablished & pointed out on this thread... http://www.picbasic.co.uk/forum/show...486#post107486 in my above snippets, I used timer0 for both the interrupts AND the CPS oscillator pulse counting - OOPS! So best check out his thread for the corrections.

    Sorry about that etc.

  28. #28


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    So Rene,

    Are you getting closer to wrapping up your project and post it here?
    It could save many members a lot of headaches and will catch everybody’s attention as a well crafted piece of code that shows how much a little PIC can do.

    Nick

  29. #29
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    So Nick,

    You are not going to learn anything that way. I have shown what a PIC is capable of. If you want to be able to do those things, then you should do your own legwork instead of just asking for a handout.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  30. #30


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    You are wrong Rene.
    I didn’t ask for any hand out (not for me, I’m not interested in this particular topic but I certainly admire the efforts going on and how other members are dedicating their time for somebody else’s problem). Unfortunately my limited knowledge and experience stops me from offering any input, but if I had it I will gladly make it fully available.
    I was just trying to prove a point some other members touched before: There is a big difference between helping and teasing but this will be your choice.
    I owe all I know in this PIC adventure to the members of this forum who were always willing to help (keyword here is help).
    There is nothing wrong with learning from great code examples and I’m sure that any of the non professional PIC users in this forum will agree with me but you might see it differently. My bad.

    I can only wish you the best.

    Nick

  31. #31
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    And there is also a huge difference between "Giving a man a fish and teaching a man to fish".

    I wish the best as well.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  32. #32
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    http://www.pic24.ru/doku.php/en/osa/.../pk2_osa_piano

    Victor Timofeev appears to be the one you need to talk to Nick.
    Last edited by mackrackit; - 12th September 2011 at 10:28.
    Dave
    Always wear safety glasses while programming.

  33. #33
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by ero View Post
    I would like to use one touch button (or pad) with pic and I read the pdf file of Microchip AN1298 about that matter.
    The document gives the following instructions to do the job;
    * 1. Set 2nd channel to output, set high (VDD)
    * 2. Select 2nd channel on ADC (charges CHOLD to VDD).
    * 3. Set sensor line to output, set low (GND)
    * 4. Select sensor line as input (TRISx = 1)
    * 5. Select sensor channel on ADC (V-div sensor:CHOLD)
    * 6. Begin ADC conversion
    * 7. Reading is in ADRESH:ADRESL
    I decided to write a program for 12F676 considering these explanations.
    Here is the program . Could you pls someone check the program and let me know if there are some mistakes or missed points. Because the program does not work as I want.
    See Microchip AN1298 - Capacitive Touch using only an ADC
    I have been using this for years without any problems.
    Warning: Other compiler

    Norm

  34. #34


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Thank you Dave and Norm.
    Isn’t that just “fishy”?
    It looks like we got the complementary fish and learn how to fish in one strike.

    Nick

  35. #35
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Just in case someone was wanting to deploy a cap touch solution for fish to use - it won't work.....their enviroment is already grounded...which negates the use of cap touch under the water.....probably best going with a sealed hall effect switch, but some intensive training of the fish involved will be needed. (where to actuate, how to actuate etc)

  36. #36
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Name:  Gone_fishing.gif
Views: 9101
Size:  6.3 KB



    ----------------
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  37. #37
    Join Date
    Oct 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    please send me the code for capacitive touch button by using adc channel with pic16f877a controller.

  38. #38
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by sumityadav View Post
    please send me the code for capacitive touch button by using adc channel with pic16f877a controller.
    See Touch interface for a complete code post of a capacitive touch button.
    Warning: Other compiler

    Norm

  39. #39
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Quote Originally Posted by sumityadav View Post
    please send me the code for capacitive touch button by using adc channel with pic16f877a controller.
    Sorry, but thats not really the way we do things here. You have to put in a little effort too! If you try to do it, we will help and attempt to teach you how to do this. Very likely you will end up with working code within a few days. At least show us your schematic if we need it, what pin(s) do you need to detect the touch on? Can you blink an LED?

    If you want a working solution without any effort, there are folks here that will be happy to get paid by you to build it for you.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  40. #40
    Join Date
    Oct 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Capacitive Touch Button by using ADC channel (the CVD system)

    Name:  Untitled.png
Views: 10859
Size:  37.3 KB

    yeah....sorry for that...i am new here....i am an B.TECH final year student.....i am trying to work on touch technology myself....
    this is my circuit diagram in proteius. i tried by burning the code in this but i do not know about the exact digital value after a touch is made
    and one more thing when we talk about the actual hardware i studied that the touch sensor is connected to one or more adc channel. the second channel is continuously scanning and connected to vdd or ground untill the touch is mot made through first one.......can u please explain how?????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts