Help on Capsense !

Thread Starter

PIYUSH SONI

Joined Nov 15, 2013
32
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:
 

Thread Starter

PIYUSH SONI

Joined Nov 15, 2013
32
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..!!
 

Thread Starter

PIYUSH SONI

Joined Nov 15, 2013
32
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.



Rich (BB code):
  void capsense_init();
  void timer_init();
  unsigned int value;
  unsigned int cnt = 0;


void main() 
{
capsense_init();
timer_init();
GIE_bit =1;
WPUA = 0;

 while(1)
 {
   if(value < 10)
   {
    RB1_bit = 1;
    }
    else
    {
     RB1_bit = 0;
     }
   }
}

void capsense_init()
{
PORTA =0;
TRISA.F1 = 1;
PORTB =0;
TRISB.F1 = 0;
ANSELA = 0b00000010;
CPSCON0 = 0b11001100;
CPSCON1 = 0b00000001;
FVRCON = 0b10001100;
DACCON0  = 0b10000000;
DACCON1 = 0b00000110;
}

void timer_init()
{
OPTION_REG =0b10010011;    //  HIGH TO LOW TRANSITION,1:16 PRESCALE ,INTRNAL INSTRUCTION CLCK CYCLE(FOSC/4)
TMR0IF_bit = 0;
TMR0IE_bit = 1;
T1CON = 0b11000101;        //  TIMER1 INIT
T1GCON = 0b11100001;       //  TIMER1 GATE ENABLE BIT,TOGGLE MODE,TIMER0 TIME BASE
TMR1GIF_bit = 0;
TMR1GIE_bit = 1;

    GIE_bit = 1;
    PEIE_bit = 1;
    TMR1L = 0x00;
    TMR1H = 0x00;
    TMR0 = 0;

}

void interrupt()
{
if(TMR0IF==1)
{

TMR0IF_bit = 0;
TMR0IE_bit = 0;
TMR1GIF_bit = 0;
TMR1ON_bit = 0;            //  STOP TIMER1

  if(cnt == 2)
  {
    value = TMR1L + (unsigned int) (TMR1H << 8);
  }
    cnt++;
    TMR1L = 0x00;
    TMR1H = 0x00;
    TMR0 = 0;
    TMR1ON_bit = 1; // RESTART TIMER1
    TMR0IE_bit = 1;
 }

}
 
Top