TPM0 Timerinterrupt on MKL27Z

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

TPM0 Timerinterrupt on MKL27Z

1,333 次查看
paultargo
Contributor I

I'm using FRDM-KL27Z with Kinetis Design Studio

Somehow i dont get the Interrupt working. I'm sure to oversee something. 

#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_device_registers.h"

void TPM0_IRQHandler(void){
GPIOB->PTOR = 1 << 18;
TPM2->SC |= TPM_SC_TOF_MASK;
}

volatile int count;
int main(void) {

// Init board hardware.
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

MCG->C1 = MCG_C1_IREFSTEN_MASK | MCG_C1_IRCLKEN_MASK;
MCG->C2 = MCG_C2_IRCS_MASK;
SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK;
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(3);

TPM0->SC = TPM_SC_CMOD(0) | TPM_SC_PS(7);
TPM0->MOD = 0xFF;

TPM0->SC |= TPM_SC_TOIE_MASK;


EnableIRQ(TPM0_IRQn);


SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
PORTB->PCR[18] = PORT_PCR_MUX(1);

GPIOB->PDDR = 1 << 18;

TPM0->SC |= TPM_SC_TOF(1);


for(;;) { 
      count = TPM0->CNT;
   }
}

It compiles and the timer (cnt) is increasing.

TOF gets set too. Setting it to 0 (in debugtools) didnt help. its just 0 until it changes again to 1.

0 项奖励
回复
2 回复数

884 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi David,

Please add below code to start the TPM counter.

TPM0->SC |= TPM_SC_CMOD(1);

The code below should be used to clear the Timer Overflow Flag of TPM0 In TPM0_IRQHandler.

TPM0->SC |= TPM_SC_TOF_MASK;

Best Regards,

Robin

0 项奖励
回复

884 次查看
dsherman
Contributor III

It's not clear what EnableIRQ does, but I don't see where the interrupt is enabled and the interrupt priority is set in the NVIC.  The TPM0 for KL27 uses NVIC_IPR4 bits 14:15, and it would be bit 17 in the NVIC_ISER to enable it.  You should probably also add the attribute tag __attribute__((interrupt("IRQ"))) to your function to declare that it's an interrupt handler.  I'm assuming that TPM0_IRQHandler is already weakly defined in the vector table so that it's latching on to the handler you've made.

0 项奖励
回复