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


Closed Thread
Results 1 to 40 of 43

Hybrid View

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

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

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    704


    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

  4. #4
    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.

  5. #5


    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

  6. #6
    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!!!

  7. #7


    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

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