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


Results 1 to 40 of 43

Threaded View

  1. #18
    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.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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