1. There have been efforts trying to make the whole Design work, baffled by capacity sensor.

According to my research, MSP432P401 has offered great resource for capacity sensor for touching, motion with  capTouch libraries. Since I mean to make design in Energia, which function of timer is confined a lot. In the end, I try customized Tick Count and make results in the end.

2. The fundamental element required in the capacitive touch sensing application described is the variable capacitor itself. This capacitor should be easy to construct as well as sensitive to human touch in order to enable this as an alternative to mechanical buttons and switches. Such a touch sensitive sensor element can be constructed by “opening up” a capacitor structure so that the electric field can be interfered with by a conductive foreign object, in this case, a finger. The figure below shows the touch sensor.

捕获.JPG

It would be same if the capacitive water level sensors since water pose larger dielectric constant of 78.36F/m , in that

捕获.JPG

 

捕获.JPG

 

 

There are two methods of capacity sensor, Oscillator-Based Capacitive Measurement or Resistor-Based Capacitive Measurement, I use the later,

捕获.JPG

using an external resistor to charge or discharge the given capacitive sensor. Using the port pins of the MSP430 to charge or discharge the sensor cap, the internal Timer_A can be used to measure the corresponding charge or discharge time. Given a fixed external resistance to provide the charge/discharge path, the capacitance of the sensor can be measured.  With reference design on MSP430,

捕获.JPG

In fact, for MSP401r, capTouch is one of bottom function in MCU, simplified with one pin without external component, which can be studied later.捕获.JPG

 

3. Capacity sensor with program logic as follows,

capsensor.JPG

 

4. The Energia Sketch as follows,

at first, I have tried tickTime= millis() for acurate time span, but it return 0. The timer still can not catch the transient state or RC circuit, so  I have to use capCount as tick counts for on and off of hand touch.

// Core library for code-sense - IDE-based
#   include "Energia.h"


// Include application, user and local libraries
//#include "rtosGlobals.h"
#include "Timer.h"


// Prototypes
#define   MYCAPSENSOR   2  // Pin 2 for capSensor;
#define   MYCAPSENSOR_POWER   3  // Pin 3 for capSensorn applying power;
#define   THRESHOLDHIGH  1.5  // ---
#define   THRESHOLDLOW   0.3  // ---


// Define variables and constants
uint8_t status = 1;
const uint8_t myLED = BLUE_LED;


const uint8_t myCapSensor = MYCAPSENSOR;
const uint8_t myCapSensor_Power = MYCAPSENSOR_POWER;


uint8_t eTag = 1;
float capVoltage;
uint32_t rcTime;
uint32_t capCount;


///
/// @brief 1st timer
///
Timer myTimer;


///
/// @brief Function for 1st timer
/// @note   Both void and ti_sysbios_interfaces_ITimer_FuncPtr work
/// @bug    Serial.print doesn't work
///
void timerFunction()
{
    
    eTag = 1; 
    capCount=0;
    
    while (eTag){
      digitalWrite(myCapSensor_Power, HIGH);
      delay(100);
      capVoltage = analogRead(myCapSensor)*3.3/1024;
      //Serial.print(capVoltage,DEC);
      //Serial.print("- -\n");
     
      if ( capVoltage > THRESHOLDHIGH ) {
              digitalWrite(myCapSensor_Power, LOW);
              while ( capVoltage > THRESHOLDLOW ) {
                capVoltage=analogRead(myCapSensor)*3.3/1024;    
                capCount++;       
                }    
               Serial.print("capCount= ");
               Serial.print(capCount,DEC);
               Serial.print("\n ");
        }
      eTag = 0;
    }




       
}


/*
 ///
 /// @brief 2nd timer
 /// @bug    Doesn't work. Only one timer allowed
 ///
 Timer myTimer2;

 ///
 /// @brief Function for 2nd timer
 /// @bug    Serial.print doesn't work
 ///
 void timerFunction2()
 {
 Serial.print("1 s\t");
 }
 */


// Add setup code
void setup()
{

    Serial.begin(115200);
    pinMode(myLED, OUTPUT);
    pinMode(myCapSensor_Power, OUTPUT);
        
   
    Serial.print("myTimer.begin... ");
    myTimer.begin(timerFunction, 2000);
    Serial.println("done");
    
/*
     Serial.print("myTimer2.begin... ");
     myTimer2.begin(timerFunction2, 1000);
     Serial.println("done");
 */
    
    Serial.print("myTimer.start... ");
    myTimer.start();
    Serial.println("done");


/*
     Serial.print("myTimer2.start... ");
     myTimer2.start();
     Serial.println("done");
 */
}


// Add loop code
void loop() 
{
    
}

 

with the result in serial console,

capCount number 2 show the touch of hand to input Pin and 1 for not.

捕获.JPG

The result is not idea and the parameter are not selected well, larger resistor and capacitor shall be used for this test. But at least ,it works and it is a good start to go.

With water level sensor, the capacitor is much larger than hand proximate, it will work well ,but thoroughly math calculation is needed.