chipKIT® Development Platform

Inspired by Arduino™

Interrupt Handler Timing debug help

Created Thu, 15 Nov 2012 22:30:55 +0000 by snovich


snovich

Thu, 15 Nov 2012 22:30:55 +0000

Hi all,

I've been reading up on timers + interrupts in the PIC32 handbook, and am having an issue where setting the TXCON register's clock-prescalar field doesn't seem to be making a difference in interrupt timing. I think I may not be fully understanding how setting it works?

On a side note, can anyone explain what the value: iplx means?

Thanks!

#include <plib.h>

int mics = 0;
int micsold = 0;

void setup()
{
  Serial.begin (19200);
  Serial.println("Init Interrupts");
  T5CON = 0x0; // stop timer + clear cntrl reg
  // prescalar is 1:1 of internal clock (80MHz);
  TMR5 = 0x0; //Clear timer register
  PR5 = 0x0010; // 
  T5CON = 0x0020; // Have tired 0x0000, 0x0010, 0x0020, and 0x0030 
  IPC5SET = 0x00000005; // Prio 3, Sub Prio 1
  // Check to see if the following settins is for Timer 2:
  IFS0CLR = 0x00100000; // Clear Timer Interrupt Status Flag
  IEC0SET = 0x00100000; // Enable Timer Interrupts %
 
  T5CONSET = 0x8000; // Start Timer  
  micsold = micros();
}

void loop()
{
 delay(0); 
}

extern "C"
{
  void __ISR(_TIMER_5_VECTOR,ipl1) Timer5Handler(void)
  {
      mics = micros();
      int tel = abs(mics-micsold);
      micsold = mics;
      Serial.print("Interrupt: ");
      Serial.println(tel);
   IFS0CLR = 0x00100000; // Clear Timer Interrupt Status
  }
}

pito

Fri, 16 Nov 2012 01:00:22 +0000

..ipl1-ipl7 = interrupt priority level..


snovich

Mon, 19 Nov 2012 17:13:28 +0000

..ipl1-ipl7 = interrupt priority level..

Got it, thanks! -S


WestfW

Tue, 20 Nov 2012 01:34:05 +0000

It's a bad idea to try to call Serial.print() from an ISR function. (it will fail completely on AVR Arduinos, because serial interrupts need to occur for the output to actually go anyway, and all interrupts are off inside in ISR; I'm not sure about PIC32 with its more complex interrupt controller.)