Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    Raul reacted to energia in [Energia Library] Capacitive Touch library   
    [Edit: New library attached with a bug fix for CapTouch on port 1 in combination with Serial]
    Attached CapTouch.zip is a capacitive touch library for the MSP430. All examples are written for the capacitive touch boosterpack (http://www.ti.com/tool/430boost-sense1). If you do not have one of these then it's fairly simple to create a capacitive sensor from a bare piece of PCB. Just solder a wire to it and hook it up to one of the pins. The library is based on the relaxing oscillator method. Each of the MSP430 pins can be connected to the internal relaxing oscillator peripheral called PinOsc. The PinOsc is a comparator based relaxing oscillator that changes frequency based on a change in capacitance. The idea is to "measure" the capacitance by counting the number of relaxing oscillator cycles during a fixed amount of time. The time during which we measure is called the gate time. So we need a counter to count the number of cycles and a timer to set the gate time during which we count. In this case the watchdog timer in interval mode is used as the gate timer and the capture compare feature of Timer0 is used as the counter. To trigger a measurement, the watchdog timer is set to a certain gate time, the counter start running and the MSP430 is put into LPM3. When the watchdog triggers, the MSP430 wakes up and triggers the capture of the Timer0 counter.
    There is a lot more to it than this though such as baseline tracking, threshold, etc. If you would like to get to the details then I recommend reading the following literature:
    There are 4 examples included in the library to show how to use the API's. To install the library, unzip the attached and copy it to a folder called libraries in you Energia Sketch folder. 
    Include CapTouch.h in your Sketch.
    CapTouch(uint8_t pin, uint8_t sensorType);
    Creates a CapTouch instance and calculates the baseline.
    pin: The pin to use as a capacitive touch or proximity pin.
    sensorType: This is either TOUCH_PROXIMITY for a proximity sensor or TOUCH_BUTTON for a button.
    void setThreshold(uint16_t threshold);
    Sets the threshold that needs to be exceeded for the button to be considered as touched. See isTouched() for more details.
    uint16_t getBaseline();
    Returns the the current baseline value of the last measurement of the untouched sensor. Note that a call to this library does not trigger a measurment.
    uint16_t getMeasured();
    Returns the measured value of the last measurement of the sensor. Not that a call to this library does not trigger a measurment.
    int16_t getDelta();
    Returns the difference between the baseline value and the las measured value. Note that a call to this function does not trigger a measurement.
    uint8_t isTouched();
    If the the difference between the baseline (untouched sensor) and the measured value exceeds the threshold then the button is considered to be touched.
    A call to this function triggers a measurement of the sensor.
    Returns 1 if the sensor is touched otherwise 0.
  • Create New...