Jump to content
Sign in to follow this  
MSPLife

Can not config Pin Osc for capacitive sensing

Recommended Posts

Hi everyone,

I am a newbie with capacitive touch, I did a example which I can not config P1.1, P1.2, P1.3 as capacitive sensing function, another pins is ok. The code as below, I just change which PIN, and Port.

/ Middle Element (P2.5)
const struct Element middle_element = {

              .inputPxselRegister = (uint8_t *)&P1SEL,
              .inputPxsel2Register = (uint8_t *)&P1SEL2,
              .inputBits = BIT2,
              // When using an abstracted function to measure the element
              // the 100*(maxResponse - threshold) < 0xFFFF
              // ie maxResponse - threshold < 655
              .maxResponse = 450+655,
              .threshold = 450
};

//*** CAP TOUCH HANDLER *******************************************************/
// This defines the grouping of sensors, the method to measure change in
// capacitance, and the function of the group

// One Button Sensor
const struct Sensor one_button =
               { 
                  .halDefinition = RO_PINOSC_TA0_WDTp,	// Sensing Method
                  .numElements = 1,						// # of Elements
                  .baseOffset = 0,						// First element index = 0
                  // Pointer to elements
                  .arrayPtr[0] = &middle_element,  		// point to middle element
                  // Timer Information
                  .measGateSource= GATE_WDT_ACLK,     //  0->SMCLK, 1-> ACLK
                  .accumulationCycles= WDTp_GATE_64   //64 - Default                                                
               };
void main(void)
{ 

  // Initialize System Clocks
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  BCSCTL1 = CALBC1_1MHZ;                // Set DCO to 1, 8, 12 or 16MHz
  DCOCTL = CALDCO_1MHZ;
  BCSCTL2 |= DIVS_2;                    // divide SMCLK by 4 for 250khz
  BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO
  
  P1OUT = 0x00;							// Clear Port 1 bits
  P1DIR |= BIT0;


  P2SEL &= ~(BIT6 + BIT7);				// Configure XIN (P2.6) and XOUT (P2.7) to GPIO
  P2OUT = 0x00;							// Drive all Port 2 pins low
  P2DIR = 0xFF;							// Configure all Port 2 pins outputs

  // Initialize Baseline measurement
  TI_CAPT_Init_Baseline(&one_button);
  
  // Update baseline measurement (Average 5 measurements)
  TI_CAPT_Update_Baseline(&one_button,5);

  // Main loop starts here
  while (1)
  {

  	#ifdef ELEMENT_CHARACTERIZATION_MODE
	// Get the raw delta counts for element characterization
	TI_CAPT_Custom(&one_button,&dCnt);
	__no_operation(); 					// Set breakpoint here
	#endif

	#ifndef ELEMENT_CHARACTERIZATION_MODE
	// Check if the middle element sensor has been triggered. The API call
	// compares the value from the sensor against the threshold to determine
	// trigger condition
	if(TI_CAPT_Button(&one_button))
	{
		// Do something
		P1OUT |= BIT0;                            // Turn on center LED
	}
	else
	{
		P1OUT &= ~BIT0;                           // Turn off center LED
	}

    // Put the MSP430 into LPM3 for a certain DELAY period
    sleep(DELAY);
    #endif

  }
} // End Main

Please give me an instruction to config them as capacitive sensing.

Thank you!

Share this post


Link to post
Share on other sites

Maybe not useful, but are you running this on a G2 launchpad?

 

P1.1,P1.2 are connected to the debugger, removing the serial link should isolate them....

 

But, P1.3 is connected to a switch, and actually has a pull-up and debounce cap (R34/C24) populated on the PCB. this will mess with the capacitive sense, and drain the parasitic capacitance before it can be measured.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×