example of capacitive sensor example for 18fxxK22 series


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: example of capacitive sensor example for 18fxxK22 series

    here what i have gathered from microchip ap note AN1250 and the 18F87k22 data sheet

    the readings i am getting ranging 0 - 4095 , jumping all over the place , without me touching the port pin at all

    no edge has been detected on the status bits

    http://ww1.microchip.com/downloads/e...tes/01250a.pdf

    http://ww1.microchip.com/downloads/e...Doc/39960d.pdf - section 27.x

    some input on what i may be doing wrong on the setup / operation of the CTMU would be great

    Cheers

    Sheldon
    Code:
    
    Cap_Touch_Sensor:
      '--------- Touch Switch varables / constants  ----------------
     
     
     ' ----- Setup CTMU - for Touch Switch on AD17 , used when IR-TX ----------
          CTMUCONH = %00000000    ' Bit7 CTMU enable 1=On ,0 = Off, Bit6 N/A , Bit5 CTMUSIDL - 1= disable modual when in idle mode 0= continue module operation when in idl mode 
                                  ' Bit4 TGEN 1 = ENABLE 0= disable edge delay gen , bit3 EDGEN 1= edges not blocked 0= edges blocked , Bit2 EDGSEQEN - 1 = edge1 occure prior edge2 can 0= no edge seq 
                                  ' Bit1 IDISSEN 1= grounded 0= Not grounded  Analoge current Source , CTTRIG 1= Trig Output enabled  0 = disabled 
                                  
          CTMUCONL = %00010100    ' Bit7 EDG2POL 1= edge2 pos edge responce 0= edge2 neg edge responce ,Bit6-5 Edge2 select source= 11=CTED1PIN 10=CTED2 pin, 01 ECCP1 , 00 ECCP2                         
                                  ' Bit4 EDG2POL 1= edge1 pos edge responce 0= edge1 neg edge responce ,bit3-2 Edge1 source= 11=CTED1PIN 10=CTED2 pin, 01 ECCP1 , 00 ECCP2  
                                  ' Bit1 = Edge 2 status 1= event occured 0= Not occured ,Bit0 = Edge 1 status 1= event occured 0= Not occured , 
        
          CTMUICON = %00000011    ' Bit7-2 011111-000001 max - min pos change from nominal current , 000000 Nominal current output set by bit1-0 ,111111 -100000 min -max neg change from nominal current
                                  ' Bit1-0 IRNG - Current Source Range Select bita 11= 100xbase(55uA) 10= 10xbase(5.5uA) ,01=base (0.55uA), 00= current sourse disabled 
     
     
     
     
         CTMUCONH.7 = 1            ' enable CTMU 
       '  ANCON2.1 = 0              ' Set PortG.3 = 0 - Set portG.3 to Digital - to ensure sensor port is at zero potential - AN17 - AD touch switch input 1R-TX mode
       '  TRISG.3  = 0              ' Set TRISG.3 = 0 - Set portG.3 to Output  - to ensure sensor port is at zero potential - AN17 - AD touch switch input 1R-TX mode
       '  LATG.3   = 0              ' Clear PortG.3 = 0 to ensure sensor port is at zero potential
       '  pauseus 5                 ' wait for zero potential
        
         ANCON2.1 = 1              ' Set PortG.3 = 1 - Select portG.3 to Analog  - AN17 - AD touch switch input 1R-TX mode
         TRISG.3  = 1              ' Set TRISG.3 = 0 - Select portG.3 to Input   - AN17 - AD touch switch input 1R-TX mode
         ADCON0 = %01000100        ' Select the A/D channel - AN17 but dont turn on a/d 
         CTMUCONH.1 = 1            ' IDISSEN (Bit1) - Drain any charge on the A/D channel  
         pauseus 125                ' wait for charge to drain 
         CTMUCONH.1 = 0            ' IDISSEN (Bit1) - Stop Discharge on the A/D channel  
         CTMUCONL.1 = 0            ' make sure edge2stat is 0 
         CTMUCONL.0 = 1            ' Begin Charging  Edge1stat
         pauseus 125                ' wait for charge 
         CTMUCONL.0 = 0            ' stop Charging  Edge1stat
          HSEROUT2 ["before a/d  - edge2 = ",dec CTMUCONL.1, "  edge1 = ",dec CTMUCONL.0,13,10]
         ADCON0 = %01000101        ' Select the A/D channel - AN17 and turn on A/D module 
         adcin 17,value1            ' do ADC reading on AN17 - touch switch input 
         HSEROUT2 ["value1 = ",dec4 value1,13,10]
         HSEROUT2 ["edge2 = ",dec CTMUCONL.1, "  edge1 = ",dec CTMUCONL.0,13,10,10,10]
        ' gosub aVERAGE             ' accumulate the values for base line and set Touchsw1 flag 
        ' HSEROUT2 ["value1 avg = ",dec4 value1,13,10]
        ' HSEROUT2 ["TouchSW1 = ",dec touchsw1,13,10,10,10]    
         ADCON0 = %01000100        ' Select the A/D channel - AN17 and turn off A/D module 
    return

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: example of capacitive sensor example for 18fxxK22 series

    I didn't use CTMU...
    But I tried CVD method, it worked, but I wasn't happy with that...
    CVD is nice because you can use on any pic with ADC.

Similar Threads

  1. 16F726 Capacitive sensing module
    By Byte_Butcher in forum General
    Replies: 39
    Last Post: - 15th May 2014, 20:40
  2. Need help setting up Capacitive Sense 12F1822
    By Heckler in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th November 2013, 22:10
  3. Capacitive sensor using ADC
    By johnmiller in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st November 2010, 11:46
  4. Replies: 3
    Last Post: - 29th September 2010, 15:45
  5. mTouch capacitive sensing
    By jrprogrammer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 1st November 2008, 23:54

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