Help on Capsense !

Discussion in 'Embedded Systems and Microcontrollers' started by PIYUSH SONI, Feb 10, 2014.

  1. PIYUSH SONI

    Thread Starter Member

    Nov 15, 2013
    32
    1
    Hello everyone! I am working on pic 16f1847 (18pin Dip) capacitive sensing module. I am trying to glow a led using capacitive sensing for that I am also using buffer ic in the hardware. I am using internal oscillator(8Mhz). I have taken taken led on RB1 and taking input from RA1 to the load pcb(for touch sensor). I haven't yet written code for all these. I have read the datasheet for configuring capacitive sensing module but I didn't got whole of it. Kindly anyone could help me that which registers I need to configure for this project, and how to calculate time base to measure the change in frequency of the capacitive sensing oscillator. I have to write my code in mikroc pro for pic. :confused:
     
  2. PIYUSH SONI

    Thread Starter Member

    Nov 15, 2013
    32
    1
    Hello FREINDS , how z u all?
    I have studied the whole application note(AN1101).
    I have some doubt in configuring parts i.e; Comparator module. Actually i am using 16f1847 MCU & want to use the Capacitive sensing(CPS) module.
    SO did i have to configure Comparator Control(CMCON) register.
    Please HELP ME FRNDS..!!
     
  3. PIYUSH SONI

    Thread Starter Member

    Nov 15, 2013
    32
    1
    This is mine coding part & i have tried it a lot but nothing is going well. I want to glow the led on PORTB , giving input in PORTA.



    Code ( (Unknown Language)):
    1.  
    2.   void capsense_init();
    3.   void timer_init();
    4.   unsigned int value;
    5.   unsigned int cnt = 0;
    6.  
    7.  
    8. void main()
    9. {
    10. capsense_init();
    11. timer_init();
    12. GIE_bit =1;
    13. WPUA = 0;
    14.  
    15.  while(1)
    16.  {
    17.    if(value < 10)
    18.    {
    19.     RB1_bit = 1;
    20.     }
    21.     else
    22.     {
    23.      RB1_bit = 0;
    24.      }
    25.    }
    26. }
    27.  
    28. void capsense_init()
    29. {
    30. PORTA =0;
    31. TRISA.F1 = 1;
    32. PORTB =0;
    33. TRISB.F1 = 0;
    34. ANSELA = 0b00000010;
    35. CPSCON0 = 0b11001100;
    36. CPSCON1 = 0b00000001;
    37. FVRCON = 0b10001100;
    38. DACCON0  = 0b10000000;
    39. DACCON1 = 0b00000110;
    40. }
    41.  
    42. void timer_init()
    43. {
    44. OPTION_REG =0b10010011;    //  HIGH TO LOW TRANSITION,1:16 PRESCALE ,INTRNAL INSTRUCTION CLCK CYCLE(FOSC/4)
    45. TMR0IF_bit = 0;
    46. TMR0IE_bit = 1;
    47. T1CON = 0b11000101;        //  TIMER1 INIT
    48. T1GCON = 0b11100001;       //  TIMER1 GATE ENABLE BIT,TOGGLE MODE,TIMER0 TIME BASE
    49. TMR1GIF_bit = 0;
    50. TMR1GIE_bit = 1;
    51.  
    52.     GIE_bit = 1;
    53.     PEIE_bit = 1;
    54.     TMR1L = 0x00;
    55.     TMR1H = 0x00;
    56.     TMR0 = 0;
    57.  
    58. }
    59.  
    60. void interrupt()
    61. {
    62. if(TMR0IF==1)
    63. {
    64.  
    65. TMR0IF_bit = 0;
    66. TMR0IE_bit = 0;
    67. TMR1GIF_bit = 0;
    68. TMR1ON_bit = 0;            //  STOP TIMER1
    69.  
    70.   if(cnt == 2)
    71.   {
    72.     value = TMR1L + (unsigned int) (TMR1H << 8);
    73.   }
    74.     cnt++;
    75.     TMR1L = 0x00;
    76.     TMR1H = 0x00;
    77.     TMR0 = 0;
    78.     TMR1ON_bit = 1; // RESTART TIMER1
    79.     TMR0IE_bit = 1;
    80.  }
    81.  
    82. }
     
Loading...