Hi all,
there is a simple modification of ftm driver example based on KSDK 1.3, KDS 3.0 on FRDM-K22F.
- enabling clocks for PORTs in hardware_init.c
void hardware_init(void) { /* enable clock for PORTs */ CLOCK_SYS_EnablePortClock(PORTA_IDX); CLOCK_SYS_EnablePortClock(PORTD_IDX); CLOCK_SYS_EnablePortClock(PORTE_IDX); PORT_HAL_SetMuxMode(PORTA,1u,kPortMuxAlt3);//red PORT_HAL_SetMuxMode(PORTA,2u,kPortMuxAlt3);//green PORT_HAL_SetMuxMode(PORTD,5u,kPortMuxAlt4);//blue /* Init board clock */ BOARD_ClockInit(); dbg_uart_init(); }


- setting ftm parameters for red, green and blue color, for red color:
ftm_pwm_param_t ftmParamR = { .mode = kFtmEdgeAlignedPWM, .edgeMode = kFtmLowTrue, .uFrequencyHZ = 24000u, .uDutyCyclePercent = 0, .uFirstEdgeDelayPercent = 0, };
- setting PWM output for each color in infinite loop
FTM_DRV_PwmStart(BOARD_FTM_INSTANCE, &ftmParamR, 6); FTM_DRV_PwmStart(BOARD_FTM_INSTANCE, &ftmParamG, 7); FTM_DRV_PwmStart(BOARD_FTM_INSTANCE, &ftmParamB, 5);
- forwarding parameters to hsv2rgb()
hsv2rgb(hue,255,255,&red,&green,&blue,255);
- changing hue and checking overflow of hue
hue++; if(hue>=360)hue=0;
- normalizing from 0-255 to 0-100 percent of PWM pulse width for each color
ftmParamR.uDutyCyclePercent = (uint8_t)(((float)red/255.0)*100.0); ftmParamG.uDutyCyclePercent = (uint8_t)(((float)green/255.0)*100.0); ftmParamB.uDutyCyclePercent = (uint8_t)(((float)blue/255.0)*100.0);
That´s all!
Importing example
- extract ftm_rainbow.zip to C:\Freescale\KSDK_1.3.0\examples\frdmk22f\driver_examples
- Go to KDS, import file


and choose .wsd file


After then don´t forget compile library first and then project.




I hope you will enjoy the demo
Iva