Hi Evgeny
To configure a PWM output at 1kHz (1ms clocking rate for another FTM) I do (from http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF)
PWM_INTERRUPT_SETUP pwm_setup;
pwm_setup.int_type = PWM_INTERRUPT;
pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16 | PWM_EDGE_ALIGNED); // clock PWM timer from the system clock with /16 pre-scaler
pwm_setup.int_handler = 0; // no user interrupt call-back on PWM cycle
pwm_setup.pwm_frequency = PWM_FREQUENCY(1000, 16); // generate 1kHz on PWM output
pwm_setup.pwm_value = _PWM_PERCENT(50, pwm_setup.pwm_frequency); // 50% PWM (high/low)
pwm_setup.pwm_reference = (_TIMER_0 | 3); // timer module 0, channel 3
fnConfigureInterrupt((void *)&pwm_setup);
This essentially does
- powers up the FTM
- set FTM_SCS to FTM_CSC_MS_ELS_PWM_LOW_TRUE_PULSES
- sets the period to FTM_MOD (the rate of 1ms)
- sets FTM_CV for the channel to 50% (half the FTM_MOD value)
- starts the FTM withot interrupt with teh defined prescaler value
It also configures the output pin (eg. on PTA6) using
_CONFIG_PERIPHERAL(A, 6, (PA_6_FTM0_CH3 | (PORT_SRE_FAST | PORT_DSE_HIGH))); // FTM0_CH3 on PA.6 (alt. function 3)
The other FTM needs to be set up to use a FTM clock input pin, connected to this output.
I do it with
pwm_setup.pwm_mode = (PWM_EXTERNAL_CLK | PWM_PRESCALER_1 | PWM_NO_OUTPUT);
pwm_setup.pwm_frequency = 0xffff;
pwm_setup.pwm_reference = (_TIMER_1 | 0); // timer module 1, channel 0
fnConfigureInterrupt((void *)&pwm_setup);
to get the second one counting from it (it must use a different FTM)
which then also configures the clock input cnnection (which depends on the exact Kinetis part since they are not all the same in this respect - some have 2 pins that can be used by all timers and some have dedicated pins for each timer).
You can get full code reference from the uTasker Open Source project to get some ideas or just use the entire project to quickly complete your development.
Regards
Mark