Toggling Pin on Kinetis Using a Timer Output

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggling Pin on Kinetis Using a Timer Output

Toggling Pin on Kinetis Using a Timer Output

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.
Comments

Please help us improve our tools and participate on Freescale Processor Expert Survey .

Thank you!

%3CLINGO-SUB%20id%3D%22lingo-sub-1108645%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EToggling%20Pin%20on%20Kinetis%20Using%20a%20Timer%20Output%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1108645%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EThis%20tutorial%20will%20show%20step-by-step%20how%20to%20create%20a%20simple%20Processor%20Expert%20project%20that%20periodically%20toggles%20an%20output%20pin%20using%20a%20timer%20output%20without%20writing%20a%20single%20line%20of%20code.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EThe%20FRDM-KL25%20board%20is%20used%20with%20one%20of%20the%20LEDs%20(blue)%20connected%20to%20the%20Timer%2FPWM%20Module%200%20(%3CSTRONG%3ETPM0%3C%2FSTRONG%3E)%2C%20channel%201.%3C%2FSPAN%3E%3C%2FP%3E%3CH2%20id%3D%22toc-hId--1416222161%22%20id%3D%22toc-hId--498479657%22%3E%3C%2FH2%3E%3CP%3E%3C%2FP%3E%3CH2%20id%3D%22toc-hId-1071290672%22%20id%3D%22toc-hId-1989033176%22%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%22%3ETimer%20Operation%20Description%3C%2FSPAN%3E%3C%2FH2%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%22%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EThe%20Timer%2FPWM%20Module%200%20(TPM0)%20provides%20(besides%20other%20features)%20a%20counter%20with%20variable%20period%20(modulo)%2C%20compare%20register%20an%20output%20pin%20suitable%20for%20the%20goal%20of%20periodic%20toggling.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3EThe%20counter%20will%20be%20configured%20to%20continuously%20run%20in%20modulo%20range%20with%20a%20300ms%20period%2C%20the%20output%20will%20be%20set%20when%20counter%20reaches%20the%20compare%20register%20value%20(150ms)%20and%20cleared%20when%20the%20counter%20resets.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EThe%20following%20picture%20describes%20the%20operation%3A%3C%2FSPAN%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2214.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2214.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40673i4A7E63E2FDE646F2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%2214.png%22%20alt%3D%2214.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CH2%20id%3D%22toc-hId--736163791%22%20id%3D%22toc-hId-181578713%22%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%22%3ECreating%20the%20Project%3C%2FSPAN%3E%3C%2FH2%3E%3CP%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EFirst%2C%20create%20a%20new%20project%20with%20Processor%20Expert%20for%20KL25%20configured%20as%20described%20in%20the%20tutorial%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fdocs%2FDOC-95535%22%20target%3D%22_blank%22%3ECreating%20Processor%20Expert%20Project%20for%20FRDM-KL25%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3ESwitch%20to%20Components%20Library%20view%20and%20its%20Categories%20tab%20and%20add%20the%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3E%3CSTRONG%3ETimerUnit_LDD%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3E%20component%20from%20the%20category%20%3CEM%3ELogical%20Device%20Drivers%20%2F%20Timer%3C%2FEM%3E%20by%20double-clicking%20on%20it%20or%20selecting%20pop-up%20menu%20command%20%E2%80%98%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%20font-style%3A%20italic%3B%22%3EAdd%20to%20project%E2%80%99.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2210.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2210.png%22%20style%3D%22width%3A%20244px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40676i30B8CE00E4DA511F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%2210.png%22%20alt%3D%2210.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22color%3A%20black%3B%20font-size%3A%2010pt%3B%20font-family%3A%20Arial%3B%22%3EThe%20component%20appears%20in%20the%20Components%20view%3A%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2211.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2211.png%22%20style%3D%22width%3A%20551px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40647iBDE76584EB7929B0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%2211.png%22%20alt%3D%2211.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3EUse%20the%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%20font-weight%3A%20bold%3B%22%3ERename%20component%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3Ecommand%20from%20the%20TU1%E2%80%99s%20context%20menu%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3E%20and%20change%20the%20name%20to%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%20font-weight%3A%20bold%3B%22%3EBlueLED%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Arial%3B%20color%3A%20black%3B%22%3E.%3C%2FSPAN%3E%20%3A%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2212.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2212.png%22%20style%3D%22width%3A%20252px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40648iDDB151BFB2F9C651%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%2212.png%22%20alt%3D%2212.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3EDouble%20click%20the%20component%20to%20open%20it%20in%20the%20inspector%20and%20configure%20the%20properties%20according%20to%20the%20following%20picture%3A%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22AAA.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22AAA.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40672i906C64996105E92E%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AAA.png%22%20alt%3D%22AAA.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3EInvoke%20code%20generation%20by%20clicking%20on%20the%20Generate%20Processor%20Expert%20Code%20button%20in%20the%20Components%20view%20of%20the%20project%3A%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22BBB.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22BBB.png%22%20style%3D%22width%3A%20370px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40671iE48D387E8217E292%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22BBB.png%22%20alt%3D%22BBB.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3EThe%20generated%20code%20is%20present%20in%20the%20%3CEM%3EGenerated_Code%3C%2FEM%3E%20folder%20of%20the%20project%3A%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2215.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%2215.png%22%20style%3D%22width%3A%20231px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40652iED62FB65367EAFEB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%2215.png%22%20alt%3D%2215.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CEM%3ENote%3A%20The%20generated%20code%20contains%20automatic%20initialization%20provided%20by%20Processor%20Expert%20%3CSPAN%20style%3D%22color%3A%20%23000000%3B%22%3E%3CEM%3Econfiguring%20all%20needed%20registers%2C%20%3C%2FEM%3E%3C%2FSPAN%3Eso%20it's%20not%20necessary%20to%20write%20any%20user%20code.%20%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3EBuild%20the%20project%20using%20the%20%3CSTRONG%3EProject%20%2F%20Build%20All.%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%20color%3A%20%23000000%3B%22%3EAfter%20the%20successful%20build%2C%20you%20can%20connect%20the%20FRDM-KL25%20board%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20line-height%3A%201.5em%3B%20color%3A%20%23000000%3B%22%3Eand%20run%20the%20application%20by%20clicking%20the%20%22Debug%22%20icon%20and%20after%20the%20code%20gets%20loaded%20into%20the%20board%20the%20%22Resume%22%20button.%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2010pt%3B%20color%3A%20%23000000%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22ccc.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22ccc.png%22%20style%3D%22width%3A%20775px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F40670iA7B0372B4C91CDF9%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22ccc.png%22%20alt%3D%22ccc.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%20style%3D%22color%3A%20%23000000%3B%20font-size%3A%2010pt%3B%22%3EThe%20LED%20should%20start%20periodically%20blinking%20with%20blue%20color.%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1108646%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Toggling%20Pin%20on%20Kinetis%20Using%20a%20Timer%20Output%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1108646%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3EPlease%20help%20us%20improve%20our%20tools%20and%20participate%20on%3CA%20class%3D%22jive-link-external-small%22%20data-content-finding%3D%22Community%22%20href%3D%22https%3A%2F%2Fwww.surveymonkey.com%2Fs%2FBFTRTCQ%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Freescale%20Processor%20Expert%20Survey%20%3C%2FA%3E.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
No ratings
Version history
Last update:
‎08-30-2013 06:50 AM
Updated by: