Having trouble with PWM using FRDM-K64F+KDS 2.0+KSDK 1.1+PEx

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

Having trouble with PWM using FRDM-K64F+KDS 2.0+KSDK 1.1+PEx

Jump to solution
3,749 Views
dave408
Senior Contributor II

I have been struggling all day so far trying to get PWM to work on my FRDM-K64F.  I am using a FRDM-K64F with KDS 2.0 and KSDK 1.1.  My initial attempts at following app notes and adding the PWM code to my application failed, so I decided to create a new project from scratch and add PEx support to it.

 

All of the examples I see online make references to a PWM PEx component.  I don't have such a component in my list, but I do have Init_FTM.  I figured that this should also suffice.

 

I have set all of the properties for this component to try to get PWM working, but so far I have been unsuccessful.  I have tried all different combinations of settings that make sense (to me), but in the end, my PWM pins (PTC10 and PTC11) just go high and stay high when I run my application.

 

Here are settings that I thought would work:

 

21328_21328.pngpastedImage_0.png

 

 

21330_21330.pngpastedImage_2.png

 

21331_21331.pngpastedImage_3.png

 

Hopefully I'm doing something silly that someone will be able to point out and explain.  Any comments would be really appreciated!

Labels (1)
0 Kudos
1 Solution
1,289 Views
dave408
Senior Contributor II

I'm glad I found this post from yesterday:

fsl_ftm bug on 100Hz?

Apparently, fsl_ftm only supports one PWM channel.  It would be really nice if the PEx developers would either put this in the GUI if they *know* that it will only support one channel, so devs using the tool aren't wasting time wondering why a feature that should work, isn't.

View solution in original post

0 Kudos
9 Replies
1,289 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Dave,

there are no actual guides for KDS 2.0, KSDK 1.1.0 and PEx together.

I can recommend you start with my easy guide for LED blinking with PWM.

How to toggle LED in KDS 2.0 with KSDK 1.1.0 and Processor Expert

But I´ll test on my side with FTM and tell you more.

I hope it helps you,

Best Regards,

Iva

0 Kudos
1,289 Views
dave408
Senior Contributor II

Hi Iva, thanks for your reply.  I have LEDs, ethernet, and UART currently working without PEx.  I couldn't get FTM figured out for PWM and QD, so I'm going to try PEx for those.

My current status is that with fsl_ftm, I have one PWM channel working, but not two.  I'll post more info on this later!  Thanks.

0 Kudos
1,290 Views
dave408
Senior Contributor II

I'm glad I found this post from yesterday:

fsl_ftm bug on 100Hz?

Apparently, fsl_ftm only supports one PWM channel.  It would be really nice if the PEx developers would either put this in the GUI if they *know* that it will only support one channel, so devs using the tool aren't wasting time wondering why a feature that should work, isn't.

0 Kudos
1,289 Views
dave408
Senior Contributor II

I have noticed that a lot of people are using fsl_* components (what is their significance in the Kinetis ecosystem?), and I also just noticed there's a fsl_ftm component in PEx.  I'm going to start playing with that component now to see what happens.

0 Kudos
1,289 Views
mjbcswitzerland
Specialist V

Hi Dave

Attached is a FRDM-K64F binary that you can load and then check register settings with the ones that PE gives you - and report any necessary corrections to the PE coders.

It generates 1kHz PWM on PTC10 and PTC11 (20% and 29.4%).

Personally I find PE useful for very first tests with a new module. It has a nice interface but doesn't always produce useful (or working) code and is much less efficient than using a decent library once you have a little experience. (My analogy: It is like a parking assistence built in to a car - useful if you are a learner/bad driver but once you are up to speed it just weighs you down).

I 'generate' the code in the uTasker project like this:

PWM_INTERRUPT_SETUP pwm_setup;

pwm_setup.int_type = PWM_INTERRUPT;

pwm_setup.pwm_mode = (PWM_SYS_CLK | PWM_PRESCALER_16); // clock PWM timer from the system clock with /16 prescaler

pwm_setup.pwm_reference = (_TIMER_3 | 6); // timer module 3, channel 6

