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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Blog Kinetis Design Studio 3.0 Kinetis SDK 1.2 Processor-Expert using FRDM-KL43Z: Dimming Red Led with TPM (varying duty cycle)
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Freedom development platform requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 31 Jul 2015 11:38 AM Date Created
  • Views 425 views
  • Likes 0 likes
  • Comments 0 comments
  • kds+ksdk1.2
  • dimming_pwm
  • frdm-kl43z
  • tpm
  • kds_30
Related
Recommended

Kinetis Design Studio 3.0 Kinetis SDK 1.2 Processor-Expert using FRDM-KL43Z: Dimming Red Led with TPM (varying duty cycle)

bheemarao
bheemarao
31 Jul 2015

Here is a Project created using new KDS version 3.0 and Kinetis software development kit 1.2 on processor expert platform. This is a project for dimming an RED LED using TPM module (i.e varying the duty cycle of the PWM pulse)  implemented on freedom board FRDM-KL43Z .

 

Requirements

To run successfully this exercise, you need first to download following packages (link enclosed):


- IDE toolchain Kinetis Design Studio (KDS) min v3.0
- microcontroller Library
Kinetis Software Development Kit (KSDK) min 1.2
-
FRDM-KL43Z materials (schematics, Quick Start Package and Sample Code Package)
- latest
P&E Micro windows drivers and SDA Applications

[http://www.pemicro.com/downloads/main_downloads_temp/201507291203137773819/Pemicro_OpenSDA_Debug_MSD_Update_Apps_2015_03_12.zip ]


Before connecting your FRDM-KL43Z for the first time to the USB port of your computer, install the P&E Micro windows driver to ensure a correct detection of the board.

Install first the IDE toolchain KDS and when the installation ended successfully, install the MCU Library KSDK keeping the proposed installation path c:\freescale\kds or ksdk unchanged.


Launch KDS and define your workspace path, then select Help, Install New Software, Add, Archive, C:\Freescale\KSDK_1.2.0\tools\eclipse_update, select KSDK_1.2.0_Eclipse_Update.zip and press Open, OK, select KSDK Eclipse Update, press Next, Accept the Licence Agreement and press Finish. The KSDK libraries are now directly available in the IDE toolchain.


The automated code generator Processor Expert is already included in the IDE Toolchain (available separately as Processor Expert Driver Suite for other IDE toolchains).

 

Tutorial instructions

The tutorial shows how to toggle LED with KSDK 1.2.0 in KDS 3.0 and Processor Expert using a Timer Output for FRDM-KL43Z.

  Guide is prepared for red LED which is connected to Timer/PWM Module 0 (TPM0), channel 2 (according to FRDM-KL43Z schematics).

image

 

Create new project

Create new project in KDS 3.0 with KSDK 1.2.0

image

Type the project name e.g. “FRDM-KL43 Dimming using TPM” choose the board FRDM-KL43Z, mark off options Kinetis SDK and Processor Expert

image


image

image

image


Now, your project structure looks like this in the project explorer and Processor Expert windows:

image

Set Processor Expert Settings

Now, go to Components Library, find fsl_tpm component using filters KSDK 1.2.0 and Applicable to Project and by double click add the component to the Processor Expert Component View of your project.

image

Double click on tpmTmr1:fsl_tpm in Components View and Component Inspector view should open automatically


First turn the Component Inspector view to Classical view by unselecting the Tab View option.

image

Enable to reload the counter on Trigger


Set the counter frequency to 1Hz with a Duty cyle of 50%
Allocate TPM0 Channel 4 to Pin LED2_RED (defined by board selection)


Select Clock source MCGIRCLK and choose the Prescaler Divide by 128
Enable the Initialization of TPM0 Channel 4

image

image

Save the configuration by pressing ctrl+s

 

Generate the Processor Expert Code for the component tpmTmr1 that we have just configured

image


Insert the Code:

 

Now its time to insert the code for dimming the led i.e varying the duty cycle from 0 to 100% and again from 100% to 0%. The PWM slowly rises from from 0 and and intensity of the led slowly increases to its max 100% then again intensity decreases from 100 to 0%.


tpmTmr1_ChnConfig0.uFrequencyHZ = 1000;

while(1){
 TPM_DRV_PwmStop(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);
//4 here represent channel no 4 connected to red led
            for(int i=100;i>=1;i--){
          tpmTmr1_ChnConfig0.uDutyCyclePercent = i;
 TPM_DRV_PwmStart(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);
          for(int x=0;x<=300000;x++){} //delay in between for the brightness
 }      // end of for

 TPM_DRV_PwmStop(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);
             for(int i= 0;i<=100;i++){
             tpmTmr1_ChnConfig0.uDutyCyclePercent = i;
 TPM_DRV_PwmStart(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);
             for(int x=0;x<=300000;x++){} // delay in between for the brightness
    }      // end of for
 } // end of while

 


Explanation of coding:


tpmTmr1_ChnConfig0.uFrequencyHZ = 1000;

This line will change the pulse frequency to 1000 Hz

 

TPM_DRV_PwmStop(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);

This will stop the pwm

 

for(int i=100;i>=1;i--){

          tpmTmr1_ChnConfig0.uDutyCyclePercent = i;

TPM_DRV_PwmStart(FSL_TPMTMR1,&tpmTmr1_ChnConfig0, 4U);

          for(int x=0;x<=300000;x++){} //delay in between for the brightness

}      // end of for

The above lines will feed the variable value of ‘i’ from 100 to 1 dutycycle value to the channel configuration 0 which we have done it in processor expert window. After feeding the duty cycle value to channel configuration we start the pwm and insert some delay between brightness


image

Build your project by clicking on the hammer button as shown below:

image

Debugging the FRDM-KL43Z board for the first time, you need to define a Debug Configuration by selecting the appropriate option from the toolbar

image

The FRDM-KL43Z embeds a multimode programming and debug interface easily reconfigurable by drag’n droping from the file explorer new SDA applications in Bootloader mode.


For this example, we are going to select the PEMicro OpenSDA Debug mode.
Select the Debugger tab to choose the Interface OpenSDA Embedded Debug - USB Port
You can now start the Debug session!!

image

Launch the configuration

image

You should now see the Dimming of Red LED i.e brightness varies from 0 to 100%

Below is the video output


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image


I have enclosed the project folder and executables for quick reference


image image image

Attachments:
FRDM-KL43 Dimming using TPM.rar
FRDM-KL43 Dimming using TPM-srec.rar
  • Sign in to reply
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