element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
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-K22F: Dimming Green Led with FTM (varying Duty Cycle)
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Freedom development platform requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bheemarao
  • Date Created: 17 Jul 2015 10:24 AM Date Created
  • Views 292 views
  • Likes 0 likes
  • Comments 1 comment
  • kds+ksdk1.2
  • frdm-k22f
  • led_dimming
  • kds3.0
  • ftm_example
Related
Recommended

Kinetis Design Studio 3.0 + Kinetis SDK 1.2 Processor-Expert using FRDM-K22F: Dimming Green Led with FTM (varying Duty Cycle)

bheemarao
bheemarao
17 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 project demonstrates dimming the LED (i.e varying the duty cycle from 0-100% and 100 to 0%) using FTM module of PE implemented using freedom board FRDM-K22F.

 

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-K22F materials (schematics, Quick Start Package and Sample Code Package)
- latest
P&E Micro windows drivers and SDA Applications


Before connecting your FRDM-K22F 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 vary the duty cycle of the FTM module connected to LED with KSDK 1.2.0 in KDS 3.0 and Processor Expert using a Flex timer module Output for FRDM-K22F freedom board.


Guide is prepared for Green LED which is connected to PTA2/FTM Module 0 (FTM0), channel 7 (according to FRDM-K22F 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-K22 dimming using FTM’, choose the board FRDM-K22F, mark off options Kinetis SDK and Processor Expert

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_ftm 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

Rename the component flexTimer1:fsl_ftm to Diming_LED

image

Before we proceed for changing the settings in component inspector go to CPU component and make the below changes

image


This is required as the pin PTA-2 is in conflict with TDO signal of Debug interface (JTAG)

Double click on Diming_LED in Components View and Component Inspector view should open automatically

 

Configure the FTM module as shown below:

image


Set frequency = 1 Hz and Duty cycle = 50% and Mode = Edge aligned PWM

Click on the Fault pin tab as shown below where it is in red mark indicating error

image

Now uncheck the Fault pin 2 check button so that error will be disappear

image

Next select the “initialisation” tab and do the settings as shown below

image

Select


FTM clock source = system clock

Clock source prescaler = 128

PWM channel initialisation:

Check box the channel no:7 and assign the pin for that channel


As we know from schematic Green LED is connected to PTA-2 / FTM channel-7 hence we will be choosing this option from pop down

Now we have completed all the hardware settings for the FTM module we will generate the code for this by clicking on the ‘generate ’ button

image

Build your project by choosing the right toolbar shortcut 

image

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

image

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 able to see the Green LED blink with a 1Hz frequency

 

We will proceed further from here as our requirement is dimming the led i.e its brightness has to vary from 0 to 100% ,

Now we need to add some lines of code to perform this activity i.e we need to stop the running PWM and load its duty cycle value from 0 to 100% inside a while loop.

 

Below is line of code:


while(1){

 FTM_DRV_CounterStart(FSL_DIMING_LED,kCounting_FTM_UP, 0, 0xFFFF, false); //start the counter

//for Green led dimming assigned to channel-7 config-0
 Diming_LED_ChnConfig0.uFrequencyHZ = 1000;
 FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

                for(int i=100;i>=1;i--){
                     FTM_DRV_PwmStop(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);
                     Diming_LED_ChnConfig0.uDutyCyclePercent = i;
                     FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);
                      for(int x=0;x<=200000;x++){} // delay in between for the brightness to stay for a while
                     }

                for(int x=0;x<=1000000;x++){} // software delay to stay while after the brightness reaches to 100%

                for(int i=1;i<=100;i++){
                     FTM_DRV_PwmStop(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);
                     Diming_LED_ChnConfig0.uDutyCyclePercent = i;
                     FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);
                      for(int x=0;x<=200000;x++){}  // delay in between for the brightness to stay for a while
                     }

                for(int x=0;x<=2000000;x++){} // software delay to stay while after the brightness reaches to 100%

  }

 

Explanation of code:


FTM_DRV_CounterStart(FSL_DIMING_LED,kCounting_FTM_UP, 0, 0xFFFF, false);//start the counter

This will load the counter with all the required parameters and start the counter.


Diming_LED_ChnConfig0.uFrequencyHZ = 1000;

This API changes the PWM running frequency to 1kHz


FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

this will start the channel-7 PWM

        

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

                     FTM_DRV_PwmStop(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

                     Diming_LED_ChnConfig0.uDutyCyclePercent = i;

                     FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

                                               for(int x=0;x<=200000;x++){} // delay in between for the brightness to stay for a while

                     }


The above loop will stop the pwm and loads the duty cycle value from 0 to 100 % (raising brightness) through the variable ‘i’ and starts the channel-7th PWM which is connected to Green Led, there is some software delay for the brightness to stay.


This process is carried out for lowering the brightness of LED by loading the duty cycle value from 100 to 0 %


               for(int i=1;i<=100;i++){

                     FTM_DRV_PwmStop(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

                     Diming_LED_ChnConfig0.uDutyCyclePercent = i;

                     FTM_DRV_PwmStart(FSL_DIMING_LED,&Diming_LED_ChnConfig0,7U);

                                               for(int x=0;x<=200000;x++){}  // delay in between for the brightness to stay for a while

                     }

Now, save the main.c file and build again as shown below:

image

image

After building, execute the project by launching the Debug configuration as shown:

image

As we had configured earlier the debug configuration settings for P&E micro device driver

Click on the resume button to start the execution

image

You can see the execution as shown in 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 binaries for quick reference and evaluation.


image

Attachments:
FRDM-K22 dimming using FTM.rar
FRDM-K22 dimming using FTM-bin.rar
  • Sign in to reply
  • DAB
    DAB over 7 years ago

    Nice detailed post.

     

    DAB

    • 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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube