element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Safe and Sound
  • Challenges & Projects
  • Design Challenges
  • Safe and Sound
  • More
  • Cancel
Safe and Sound
Blog Safe & Sound - Smart Safety Glasses #5: Capacitive sensing in CCS
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: salexku
  • Date Created: 14 Apr 2017 8:17 PM Date Created
  • Views 616 views
  • Likes 4 likes
  • Comments 2 comments
Related
Recommended

Safe & Sound - Smart Safety Glasses #5: Capacitive sensing in CCS

salexku
salexku
14 Apr 2017

In the previous blog post I've described how to establish a WiFi link with the CC3100 booster pack and Energia. Unfortunately, I couldn't find any Enregia libraries that implement capacitive sensing and support the MSP432. The libraries which are out there, are only for the MSP430. I've spent a considerable effort trying to get them working but finally decided to switch to CCS.

So, In this blog post I'll describe how to test the capacitve sense functionality using TI's libraries in Code Composer.

 

Capacitive touch sensing in the MSP432

 

I've already touched (get it? touched?) on this topic on my second blog post, but here is a short recap:

The capacitive sensing method being used by the MSP432 is the relaxation oscillator (RO) method. The internal oscillator has a variable frequency as a function of capacitance. As the capacitance increases, the oscillator's frequency decreases. A second, fast timer, is used to count the number of the RO pulses that fit within a certain time interval. When a person touches the sensor he causes the capacitance to increase, hence causes the frequency and number of pulses to decrease. The software can than detect this change in number of pulses and trigger a certain action.

 

image

 

The MSP432 is already equiped with all the necessary hardware to implement RO based capacitive sensing, so only the an external sensing element is needed and the software are required.

The code implementation is based on the TI's Capacitive touch software library. I found it rather difficult to figure out the various timer configuration required, but fortunately, my application is very basic in terms of the many features the library provides and it turned out to be rather simple to make use of the basic API's.

According to TI, the library provides three different layers of abstraction. I'm using the lowest level which is the TI_CAPT_RAW function. This function provides the raw capacitance measurement (number of pulses) to the application layer. The other layers implement various baseline tracking algorithms (i.e., determine a reference value for the capacitance. A change in capacitance will be sensed relative to this reference value). For now, however, I find it more straightforward to monitor the raw values and set an appropriate threshold manually.

 

 

So, in the rest of the post we will:

  • See how to load the example project from the Capacitive touch library to CCS and modify the code to simply read the number of pulses.
  • Test the code with the Capacitive Touch Booster Pack.
  • Test the code with the "parallel plate" sensing element described in blog post #2.

 

Loading the example project to CCS:

 

1. Download the 432CAPSENSELIBRARY from the above link and unzip the file.

2. In CCS, import the project intro the workspace: File --> Import --> Code composer Studio --> CCS Projects

image

3. Click Browse and navigate to "Download Folder"l\Firmware\Source\430BOOST-SENSE1_CapTouch_MSP432P401R\CCS. Finally, click the "Finish" button and the project should be imported into the workspace:

image

 

4. Now, the original code implements a variety of features such as proximity detection, scroll wheel, led flashing, etc. Since all I really need is the raw number of counts, I've modified the main() function to simply read the raw number of counts and report it via UART.

The TI_CAPT_RAW is being called periodically and writes the number of counts to the "raw_data" variable. This number is converted to a string and transmitted via UART. We are expecting this number to decrease as we touch the sensor (capacitance increases). The sensor under test is the middle button of the Touch Booster pack as can be seen by the first argument that is being pass to the TI_CAPT_RAW function. "middle_button" is a class defined in "structure.c". The class includes various parameter definitions such as port configuration, thresholds, etc. Maybe these parameters will be used later for fine tuning but for now lets see how it works with the default values.

 

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;           // Stop watchdog timer
    System_setupDIOPorts();
    /* Setup Clocks: DCO to 1MHz and SMCLK to DCO/8 = 125kHz, MCLK = DCO, ACLK = REFO */
    /* MAP_function will use ROM version of function if available                     */
    MAP_FPU_enableModule(); // Enable FPU for DCO frequency calculation
    MAP_CS_setDCOFrequency(CS_1MHZ); // Set DCO Frequency to 1MHz
    MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8); //Source DCO/8 for SMCLK
    MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); //Source DCO for MCLK, no divider
    MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); //Source REFO for ACLK
    NVIC_EnableIRQ(TA0_0_IRQn); //Enable TA0 interrupt in NVIC

    UART_init();
    UART_print("Hello\n\r");
    char tmp[10] = "";
    short int raw_data[4];
    while(1)
    {
        TI_CAPT_Raw(&middle_button,raw_data);
        char tmp1[10] = "";
        itoa(raw_data[0],&tmp1[0],10); // convert int to string
        UART_print(tmp1);
        UART_print("\n\r");
        __delay_cycles(100000);
        __no_operation(); // set breakpoint here
    }

}

 

 

Testing it out:

 

1. Connect the Capacitive touch booster pack to the MSP432 Launchpad.

2. Build the project and program the MSP.

3. Open a serial monitor and observe the changes in the number of counts when touching the middle sensor. So, as expected, we see that touching the sensor reduces the number of counts that fit inside the measurement interval.

 

imageimage

 

4. Ok, it seems to be working. Now, let's test it with our parallel-plate-capacitor sensor.

  • First, we have to figure out to what port is the middle button connected to. This is defined in the structure.c file, as we see below. So, the middle sensor is connected to P5.0. This is the port to which we will connect the top plate of the sensor. The bottom plate will be connected to GND.

 

const struct Element middle_element = {

        // Select P5.0
  .inputBits = CAPTIOPOSEL_5 + CAPTIOPISEL_0,

 

  • Connect sensor to the lanuchpad:

          Top Plate            ---->         P5.0

          Bottom Plate      ----->        GND

image

  • Test it out with the glasses: The left photo shows the capacitance measurement with the glasses off and the right one shows it with the glasses on.

         Great! we see that wearing the glasses increases the capacitance that is connected to P5.0 at thus reduces the number of counts.

imageimage

 

Summary

  • In this post we've seen how to implement a very basic touch sensor based on the example project in the Capacitive Touch Library.
  • The code was tested with the CapTouch booster pack and the "parallel-plate-conductive-tape" sensing element.
  • We've seen that wearing the glasses reduces the number of counts (=increases capacitance) and a certain threshold can be established.
  • In the next post we'll return to establishing a WiFi link, this time using CCS and integrating it with the capacitive sensing.
  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +1
    Nice update. I like the test results. You have a good reliable way to check if the safety glasses are being properly worn. It will be interesting to see your results in an actual shop environment. DAB
  • e14phil
    e14phil over 8 years ago

    Nice update keep going! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 8 years ago

    Nice update.

     

    I like the test results.

    You have a good reliable way to check if the safety glasses are being properly worn.

    It will be interesting to see your results in an actual shop environment.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube