PROBLEM IN CREATING INTERRUPT THROUGH PIT

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

PROBLEM IN CREATING INTERRUPT THROUGH PIT

跳至解决方案
7,478 次查看
gagangarg
Contributor II

Hello,

I am trying to create an interrupt through pit.

But I didn't find any resourceful material in order to call an interrupt.

I want to know what all modification is required to be done in order to call interrupt isr.

All i know is I have to define vector in isr.h for the required isr function only.

标签 (1)
标记 (3)
0 项奖励
回复
1 解答
2,644 次查看
TomasVaverka
NXP TechSupport
NXP TechSupport

Gagan,

Here is a simple example for the KL25Z MCU.

// PIT Initialization 


SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;     // Enable the clock to the PIT module

PIT_LDVAL0 = 8000000;     // Default start value

PIT_MCR = PIT_MCR_FRZ_MASK;     // Enable clock for timer, freeze timer in debug mode

PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK;     // Enable timer and timer interrupt

// Initialize the NVIC to enable the PIT interrupt

NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);

NVIC_ISER |= 1 << ((INT_PIT - 16) % 32);

In CW 10.3 and for FRDM-KL25Z the GCC compiler is used, this compiler creates the vector table with the names of each interrupt. So it is just necessary to name you ISR with the same name in the vector table (PIT_IRQHandler in the kinetis_sysinit.c).

void PIT_IRQHandler()

{

PIT_TCTRL0 = 0;     // Disable timer

PIT_TFLG0 |= PIT_TFLG_TIF_MASK;     // Clear the timer interrupt flag 

PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK;     // Enable timer

}


Hope it helps.


Regards,

Tomas

在原帖中查看解决方案

4 回复数
2,645 次查看
TomasVaverka
NXP TechSupport
NXP TechSupport

Gagan,

Here is a simple example for the KL25Z MCU.

// PIT Initialization 


SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;     // Enable the clock to the PIT module

PIT_LDVAL0 = 8000000;     // Default start value

PIT_MCR = PIT_MCR_FRZ_MASK;     // Enable clock for timer, freeze timer in debug mode

PIT_TCTRL0 = PIT_TCTRL_TIE_MASK | PIT_TCTRL_TEN_MASK;     // Enable timer and timer interrupt

// Initialize the NVIC to enable the PIT interrupt

NVIC_ICPR |= 1 << ((INT_PIT - 16) % 32);

NVIC_ISER |= 1 << ((INT_PIT - 16) % 32);

In CW 10.3 and for FRDM-KL25Z the GCC compiler is used, this compiler creates the vector table with the names of each interrupt. So it is just necessary to name you ISR with the same name in the vector table (PIT_IRQHandler in the kinetis_sysinit.c).

void PIT_IRQHandler()

{

PIT_TCTRL0 = 0;     // Disable timer

PIT_TFLG0 |= PIT_TFLG_TIF_MASK;     // Clear the timer interrupt flag 

PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK;     // Enable timer

}


Hope it helps.


Regards,

Tomas

2,644 次查看
davidemanzati
Contributor I

Hello Tomas, i'm trying to follow your example but it didn't work...i've copied your code but i've a question...i have to write the instruction for the interrupt in Kinetis_sysinit.c or in main.c?

Thanks Davide.

0 项奖励
回复
2,644 次查看
Paul_Tian
NXP Employee
NXP Employee

Sorry, I do not know which series chip you use. So here, I give you a PIT example initial code for your reference. In this code, it use interrupt flag check method.

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

  PIT_MCR= 0x00;

  PIT_LDVAL = 0x16E3600;

  PIT_TCTRL = PIT_TCTRL0_TIE_MASK;

  PIT_TCTRL |= PIT_TCTRL0_TEN_MASK;

  while(PIT_TFLG == 0) ;//Waiting Interrupt

  PIT_TFLG  = PIT_TFLG0_TIF_MASK; // Clear Interrupt flag

  PIT_TCTRL = 0 ; //Disable TEN

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

0 项奖励
回复
2,643 次查看
Hui_Ma
NXP TechSupport
NXP TechSupport

In addition to Zhe Tian's reply, please refer below PIT example code for K60 100MHz product.

Wish it helps.

0 项奖励
回复