Author Topic: Timer Interrupt Overrun  (Read 3611 times)

Offline Phil

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Timer Interrupt Overrun
« on: September 18, 2018, 11:27:09 PM »
Mark,

Here is a sample timer interrupt process that I am running:

   static TIMER_INTERRUPT_SETUP timer_setup = {0}; // interrupt configuration parameters

   timer_setup.int_type = TIMER_INTERRUPT;
   timer_setup.int_priority = PRIORITY_TIMERS;
   timer_setup.int_handler = IR_Receiver;
   timer_setup.timer_reference = 2; // timer channel 2
   timer_setup.timer_mode = (TIMER_PERIODIC | TIMER_US_VALUE); // single shot us timer
   timer_setup.timer_value = 281; // (562.5/2) // µs delay
//   timer_setup.timer_value = 1000;
   fnConfigureInterrupt((void *)&timer_setup); // enter interrupt and start timer

The function, IR_Receiver(), gets executed once every 281 us.  The problem is that it causes a hardware reset on my MK64 MCU.  If I change the timer_value to 1000 us, there is no lockup and the routine runs from beginning to end. It doesn't happen quick enough to get us the valid info we need but it works nonetheless.

I see examples of PIT timers and other timers with 100 us cycle times. I wouldn't think this would be a problem. But, my MCU resets.

Can you explain what is happening?

Regards,

Phil


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Timer Interrupt Overrun
« Reply #1 on: September 18, 2018, 11:47:12 PM »
Hi Phil

Can you try this instead?

   static TIMER_INTERRUPT_SETUP timer_setup = {0}; // interrupt configuration parameters
   timer_setup.int_type = TIMER_INTERRUPT;
   timer_setup.int_priority = PRIORITY_TIMERS;
   timer_setup.int_handler = IR_Receiver;
   timer_setup.timer_reference = 2; // timer channel 2
   timer_setup.timer_mode = (TIMER_PERIODIC); // periodic us timer
  timer_setup.timer_value = TIMER_US_DELAY(281);  // µs delay
   fnConfigureInterrupt((void *)&timer_setup); // enter interrupt and start timer


The TIMER_US_VALUE flag is not used in the Kinetis version and instead it needs the value passed in counts and not us (using the TIMER_US_DELAY() macro, whereby the API also calculates the best prescaler value to use with it).

This will give you 281us periodic interrupt whereby the original would have given 4.7us rate (possibly too fast) with a 60MHz bus clock (I assume you are using K64 at 120MHz and 60MHz bus).

Regards

Mark

Offline Phil

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: Timer Interrupt Overrun
« Reply #2 on: September 19, 2018, 12:04:47 AM »
That worked just fine.

Thank you once again, Mark.

Phil