PROBLEM IN CREATING INTERRUPT THROUGH PIT

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

PROBLEM IN CREATING INTERRUPT THROUGH PIT

Jump to solution
6,175 Views
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.

Labels (1)
Tags (3)
0 Kudos
1 Solution
1,341 Views
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

View solution in original post

4 Replies
1,342 Views
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

1,341 Views
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 Kudos
1,341 Views
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 Kudos
1,341 Views
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 Kudos