FTM standalone timer

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

FTM standalone timer

2,343 Views
vigneshbalaji
Senior Contributor I

Hi,

    I need an exampe for FTM as a standalone timer.

10 Replies

1,871 Views
pascalschröer
Contributor V

Vignesh,

try this part of code:

void FTM0_init()

{

     FTM0_SC = 0x00;

     FTM0_CNTIN = FTM_CNTIN_INIT(0);

     FTM0_MOD = FTM_MOD_MOD("your value"); //your value should be smaller than 65535! 

     FTM0_SC = FTM_SC_CLKS(0x01) | FTM_SC_PS(0);

}

If you need more support, please give us more input :smileywink:

Pascal

1,871 Views
vigneshbalaji
Senior Contributor I

Hi pascal,

               I want to understand about clocks I. FTM timer and how the clock affects the timer.Can you provide me a calculation for the each FTM count based on clocks?

0 Kudos
Reply

1,871 Views
pascalschröer
Contributor V

Hi,

especially for the FTM I calculated the specific modv and prescaler values for my bachelor thesis like this:

NOTE: period_us is the suggested timer period in us!

      CORE_PERIOD_NS is the period time of your system clock in ns!

/* This routine calculates the modv value in combination with

  * a suitable prescaler. If there is no suitable prescaler =>

  * the value is too tall and an error code will be set

  * Calculation: Register Value = period_us / CORE_PERIOD

  * us/ns = 1*10^-3 => pow(10,3) */

  modv = (period_us/CORE_PERIOD_NS)*pow(10,3);

  /* In the FTM0_MOD register are only 16bits available => 65535 */

  while((period_us/CORE_PERIOD_NS)*pow(10,3)>65535)

  {

       /* The value 7 is the tallest available prescaler (see datasheet) */ 

       if(prescaler>7)

       {

            program_error(PROGRAM_ERROR_ftm);

            break;

       }

       prescaler++;

       /* Every prescaler multiplies the time with factor 2 => time value /= 2 */

       modv /= 2;

       /* modv /= 2 accords with period_us (see the calculation in the while loop) */

       period_us /= 2;

  }

So your timer period depends on your selected clock, your clock frequency the modv value and your selected prescaler!

Cheers,

Pascal

1,871 Views
vigneshbalaji
Senior Contributor I

Hi pascal,

               I want to know about the core period?How do I find it out?I am using KEA-128

0 Kudos
Reply

1,871 Views
pascalschröer
Contributor V

Have a look:

Bildschirmfoto 2016-01-15 um 20.28.37.png

Bildschirmfoto 2016-01-15 um 20.28.59.png

Bildschirmfoto 2016-01-15 um 20.29.06.png

First step of starting an embedded system is to initialize your clocks!

Cheers,

Pascal

0 Kudos
Reply

1,870 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, all,

Regarding the FTM driving clock, it is dependent on the FTM  clock source and prescaler, in other words, the FTM driving clock frequency equals to (FTM clock source frequency)/Prescaler.

The CLKS bits in FTM_SC register determines the FTM clock source for KEA128 chip:

CLKS bits                        clock source                        

00                                   FTM disabled

01                                  system clock source   

10                                  Fixed frequency clock

11                                  External clock source

Pls refer to Figure 5-3. FTM and PWT clock generation in the KEA128RM.pdf for the detailed FTM clock source.

When the CLKS=01, the system clock source is selected, in the condition, the ICSOUTCLK clock source divided by DIV3 is used as FTM clock source, DIV3 bits is specified in SIM_CLKDIV. Pls refer to the Figure 5-1. Clocking diagram in KEA128RM.pdf.

when the CLKS=10, the ICSFFCLK clcok source is selected as FTM clock source, ICSFFCLK clock source is 37.5KHz IRC or (external OSC)/RDIV, pls refer to Figure 5-1. Clocking diagram.

when the CLKS=11, the FTM clcok source are from TCLK0/TCLK1/TCLK2 pins, SIM_PINSEL0[FTM0CLKPS] select the clock source pins from the three pins. Note TCLK0/TCLK1/TCLK2 are Kea128 external signal pads, for example:

This is the pin assignment of TCLK0 pin.

79(79 LQFP) 63(63 LQFP) PTA5, RESET_b, PTA5 KBI0_P5, IRQ, TCLK0, RESET_b

In otherwords, you can connect the external clock source to the TCLK0 pin, the FTM driving clock frequency will be (TCLK0 Pin clock frequency)/Prescaler, the prescaler is defined in the FTM_SC register.

Note you should enable the FTM  gate clock by setting the corresponding bit in SIM_SCGC register when you use CLKS=01 setting..

BR

Xiangjun Rong

0 Kudos
Reply

1,870 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, all,

Pls refer to an5142 for the FTM features and corresponding code, but you have to add the code to select the FTM clock source based on KEA128RM.

Pls go to the website and download "features of FlexTimer Module"

K40_100 |Kinetis K40 100 MHz MCUs|NXP

BR

Xiangjun Rong

0 Kudos
Reply

1,870 Views
vigneshbalaji
Senior Contributor I

Hi,

I need to run the clock of my KEA-128 at 24 Mhz.I am finding

difficulty in setting the ICS_C1 register in it.Can you provide me any

example for it?

On Sat, Jan 16, 2016 at 1:03 AM, pascalschröer <

0 Kudos
Reply

1,870 Views
pascalschröer
Contributor V

Maybe it's more easier to say:

Your modv value (modification value) is calculated like this:

modv = period_time / system_clock_period

If your modv value is too large (<65535), you can use a prescaler. Every prescaler level divides your modv value by 2.

Cheers,

Pascal

1,870 Views
vigneshbalaji
Senior Contributor I

Hi Can you give me more clarity on period time and system clock

0 Kudos
Reply