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
Freedom development platform
  • Products
  • Dev Tools
  • Freedom development platform
  • More
  • Cancel
Freedom development platform
Documents Codewarrior Tutorial for FRDM-KL25Z : Touching the Freescale Freedom Board
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Freedom development platform to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: FreescaleTools_and_Software
  • Date Created: 2 Oct 2012 1:15 PM Date Created
  • Last Updated Last Updated: 8 Oct 2021 5:13 AM
  • Views 816 views
  • Likes 0 likes
  • Comments 1 comment
Related
Recommended

Codewarrior Tutorial for FRDM-KL25Z : Touching the Freescale Freedom Board

This tutorial was extracted from Erich Styger blog http://mcuoneclipse.wordpress.com with his agreement.

 

 

 

I have covered several aspects of the Freescale FRDM-KL25Z Freedom board with a tutorial: LED, Accelerometer and FreeRTOS.
One peripheral on the board is missing so far: the touch slider area.

 

Freedom KL25Z Board Touch Slider Area

Freedom KL25Z Board Touch Slider Area

 

 

 

The Kinetis device has implemented a TSS (Touch Sensing Software) in the silicon. It helps a lot to implement a capacitive touch sensing application, but requires a lot of reference manual reading. Luckily there is a Processor Expert driver which simplifies things a lot. So in this tutorial I’m using that Freescale Processor Expert component.

 

Creating the Project

 

I’m not going into the details to create a Processor Expert project with CodeWarrior for MCU10.3 here. You should be able to find all the needed information in the LED, Accelerometer and FreeRTOS tutorials.

Alternatively, it is possible to add the touch support to any of the above tutorial projects.

 

Related Tutorials

 

  • Tutorial: Enlightening the Freedom KL25Z Board
  • Tutorial: Accelerating the KL25Z Freedom Board
  • Tutorial: Tutorial: Freescale FRDM-KL25Z Freedom with FreeRTOS and Kinetis-L

 

Adding the TSS_Library Processor Expert Component

 

From the Components Library view, I add the TSS_Library component to my project, either with the context menu (Add to project), with the ‘+’ icon in that view or simply double clicking on the TSS_Library component:

 

Adding TSS_Library Processor Expert Component

Adding TSS_Library Processor Expert Component

Where are the Electrodes?

 

Looking at the board schematics, it shows that there are two electrodes, connected to PTB16/Channel9 and PTB17/Channel10:

 

FRDM-KL25Z TSI Schematics (Source: Freescale)

FRDM-KL25Z TSI Schematics (Source: Freescale)

 

Adding the Electrodes

 

This two electrodes needs to be configured. For this I select the TSS_Library component in my project. In the Component Inspector view define/add two electrodes. For this I press the ‘+’ sign to increase the number of Electrodes to two.

 

Hint 1: If the Component Inspector view is not visible: use the context menu ‘Inspector’ on the TSS_Library icon.

Hint 2: In order two show the ‘+’ and ‘-’ sign for the number of electrodes as shown in the screenshot below, I need to click image into the field.

 

 

Adding Electrodes

Adding Electrodes

 

 

With this, I set it up to use two electrodes:

 

Using two Electrodes

Using two Electrodes

 

 

Setting the Controls

 

The really cool thing with this Processor Expert component is that it provides support for all kind of controls. So I add one slider control, and for now I go with the default settings:

 

Definition of controls

Definition of controls

 

 

Note that this is a *ASLIDER* (Analog Slider) control. I have it configured that it has a range of 0..64, and that the values will be in a structure named TSS1_cKey0. This structure name and value range is what we will use later when the TSS library detects a touch.

 

 

Adding LEDs

In my code I want to show the status of the slider on the RGB LED of my board. I do not explain the steps how to add the LEDs to my project, as this is explained in details in the LED tutorial.

 

Hint: I can copy-paste the LED component from my other tutorial projects. That way it only takes seconds to have it in my new project.

 

 

