No interrupts with MKL04 PIT

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

No interrupts with MKL04 PIT

1,041 Views
JBM
Contributor IV

I am having an issue with the MKL04Z8VFK4 PIT setup.  I've used the following code for years on various Kinetis controllers:

 

  PIT_MCR     = 0x0;

  PIT_LDVAL1  = 20000L;

  PIT_TCTRL1  = PIT_TCTRL_TIE_MASK;

  PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK;

  enable_irq(PIT_IRQn);

 

enable_irq calls NVIC_EnableIRQ. 

 

Also, in main before the timer is initialized, the following is set:

 

  SIM_SCGC6 |= SIM_SCGC6_PIT_MASK |

               SIM_SCGC6_ADC0_MASK;

 

For some reason with this microcontroller, I'm not getting any interrupts.

 

In checking the documentation, the reference manual, KL04P48M48SF1RM.pdf, lists the TIE and TEN bits as bits 30 and 31 of the PIT_TCTRLn registers (these registers are numbered backwards compared to other registers in the same pdf file).  The PIT_TCTLR_TIE_MASK is declared as 0x2u and PIT_TCTRL_TEN_MASK is declared as 0x1u in MKL04Z4.h which is automatically included when the project was created.

 

I have stepped through all the code to make sure everything is being executed.  Interrupts are enabled by calling EnableInterrupts declared as:

 

#define EnableInterrupts __asm(" CPSIE i");

 

So two things -- it appears as though either the include file, or the documentation is wrong (see attached files).  Also, I've tried it both ways and interrupts are not happening.  

 

Any suggestions?

 

Thanks.

Original Attachment has been moved to: MKL04Z4.h.zip

Labels (1)
0 Kudos
7 Replies

733 Views
mjbcswitzerland
Specialist V

James

1. Check that the PIT interrupt ID is 22 - it is the same for all KL parts with PIT.

2. The PIT bit numbering is a document errata which has been discussed in another thread somewhere - the header bit defines are correct.

3. I don't think that the KL04 has any reported PIT erratas but I would add erratas 7914 and 2682 workarounds to be sure.
As reference I have attached the PIT module from the uTasker project that is compatible with all Kinetis (K,K,KEA,KL,KV,KM,KW) parts and includes/documents PIT errata workarounds.

Regards

Mark

0 Kudos

733 Views
JBM
Contributor IV

Thanks for that.  I looked through the code you posted and didn't see anything that struck me as odd or different.  I tried both errata and no luck.  Just in case it was something I was doing that is stupid, I created a new project (see below) and it also does not get an interrupt.  This is straight out of the reference manual (with the exception of the 20000UL as the counter value).   I also tried timer 0, not that it should make any difference -- same thing.

If anybody has any other ideas, I would love to hear them.

Thanks,

Brad

/*
*/

#include <stdint.h>

#include "MKL04Z4.h"

uint32_t counter = 0;

void PIT_IRQHandler(void)
{
   counter++;
   PIT_TFLG1 = PIT_TFLG_TIF_MASK;
}

int main(void)
{
   int i;
   volatile uint32_t c;

   SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

   __asm("CPSIE i");

   PIT_MCR = 0x0;
   PIT_LDVAL1 = 20000L;
   PIT_TCTRL1 = PIT_TCTRL_TIE_MASK;
   PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK;
   NVIC_EnableIRQ(PIT_IRQn);

   /*
    *
    */
   for (;;)
   {
      c = PIT_CVAL1;
      i++;
   }
   /* Never leave main */
   return 0;
}

0 Kudos

733 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi James,

I haven't found any obvious problems in your program. Maybe you can attached the whole project after zip it. So that we can test it directly.

You can test the attached project generated by Processor Expert with KDS3.2. It can always run into the PE_ISR(PIT_isr).

PIT_ISR.png

During debug, can you observe the value of PIT_CVAL1 decrease?

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

733 Views
JBM
Contributor IV

Just for the fun of it, I checked the value of the PIT_TFLG1 register -- it has the TIF bit set when the counter is zero.  After I write 0x01 to PIT_TFLG1 register, it is zero.  So it is set correctly and clears correctly, but no interrupt.

I also verified the PIT_IRQHandler interrupt in startup_MKL04Z4.S is the 22nd interrupt (the right place in the interrupt vector table).

/*
*/

#include <stdint.h>

#include "MKL04Z4.h"

uint32_t counter = 0;

void PIT_IRQHandler(void)
{
   counter++;
   PIT_TFLG1 = PIT_TFLG_TIF_MASK;
}

int main(void)
{
   int i;
   volatile uint32_t c;

   SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

   PIT_MCR = 0x01;
   PIT_LDVAL1 = 20000UL;
   PIT_TCTRL1 = PIT_TCTRL_TIE_MASK;
   PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK;
   NVIC_EnableIRQ(PIT_IRQn);

   __asm("CPSIE i");

   /*   
    *
    */
   for (;;)
   {
      c = PIT_CVAL1;
      if (0 == c)
      {
         c = PIT_TFLG1;
         PIT_TFLG1 = 0x1;
         c = PIT_TFLG1;
      }
      i++;
   }
   /* Never leave main */
   return 0;
}

0 Kudos

733 Views
JBM
Contributor IV

Quick question on the project you attached.  It uses the Processor Expert and the Kinetis SDK, right?  What compiler does that use?  I don't seem to be able to open it and make it run.

I use the gcc compiler on a recommendation from NXP due to a bug when returning structures.  I had some vector routines on a K22 that didn't work with the other compiler -- they said the only way to solve my problem was to switch to gcc.

0 Kudos

733 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

The project is generated by Processor Expert with KDS3.2 ide.

I can't build your project either with CodeWarrior10.7 and KDS3.2.

0 Kudos

733 Views
JBM
Contributor IV

Yes, I checked PIT_CVAL1, it is decreasing.  I have attached the test project.

Thanks,

Brad

0 Kudos