Capacitive Sensing Module not working on PIC16LF1947 - it just won't oscillate


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    DVice8's Avatar
    DVice8 Guest

    Default Capacitive Sensing Module not working on PIC16LF1947 - it just won't oscillate

    Hi, since a couple of days I am trying to get the built-in CPS Module to work on the PIC16LF1947 with the AN6 (=RF1) pin but without any succes. I don't think the CPS module is even oscillating while if the appropriate registers CPSCON0 and CPSCON1 are set it should start up. Also looking at the Timer1, that uses the CPS oscillator as source, it doesn't count anything. I really don't know what I am doing wrong. It all seems to be so straight forward but it isn't at all.

    Code:
    #include <htc.h>#include <pic.h>
    #include <stdio.h>
    
    
    __CONFIG(	        WDTE_OFF				//Wacthdog Timer Disable
    			& FOSC_INTOSC
    			& MCLRE_ON
    			& FCMEN_OFF			//Fail-Safe Clock Monitor enable bit enabled
    			& LVP_OFF				//Low Voltage Programing On
    			& CP_OFF				//Table Read-Protect
    			& CLKOUTEN_ON);		//Clock out enable bit
    
    
    #define _XTAL_FREQ 8000000
    
    
    void capInit(void);
    void interrupt isr(void);
    
    
    int reading;
    int average = 0;
    
    
    void main(void){
    	OSCCON = 0b01110010;	// 4xPLL off, 4MHz, internal clock
    
    
    	ANSELA = 0;			// Digitaal
    	TRISA = 0;				// Ouput
    	LATA = 0;				// Low signal
    
    
    	LATF = 0;				// Low signal
    	ANSELF = 1;			// Analoog
    	TRISF = 1;				// Input
    	
    	RA1 = 0;				// Red
    	RA2 = 0;				// Green
    	RA3 = 0;				// Bleu
    
    
    	capInit();
    
    
    	while(1){}
    }
    
    
    void capInit(void){
    	CPSCON0 = 0b10001101;			// Cap sense ON, internal osc, High Range
    	CPSCON1 = 0b00000110;			// channel 6
    	
    	OPTION_REG = 0b11101000;        		// T0CS:    Transition on RA4/T0CKI
                                        				// Prescaler assigned to WDT
    	
    	TMR0IF = 0;
    	TMR0IE = 1;
    	
    	T1CON = 0b01000001;
    	
    	TMR1IF = 0;
    	TMR1IE = 1;
    
    
    	T1GCON = 0b11110001;
    	
    	TMR1GIF = 0;
    	TMR1GIE = 1;
    
    
    	GIE = 1;
    }
    
    
    void interrupt isr(void){
    	if (TMR0IE && TMR0IF)				// Overflow interrupt
    		TMR0IF = 0;				// Clear T0IF every time
    
    
    	if (TMR1GIF && TMR1GIE){			// Gate interrupt
    		TMR1GIF = 0;
    		
    		TMR0 = 0;
    		
    		reading = TMR1L + (unsigned int)(TMR1H << 8);
    		
    		if (reading < average - (average >> 4))
    			RA1 = 1;
    		else if (reading > average - (average >> 3)){
    			RA2 = 1;
    			average = average - (unsigned int)(average >> 4);
    			average = average + (unsigned int)(reading >> 4);
    		}
    
    
    		TMR1L   = 0x00;						// Reset Timer1
    		TMR1H   = 0x00;						//   "     "
    		TMR1ON  = 1;						// Restart Timer1
    		
    		TMR0 = 0xFE;
     		T1GGO = 1;
    	}
    }

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

    Default Re: Capacitive Sensing Module not working on PIC16LF1947 - it just won't oscillate

    You will have better luck getting an answer to you C code problem on a forum that does C. This forum is for PicBasicPro.
    Dave
    Always wear safety glasses while programming.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts