16F726 Capacitive sensing module


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    Finally I got my first touch demo working with 16F1827 chip. The CSM module is easy to use and makes program small enough.

    But, I have one problem with the stability of the output that shows whether one is touching, close to touch or not touching at all.

    Although I have included Darrel's Average routine there is a grey region that makes deciding if one is touching not very clear.

    The following test code has a LED indicator to show when touch pad is really touched or not. If finger is very close, value is playing up or down the threshold and makes the LED indicator blink.

    Code:
    OPTION_REG = %10000110    'Tmr0 from 256 presc and Int Clock
      
     T1CON = %11000001 '%00110000    ' TMR1 1:8 prescale, timer1 off
    
    led         var portb.4       
    value       var word
    AvgCount CON 32  ' = Number of samples to average
    FAspread CON 10000 ' = Fast Average threshold +/-
    ADavg  VAR WORD
    flag        var bit
    'Interrupt Engine Setup
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ASM
    INT_LIST  macro    ; IntSource,     Label,      Type,       ResetFlag?
      INT_Handler   TMR0_INT,       _Timer_0,     PBP,    yes
    
     endm
     INT_CREATE               ; Creates the interrupt processor
        INT_ENABLE   TMR0_INT
    ENDASM
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::       
    
    goto main
    
    Timer_0:
        t1con.0=0
        vALUE.lowbyte=tmr1l:VALUE.highbyte=tmr1h
        flag=1
        tmr1l=0:tmr1h=0
        t1con.0=1
    @ INT_RETURN    
    
    main:
    clear
    pause 1000
    
    start:
    if flag=1 then
        flag=0
        gosub Average
    endif
    
    hserout [27,"[H",27,"[10;0H","Value is: ",#vALUE," "]
    
    if VALUE<319 then
        high led
    else
        low led
    endif
    goto start
    
    Average:
        IF Value = ADavg Then NoChange
        IF ABS (Value - ADavg) > FAspread OR Value < AvgCount Then FastAvg
        IF ABS (Value - ADavg) < AvgCount Then RealClose
        ADavg = ADavg - (ADavg/AvgCount)
        ADavg = ADavg + (Value/AvgCount)
        GoTo AVGok
      FastAvg:
        ADavg = Value
        GoTo AVGok
      RealClose:
        ADavg = ADavg - (ADavg/(AvgCount/4))
        ADavg = ADavg + (Value/(AvgCount/4))
      AVGok:
        Value = ADavg  ' Put Average back into Value
      NoChange:
    Return
    Any ideas welcome.
    Ioannis
    Last edited by Ioannis; - 4th December 2011 at 22:21.

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


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    Just a wild guess...

    What if bit 6 of the T1GCON register is set to 0?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    Ioannis,

    Try this modification to the averaging routine for the CSM.
    http://www.picbasic.co.uk/forum/show...598#post107598
    DT

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    I wanted to correct minor mistakes in the comments of the code I posted but it is not possible. Can any of the moderators or Admins see the whole code? I cannot for sure (in the Edit Post mode).

    Dave, I have not changed the T1GCON register which by default on Power up is reset to zero. I do not use the gate anyway.

    Darrel, I missed that. Will try it an get back.

    Thanks both,
    Ioannis

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    I use the CSMs with great success without having to average.

    I basically store away the last cap sense output reading (ie TMR1 count), take the present reading (the TMR1 count again) and just have the program calculate an ongoing 'trigger' threshold count (the threshold being the last TMR1 reading reading minus a certain percentage)

    And then just code it along the lines of if the present reading just takenis less than the threshold (ie the last reading minus a preset percentage), then the sensor has been touched....set a flag variable.

    There should be a huge amount of difference between the non touched count & the touched count ...I set my threshold at something like 30% and it trigger everytime.

    One thing i've found helps greatly with CSM ...is to adjust the CSM oscillator settings & also the sample period so that you get a 'normal' reading in the 10,000->15,000 count ballpark.
    Last edited by HankMcSpank; - 5th December 2011 at 21:37.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    Thanks Hank. Well, 30% seems too much to me. I have managed up to 16%...

    Thanks Darrel too. Yes your suggestions did made alot of difference.

    Ioannis

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default Re: 16F726 Capacitive sensing module

    After some testing, it seems that with the modification Darrel suggested, it needs to touch very quickly to get a 'pressed=1' flag.

    If you approach relatively slow the touch pad it won't get triggered. I may have to play with the constants in the CSM and average too.

    But it made a very reliable system now.

    Thanks for the tips.

    PIC16f1827 with the internal CSM module makes it very easy to make a touch keyboard. Only a couple of registers to setup and you are ready.

    Ioannis

Similar Threads

  1. Version Control
    By btaylor in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 16th October 2011, 17:12
  2. Relaxation oscillators (for capacititive touch sensing)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 6th December 2009, 22:03
  3. mTouch capacitive sensing
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 1st November 2008, 22:54
  4. Replies: 1
    Last Post: - 27th July 2008, 06:14
  5. Rf module
    By tangray in forum Adverts
    Replies: 0
    Last Post: - 7th August 2006, 07:14

Members who have read this thread : 0

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