AnsweredAssumed Answered

Why is TPM0 not incrementing / interrupting?

Question asked by Evan Griffith on Jun 5, 2019
Latest reply on Jun 12, 2019 by Mark Butcher

Hi,

 

I am new to MCUExpresso, and I am having difficulty with a TPM Timer.  I looked over the example and the SDK and attempted to implement it on my board, but I can not get the timer to count, let alone interrupt.  I have attached a screen shot of the clocks table and below are the parts of my code dealing with the TPM module. 

 

Thanks in advance for your help!

 

 

#include <stdio.h>
#include "MKL17Z644.h"

#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_gpio.h"
#include "fsl_spi.h"

#include "fsl_tpm.h"

 

#define BOARD_TPM TPM0
#define BOARD_TPM_IRQ_NUM TPM0_IRQn
#define BOARD_TPM_HANDLER TPM0_IRQHandler
//#define TPM_SOURCE_CLOCK (CLOCK_GetFreq(kCLOCK_McgIrc48MClk)/4)
#define TPM_SOURCE_CLOCK (CLOCK_GetFreq(kCLOCK_McgInternalRefClk))

 

volatile uint32_t tpmCounter = 0U;

 

void BOARD_TPM_HANDLER(void);

 

int main(void)
{

tpm_config_t tpmInfo;

 

/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
InitGPIOs();
CLOCK_SetTpmClock(1U);

 

/* TPM Setup */

TPM_GetDefaultConfig(&tpmInfo);

#ifndef TPM_PRESCALER
#define TPM_PRESCALER kTPM_Prescale_Divide_4
#endif

//tpmInfo.prescale = TPM_PRESCALER; /* TPM clock divide by TPM_PRESCALER */
TPM_Init(BOARD_TPM, &tpmInfo); /* Initialize TPM module */
TPM_SetTimerPeriod(BOARD_TPM, USEC_TO_COUNT(1000U, TPM_SOURCE_CLOCK)); /* Set timer period. */
TPM_EnableInterrupts(BOARD_TPM, kTPM_TimeOverflowInterruptEnable);
EnableIRQ(BOARD_TPM_IRQ_NUM);

 


printf("Starting TPM Timer!\r\n");
tpmDelay(100);
printf("Returning from TPM Timer!\r\n");

}

 

void BOARD_TPM_HANDLER(void)

{
/* Clear interrupt flag.*/
TPM_ClearStatusFlags(BOARD_TPM, kTPM_TimeOverflowFlag);
tpmCounter++;
__DSB();
//__ISB(); //Needed?
}

uint8_t tpmDelay(uint32_t delayTime)
{
TPM_StartTimer(BOARD_TPM, kTPM_SystemClock);
tpmCounter = 0;
while(1)
{
if(delayTime <= tpmCounter)
{
TPM_StopTimer(BOARD_TPM);
printf("delayTime was: %d\r\n", delayTime);
printf("tpmtmrCounter was: %d\r\n", tpmCounter);
return 0;
}
//__WFI();
}

 

 

From clocks_config.c

#define SIM_TPM_CLK_SEL_MCGIRCLK_CLK                      3U  /*!< TPM clock select: MCGIRCLK clock */

CLOCK_SetTpmClock(SIM_TPM_CLK_SEL_MCGIRCLK_CLK);

Attachments

Outcomes