Rainbow color using FTM PWM with KSDK 1.3

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Rainbow color using FTM PWM with KSDK 1.3

Rainbow color using FTM PWM with KSDK 1.3

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(); }

127378_127378.pngrgb.png

 

  • 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

  1. extract ftm_rainbow.zip to C:\Freescale\KSDK_1.3.0\examples\frdmk22f\driver_examples
  2. Go to KDS, import file

127754_127754.pngKDS.png

and choose .wsd file

127755_127755.pngKDS_2.png

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

127756_127756.pngKDS_3.png

 

127907_127907.JPGIMG_4157.JPG

 

I hope you will enjoy the demo

 

Iva

标签 (1)
附件
无评分
版本历史
最后更新:
‎09-10-2020 01:50 AM
更新人: