I want to run #FRDMKW41ZUG board with #MKW41Z mcu, using frdmkw41z_driver_examples_tpm_combine_pwm example with #deadtime insertion, but cannot run it well. I try to change filter register directly with no result.
You can see that no deadtime insertion.
Code from example:
#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_tpm.h"
#include "pin_mux.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* define instance */
#define BOARD_TPM_BASEADDR TPM2
/* TPM channel pair 0 works with TPM channels 0 and 1*/
#define BOARD_TPM_CHANNEL_PAIR kTPM_Chnl_0
/* Interrupt to enable and flag to read; depends on the TPM channel pair used */
//#define TPM_CHANNEL_INTERRUPT_ENABLE kTPM_Chnl0Interrupt
#define TPM_CHANNEL_FLAG kTPM_Chnl0Flag
/* Interrupt number and interrupt handler for the TPM instance used */
//#define TPM_INTERRUPT_NUMBER TPM2_IRQn
#define TPM_LED_HANDLER TPM2_IRQHandler
/* Get source clock for TPM driver */
#define TPM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_McgFllClk)
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
volatile bool brightnessUp = true; /* Indicate LED is brighter or dimmer */
volatile uint8_t updatedDutycycle = 10U;
volatile uint8_t getCharValue = 0U;
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main function
*/
int main(void)
{
tpm_config_t tpmInfo;
tpm_chnl_pwm_signal_param_t tpmParam;
tpm_pwm_level_select_t pwmLevel = kTPM_LowTrue;
uint8_t deadtimeValue;
uint32_t filterVal;
/* Configure tpm params with frequency 24kHZ */
tpmParam.chnlNumber = BOARD_TPM_CHANNEL_PAIR;
tpmParam.level = pwmLevel;
tpmParam.dutyCyclePercent = 35U;
tpmParam.firstEdgeDelayPercent = 0U;
/* Board pin, clock, debug console init */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Select the clock source for the TPM counter as MCGPLLCLK */
CLOCK_SetTpmClock(1U);
/* Need a deadtime value of about 200nsec */
deadtimeValue = (((uint64_t)TPM_SOURCE_CLOCK * 400) / 1000000000) / 4;
/* Print a note to terminal */
PRINTF("\r\nTPM example to output combined complementary PWM signals on two channels\r\n");
PRINTF("\r\nIf an LED is connected to the TPM pin, you will see a change in LED brightness if you enter different values");
PRINTF("\r\nIf no LED is connected to the TPM pin, then probe the signal using an oscilloscope");
TPM_GetDefaultConfig(&tpmInfo);
/* Initialize TPM module */
TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo);
TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_CombinedPwm, 24000U, TPM_SOURCE_CLOCK);
#if defined(FSL_FEATURE_TPM_HAS_POL) && FSL_FEATURE_TPM_HAS_POL
/* Change the polarity on the second channel of the pair to get complementary PWM signals */
BOARD_TPM_BASEADDR->POL |= (1U << ((BOARD_TPM_CHANNEL_PAIR * 2) + 1));
#endif
/* Set deadtime insertion for the channel pair using channel filter register */
filterVal = BOARD_TPM_BASEADDR->FILTER;
/* Clear the channel pair's filter values */
// filterVal &= ~((TPM_FILTER_CH0FVAL_MASK | TPM_FILTER_CH1FVAL_MASK)
// << (BOARD_TPM_CHANNEL_PAIR * (TPM_FILTER_CH0FVAL_SHIFT + TPM_FILTER_CH1FVAL_SHIFT)));
/* Shift the deadtime insertion value to the right place in the register */
filterVal |= (TPM_FILTER_CH0FVAL(deadtimeValue) | TPM_FILTER_CH1FVAL(deadtimeValue))
<< (BOARD_TPM_CHANNEL_PAIR * (TPM_FILTER_CH0FVAL_SHIFT + TPM_FILTER_CH1FVAL_SHIFT));
BOARD_TPM_BASEADDR->FILTER = filterVal;
TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock);
while (1) {}
}
Is anybody who run it well?
Helllo Vitaliy,
I have reported this issue to the SW team. I will update this thread when a resolution is available.
Regards,