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


Results 1 to 40 of 43

Threaded View

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

    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.

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