PWM RGB control on FRDM-K64F, KDS 2.0, KDSK 1.1.0, PEx

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

PWM RGB control on FRDM-K64F, KDS 2.0, KDSK 1.1.0, PEx

Jump to solution
2,134 Views
michaellyons
NXP Employee
NXP Employee

Hi,

I'm trying to control the RGB LEDs on the FRDM-K64F with PWM.  I have successfully faded the LEDs using the PWM LDD (without using KDSK), but when I start a project with KDSK and PEx the PWM LDD option goes away.  I believe I'm supposed to use the fsl_ftm module but I have had no luck using that to PWM my on board RGBs (PTB21, PTB22, PTE26).  If anyone could help me configure the module I would very much appreciate the help!


Thanks,
Michael

Labels (1)
Tags (5)
1 Solution
1,029 Views
alexeyusoltsev
Contributor IV

Hi Michael,

If you have configured FTM-ini you can immediately use PWM-no need any other components of PE to use PWM. As i understand it is the lowest level to control FTM in PE so i have chosen it for myselth. How to use PDD with FTM is described here: How to use PDD macros in CW V10.4 step by step  . In KDS usage is the same. Use FTM_PDD_WriteChannelValueReg(.....) to control duty cycle.(got 3 parameters)

As consern PIT steps are the following:

->configure timer perriod

->Enable interrupt and do increment of i in it.

->create iteration variablein interrupt. Let's call it uint8_t i.

->iterrate it each interrupt

->Set and Clear your led on definite levels of i-value.

for example:

void PIT_Oninterrupt(void)

{

     static uint8_t=0;          //has to be static to be created only once

     i++;

     if(i==0) red_SetVal();  

     if(i=150) red_ClrVal();

}

so you get period of 256. And duty cycle is 150/(256-150). If you have a lot of action on comparison(not a simple toggling pins) it is better to put it in the main loop to not be stalled in interraotion routine.

Best regards,

Alexey.

View solution in original post

0 Kudos
5 Replies
1,029 Views
mjbcswitzerland
Specialist V

Hi Michael

The Ports connected to the RGB LED on the FRDM-K64F have not FlexTimer output function and so can't be controlled by PWM and FlexTimer.

How did you manage to fade them? Was it using a timer and interrpt that was 'simulating' PWM in software?

The links below otherwise include all such support for the FRDM-K64F

Regards

Mark

Kinetis: µTasker Kinetis support

K64: µTasker Kinetis FRDM-K64F support / µTasker Kinetis TWR-K64F120M support

PWM: http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF

Hardware Timers: http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF

For the complete "out-of-the-box" Kinetis experience and faster time to market

1,029 Views
michaellyons
NXP Employee
NXP Employee

Looking back at my other code, I did simulate the pwm using the interrupt.  I wonder why the LEDs aren't routed to PWM outputs like they are on my other FRDM boards...  I'm still having trouble using the interrupts and the fsl_ftm though.  I will try some more tweaking but if you could help me set up the fsl_ftm that would be great.  Thanks for you help!

0 Kudos
1,029 Views
alexeyusoltsev
Contributor IV

Hi Michael,

You can try download and import my PE FTM-ini component. It is not generating interrupt but toggles A1 leg(propper functioning checked by oscilloscope).

Fings for you to check:

clock gate ->enable

clock source->togle it. In my case default clock source did not start FTM until i toggled it couple times.

modulo counter-> pass a value there. On that step you have to see period.(it shows in the next next string)

Next your step is to enable the chanal you are planing to use and set in "Initialisation" sub-menu propper punkts.

But for your purpose i would reccomend to use PIT-much simplier to use and is created for such a purpose.

Good luck man!

Best regards,Alexey.

1,029 Views
michaellyons
NXP Employee
NXP Employee

Alexey,

Thanks for the link.  So, if I understand what you're saying correctly, you must configure the FTM-ini before the fsl_ftm component? or is the fsl_ftm not needed?  I'm sorry, I read the PEx user guide but I'm still very new to it.  Also, I am able to blink the RGBs with the PIT but how can I use that as a PWM?  Is there a PWM setting in the PIT or do I set up two PITs and change the delay on one to create an adjustable duty cycle?


Thanks,
Michael

0 Kudos
1,030 Views
alexeyusoltsev
Contributor IV

Hi Michael,

If you have configured FTM-ini you can immediately use PWM-no need any other components of PE to use PWM. As i understand it is the lowest level to control FTM in PE so i have chosen it for myselth. How to use PDD with FTM is described here: How to use PDD macros in CW V10.4 step by step  . In KDS usage is the same. Use FTM_PDD_WriteChannelValueReg(.....) to control duty cycle.(got 3 parameters)

As consern PIT steps are the following:

->configure timer perriod

->Enable interrupt and do increment of i in it.

->create iteration variablein interrupt. Let's call it uint8_t i.

->iterrate it each interrupt

->Set and Clear your led on definite levels of i-value.

for example:

void PIT_Oninterrupt(void)

{

     static uint8_t=0;          //has to be static to be created only once

     i++;

     if(i==0) red_SetVal();  

     if(i=150) red_ClrVal();

}

so you get period of 256. And duty cycle is 150/(256-150). If you have a lot of action on comparison(not a simple toggling pins) it is better to put it in the main loop to not be stalled in interraotion routine.

Best regards,

Alexey.

0 Kudos