TWR-K65 FTM PWM Example

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

TWR-K65 FTM PWM Example

1,510 Views
daviddugan
Contributor II

I am attempting to run a PWM example on a TWR-K65. 

 

  In the "FTM - Two Channel PWM" driver example .C file (attached) you will notice:

 

#define BOARD_FTM_BASEADDR FTM2

#define BOARD_FIRST_FTM_CHANNEL 0U

#define BOARD_SECOND_FTM_CHANNEL 1U

 

I assume the is defining the Flex Time Module for the example to be FTM 2, and the two channels that will output the PWM will be FTM2 CH0 and FTM2 CH1.

 

The TWR-K65 schematic (attached) shows no available connections to FTM2 CH0 or CH1.  So I changed this line of code to:

 

#define BOARD_FTM_BASEADDR FTM0

#define BOARD_FIRST_FTM_CHANNEL 4U

#define BOARD_SECOND_FTM_CHANNEL 5U

 

I thought this would output a PWM signal on FTM0 CH4 and CH5, which according to the TWR-K65 schematic (sheet 8), are hooked up to B39 and B40.

 

When I run the example I get no pulses on those pins.

 

Could some one please tell me what I am doing wrong?

Original Attachment has been moved to: ftm_pwm_twochannel.c.zip

Labels (1)
0 Kudos
4 Replies

1,059 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, David,

Regarding your question that you can not see the PWM signals from FTM0_CH4 and FTM0_CH5, do you have the code to set the pin assignment?

for the example, the FTM0_CH4/FTM0_CH5 are multiplexed with PTD4 and PTD5 for K66, you have to set the PTD4/5 as the FTM function with the code:

    CLOCK_EnableClock(kCLOCK_PortD);

    /* Affects PORTD_PCR4 register */

    PORT_SetPinMux(PORTD, 4U, kkPORT_MuxAlt4);

    /* Affects PORTD_PCR5 register */

    PORT_SetPinMux(PORTD, 5U, kPORT_MuxAlt4);

Pls have a try for the above code. If you have done the setting, pls update the ticket, I will download the code and have a try.

BR

Xiangjun Rong

1,059 Views
daviddugan
Contributor II

Am I able to load the TWR-K65 configuration into the Pin Tool?  I think this would be very helpful. 

If this is possible could someone please show me how.

Thanks!

-Dave

0 Kudos

1,059 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Dave,

You are right, the resistor R96 and R98 are not populated, DNP means "Do Not Populated", so you can not see the FTM signal on B39 and B40 pins. But the PTD4 and PTD5 are also routed to pin A78 and A79, you can observe the FTM0_CH4 and FTM0_CH5 PWM signals on A78 and A79 pins on primary elevator board.

I have run the code pasted on TWR-K65F180M board, I can see the PWM signals on the two pins.

I attach the main.c, running the code, I can see the two PWM signals on the two pins.

Hope it can help you.

BR

Xiangjun Rong

#include "fsl_debug_console.h"

#include "board.h"

#include "fsl_ftm.h"

#include "fsl_device_registers.h"

#include "pin_mux.h"

#include <stdbool.h>

#include "clock_config.h"

#include "fsl_port.h"

/*******************************************************************************

* Definitions

******************************************************************************/

#define BOARD_FTM_BASEADDR FTM0

#define BOARD_FIRST_FTM_CHANNEL 0U

#define BOARD_SECOND_FTM_CHANNEL 1U

#define BOARD_FTM_CHANNEL4 4U

#define BOARD_FTM_CHANNEL5 5U

/* Get source clock for FTM driver */

#define FTM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)

/*******************************************************************************

* Prototypes

******************************************************************************/

/*!

* @brief delay a while.

*/

void delay(void);

void pinAssignment(void);

/*******************************************************************************

* Variables

******************************************************************************/

/*******************************************************************************

* Code

******************************************************************************/

void delay(void)

{

    volatile uint32_t i = 0U;

    for (i = 0U; i < 800000U; ++i)

    {

        __asm("NOP"); /* delay */

    }

}

/*!

* @brief Main function

*/

int main(void)

{

    bool brightnessUp = true; /* Indicate LEDs are brighter or dimmer */

    ftm_config_t ftmInfo;

    uint8_t updatedDutycycle = 0U;

    ftm_chnl_pwm_signal_param_t ftmParam[2];

    /* Configure ftm params with frequency 24kHZ */

    ftmParam[0].chnlNumber = (ftm_chnl_t)BOARD_FTM_CHANNEL4;  //BOARD_FIRST_FTM_CHANNEL;

    ftmParam[0].level = kFTM_LowTrue;

    ftmParam[0].dutyCyclePercent = 0U;

    ftmParam[0].firstEdgeDelayPercent = 0U;

    ftmParam[1].chnlNumber = (ftm_chnl_t)BOARD_FTM_CHANNEL5;  //BOARD_SECOND_FTM_CHANNEL;

    ftmParam[1].level = kFTM_LowTrue;

    ftmParam[1].dutyCyclePercent = 0U;

    ftmParam[1].firstEdgeDelayPercent = 0U;

    /* Board pin, clock, debug console init */

    BOARD_InitPins();

    BOARD_BootClockRUN();

    BOARD_InitDebugConsole();

    pinAssignment();

    /* Print a note to terminal */

    PRINTF("\r\nFTM example to output PWM on 2 channels\r\n");

    PRINTF("\r\nYou will see a change in LED brightness if an LED is connected to the FTM pin");

    PRINTF("\r\nIf no LED is connected to the FTM pin, then probe the signal using an oscilloscope");

    /*

     * ftmInfo.prescale = kFTM_Prescale_Divide_1;

     * ftmInfo.bdmMode = kFTM_BdmMode_0;

     * ftmInfo.pwmSyncMode = kFTM_SoftwareTrigger;

     * ftmInfo.reloadPoints = 0;

     * ftmInfo.faultMode = kFTM_Fault_Disable;

     * ftmInfo.faultFilterValue = 0;

     * ftmInfo.deadTimePrescale = kFTM_Deadtime_Prescale_1;

     * ftmInfo.deadTimeValue = 0;

     * ftmInfo.extTriggers = 0;

     * ftmInfo.chnlInitState = 0;

     * ftmInfo.chnlPolarity = 0;

     * ftmInfo.useGlobalTimeBase = false;

     */

    FTM_GetDefaultConfig(&ftmInfo);

    /* Initialize FTM module */

    FTM_Init(BOARD_FTM_BASEADDR, &ftmInfo);

    FTM_SetupPwm(BOARD_FTM_BASEADDR, ftmParam, 2U, kFTM_EdgeAlignedPwm, 24000U, FTM_SOURCE_CLOCK);

    FTM_StartTimer(BOARD_FTM_BASEADDR, kFTM_SystemClock);

    while (1)

    {

        /* Delay to see the change of LEDs brightness */

        delay();

        if (brightnessUp)

        {

            /* Increase duty cycle until it reach limited value */

            if (++updatedDutycycle == 100U)

            {

                brightnessUp = false;

            }

        }

        else

        {

            /* Decrease duty cycle until it reach limited value */

            if (--updatedDutycycle == 0U)

            {

                brightnessUp = true;

            }

        }

        /* Start PWM mode with updated duty cycle */

        FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, (ftm_chnl_t)BOARD_FTM_CHANNEL4, kFTM_EdgeAlignedPwm,

                               updatedDutycycle);

        FTM_UpdatePwmDutycycle(BOARD_FTM_BASEADDR, (ftm_chnl_t)BOARD_FTM_CHANNEL5, kFTM_EdgeAlignedPwm,

                               updatedDutycycle);

        /* Software trigger to update registers */

        FTM_SetSoftwareTrigger(BOARD_FTM_BASEADDR, true);

    }

}

void pinAssignment(void)

{

    CLOCK_EnableClock(kCLOCK_PortD);

      /* Affects PORTD_PCR4 register */

    PORT_SetPinMux(PORTD, 4U, kPORT_MuxAlt4);

    /* Affects PORTD_PCR5 register */

    PORT_SetPinMux(PORTD, 5U, kPORT_MuxAlt4);

}

0 Kudos

1,059 Views
daviddugan
Contributor II

Thank you for your quick reply, unfortunately I've been very busy with another project and wasn't able to test your code until today.

I updated Pin_mux.c in my project with your instructions, and removed the driver's original code.

<code>

//////////////////////////////////////////////////

    //Original code from driver example

    /* Ungate the port clock */

    //CLOCK_EnableClock(kCLOCK_PortB);

    /* PTB18 FTM2 channel 0 */

    //PORT_SetPinMux(PORTB, 18U, kPORT_MuxAlt3);

    /* PTB19 FTM2 channel 1 */

    //PORT_SetPinMux(PORTB, 19U, kPORT_MuxAlt3);

///////////////////////////////////////////////////

    //Updated code from xiangjun.rong response on NXP forum

    /* Ungate the port clock */

    CLOCK_EnableClock(kCLOCK_PortD);

      /* Affects PORTD_PCR4 register */

    PORT_SetPinMux(PORTD, 4U, kPORT_MuxAlt4);

    /* Affects PORTD_PCR5 register */

    PORT_SetPinMux(PORTD, 5U, kPORT_MuxAlt4);

</code>

I still get no PWM signal at pin B40 and B39 where the FTM0 CH4 and CH5 are connected according to sheet 8 of the TWRK65 schematic attached in my previous post.

Upon further inspection of the schematic I noticed 0 ohm resistors before the B40 and B39 pins, (R98 and R96).  While I was not able to find R96 on the board, I was able to find where R98 was labeled on the board.  There was no resistor, I went back to the schematic and noticed a "DNP" (do not populate) note.

I put my scope on both sides of that pad and saw no signal.

THEN my electrical engineer was kind enough to point out that PTD4 was hooked up to the TWRK65 Flex Bus for the memory module... So.... This was a poor choice for my example. 

I will re-evaluate, and respond when I get the project working.  xiangjunrong​, thank you for your suggestion, while it didn't get my project working, it was helpful in teaching me how to setup a board.

Thanks again,

-Dave

0 Kudos