pwm_setup.pwm_frequency = PWM_TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(1000), 16); // generate 1000Hz on PWM output

pwm_setup.pwm_value = _PWM_PERCENT(20, pwm_setup.pwm_frequency); // 20% PWM (high/low)

fnConfigureInterrupt((void *)&pwm_setup); // enter first PWM configuration

pwm_setup.pwm_reference = (_TIMER_3 | 7); // timer module 3, channel 7

pwm_setup.pwm_value  = _PWM_TENTH_PERCENT(706, pwm_setup.pwm_frequency); // 70.6% PWM (low/high) on different channel

fnConfigureInterrupt((void *)&pwm_setup); // enter second PWM configuration

To get the PWM outputs on the desired pins I define

#define FTM3_6_ON_C // FTM3 channel 6 on port C rather than port E

#define FTM3_7_ON_C // FTM3 channel 7 on port C rather than port E

As you can see - pretty low tech. But the fact is that after 5 minutes I have a complete tested/working project. (When I run the uTasker K64 simulator it also shows me that the pins are configured correctly which gives complete confidence and removes any quessing involved).

Apart from the channels/pin locations, the same code will work on any K, KE, KV or KL device (adapts itself for FlexTimer or TPM).

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

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

0 Kudos
1,289 Views
dave408
Senior Contributor II

Hi Mark, thank you for the example and your suggestions.  I'll give them a try!

By the way, how is uTasker's support of quadrature decoding in the FTM?

0 Kudos
1,289 Views
mjbcswitzerland
Specialist V

Dave

The FlexTimer interface allows PWM, periodic or monostable timer interrupt operation. It doesn't include QD at the moment but this can be taken from other setups as needed (it is low level code which can be taken from anywhere where it is known to work).

It does however include Ethernet and USB, low power and many other (interrupt and/or DMA driver) drivers so if I want to have Ethernet with Telnet, FTP and web server I can set:

#define ETH_INTERFACE

#define USE_TCP

#define USE_FTP

#define USE_HTTP

#define USE_TELNET

and it is ready to run; either operating from a file system in internal Flash or from an SD card.

I set #define FLASH_FAT rather than #define SDCARD_SUPPORT (for conventience, using the second half of internal Flash)

To add USB-MSD and USB-CDC composite device operation as well:

#define USE_INTERFACE

#define USE_USB_MSD

#define USE_USB_CDC

#define USB_CDC_COUNT  3 (optionally have 3 USB-CDC to UART bridges)

Doesn't look as pretty as PE but it works on all boards with the required peripheral(s) (no porting needed) and builds with many IDEs (CW, KDS, IAR, Keil, Atollic, Rowley Crossworks, Green Hills, CooCox, GCC and VisualStudio) so no restrictions on the tools.

I just build the configration as above and attached the resulting binary (again 5..10 minutes work to 'generate' and test the complete working project). You can attach the board to the PC USB host and it will appear as 512k hard driver (internal Flash) with 3 x virtual com ports (drivers for 32 and 64 bit Windows attached in case you really want to check it - needed due to the CDC). Format the disk, then create a directory called "web" and place "index.htm" there plus other web pages as desired.

The board is contactable on 192.168.0.3 as TELNET, FTP or web server - FTP and the web server will work with the hard drive content so the web pages can be loaded eiter via USB or via FTP.

There is a UART connection with menu shell on the OpenSDA virtual COM where all settings can be adjusted and save if they don't suit.

[There are variosus other stuff that was already enabled t0o, such as multicast IGMP, SNTP, SNMP so these will be operating and can be controlled in the Telnet or UART shell]

The 2 PWM outputs are still operating (but without QD ...;-( although I may add this at some time too).

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

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


0 Kudos
1,289 Views
dave408
Senior Contributor II

Mark, I have submitted an application for uTasker on your website and look forward to a response after you have a chance to evaluate our system requirements.

0 Kudos
1,289 Views
dave408
Senior Contributor II

Mark, I think I'll follow up with you on your uTasker forum.  We've communicated there in the past when I was first looking at uTasker for my application.  Thanks for all of your replies here!

0 Kudos