16F726 Capacitive sensing module


Results 1 to 40 of 40

Threaded View

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

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