Touch Project with LEDs added

Touch Project with LEDs added

Generating Processor Expert Driver Code

 

Now I can generate my driver code based on my settings. The simplest way is to select the project and to use the ‘Generate Processor Expert Code’ button:

 

Generate Processor Expert Code

Generate Processor Expert Code

 

 

The generated code is placed into the ‘Generated_Code’ project folder, which now has my TSS driver code based on my settings:

 

Generated TSS Driver Code with TSS Files

Generated TSS Driver Code with TSS Files

 

 

Initializing the TSS Library

 

I have not initialized the TSS library. For this I need to call the Configure() function. An easy way to call that function is to drag&drop that method into my source code:

 

Configuring the TSS Library: drag&drop the method

Configuring the TSS Library: drag&drop the method

 

TSS Library Task Function

 

The other thing is: I need to periodically call the TSS library with a call to TSS_Task(). So my code in main needs to add this in a loop:

 

 

01int main(void)
02/*lint -restore Enable MISRA rule (6.3) checking. */
03{
04/* Write your local variable definition here */
05
06/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
07PE_low_level_init();
08/*** End of Processor Expert internal initialization. ***/
09
10Configure(); /* initialize TSS library */
11for(;;) {
12TSS_Task(); /* call TSS library to process touches */
13}
14/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
15/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
16#ifdef PEX_RTOS_START
17PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
18#endif
19/*** End of RTOS startup code. ***/
20/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
21for(;;){}
22/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
23} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

 

 

 

TSS Library Callback

 

 

The function TSS_Task() will detect if the slider has been touched, and will call a callback. This callback is named ‘fcallBack()‘. For my first (and only) control in the system this is TSS1_fCallback0():

 

TSS Library Callback

TSS Library Callback

 

 

Double clicking on that callback event jumps the editor view to the user callback function of it in Events.c:

 

TSS Event Callback in Events.c

TSS Event Callback in Events.c

 

 

Remember the Range and Structure Name we defined in the control? Now it is time to use it here and to turn on a LED depending on the range value. This is implemented with following code:

 

 

1void TSS1_fCallBack0(TSS_CONTROL_ID u8ControlId)
2{
3(void)u8ControlId; /* avoid warning */
4LED1_Put(TSS1_cKey0.Position<=20);
5LED2_Put(TSS1_cKey0.Position>20 && TSS1_cKey0.Position<=40);
6LED3_Put(TSS1_cKey0.Position>40 && TSS1_cKey0.Position<=64);
7}

 

 

 

Touching it

 

 

The rest is easy: compile, download and run it on the board. With this, LED1 is on if I touch it on the left, LED2 is on if I touch it in the middle, and LED3 is on if I touch it on the right :-) .

 

Touch on the left: red LED on

Touch on the left: red LED on

 

 

Touch in the Middle: Green LED on

Touch in the Middle: Green LED on

 

 

Touch on the right: blue LED on

Touch on the right: blue LED on

 

 

Summary

 

Using capacitive touch functionality is usually not easy. But the TSS Processor Expert component delivered with the Eclipse based CodeWarrrior for MCU10.3 makes it really easy. For sure there are a lot of things which can be fine tuned (sensitivity, resolution, kind of controls), but I hope this gives an idea what can be implemented. Additionally there is a lot of documentation about the TSS library available here.

 

The current software was attached to this document but I would recommend to download the updated version on GitHub with all the Processor Expert components.

 

Happy Touching :-)

Attachments:
Freedom_Touch.zip
  • processor_expert
  • freescale
  • Cortex-M
  • codewarrior
  • frdm-kl25z
  • kinetis-l
  • arm
  • freedom
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • McuOnEclipse
    McuOnEclipse over 13 years ago

    The link to the project and sources is this one:

    http://www.steinerberg.com/EmbeddedComponents/Examples/FreedomBoard/Freedom_Touch.zip

     

    Erich

    • Cancel
    • Vote Up 0 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