Toggling Pin on Kinetis Using a Timer Output

Document created by Petr_H Employee on Aug 30, 2013
Version 1Show Document
  • View in full screen mode

This tutorial will show step-by-step how to create a simple Processor Expert project that periodically toggles an output pin using a timer output without writing a single line of code.

The FRDM-KL25 board is used with one of the LEDs (blue) connected to the Timer/PWM Module 0 (TPM0), channel 1.

 

Timer Operation Description


The Timer/PWM Module 0 (TPM0) provides (besides other features) a counter with variable period (modulo), compare register an output pin suitable for the goal of periodic toggling.

The counter will be configured to continuously run in modulo range with a 300ms period, the output will be set when counter reaches the compare register value (150ms) and cleared when the counter resets.

The following picture describes the operation:

14.png

Creating the Project

 

  • First, create a new project with Processor Expert for KL25 configured as described in the tutorial Creating Processor Expert Project for FRDM-KL25
  • Switch to Components Library view and its Categories tab and add the TimerUnit_LDD component from the category Logical Device Drivers / Timer by double-clicking on it or selecting pop-up menu command ‘Add to project’.

10.png

  • The component appears in the Components view:

11.png

 

  • Use the Rename component command from the TU1’s context menu and change the name to BlueLED. :

12.png

 

  • Double click the component to open it in the inspector and configure the properties according to the following picture:

AAA.png

  • Invoke code generation by clicking on the Generate Processor Expert Code button in the Components view of the project:

BBB.png

 

  • The generated code is present in the Generated_Code folder of the project:

15.png

Note: The generated code contains automatic initialization provided by Processor Expert configuring all needed registers, so it's not necessary to write any user code.


  • Build the project using the Project / Build All.
  • After the successful build, you can connect the FRDM-KL25 board and run the application by clicking the "Debug" icon and after the code gets loaded into the board the "Resume" button.

ccc.png

  • The LED should start periodically blinking with blue color.

Attachments

    Outcomes