View Full Version : Teensy 3.0 and interrupts

10-26-2012, 11:38 PM
I'm porting over an Arduino sketch that relied on the chip for timer-based interrupts. It looks to me from the documentation as though the proper timer to use for this on Teensy 3.0 is the periodic interrupt timer, PIT. So I did some setup:

// Constants for bitvalues within the TCTRL1 register
#define TIE 2
#define TEN 1

void timer_setup() {
/* Arduino version of timer setup
TCCR2A = 0;
TCNT2=455; //455 outputs 1.007khz
TCCR2B = B00000010;
//Timer2 Overflow Interrupt Enable
TIMSK2 = 1<<TOIE2;

// Teensy 3.0 version

// Turn on PIT
PIT_MCR = 0x00;

// Set the period of the timer. Unit is (1 / 50MHz) = 20ns
// So 1 kHz frequency -> 1 ms period -> 50000 * 20ns
PIT_LDVAL1 = 50000;
// Enable interrupts on Timer1
// Start the timer

I'm not completely certain that's correct, but it's similar to code included in the chip datasheet.

But I'm not really sure how to declare an interrupt handler for the PIT. The Arduino code is

ISR(TIMER2_OVF_vect) {
// function body

but of course that's for the AVR timer interrupt. I tried to look through the hardware/teensy3 code, but I couldn't find the relevant bits. The datasheet just says "See the MCU specification for related vector addresses and priorities," and I couldn't work out what that meant. (My best guess was "http://cache.freescale.com/files/32bit/doc/data_sheet/K20P64M50SF0.pdf", but that doesn't have any relevant information.)

Is there a good source of documentation on this?


10-27-2012, 01:50 AM
Sorry, probably should have been in "General Guidance." Not sure how to move it--just copying the post over there. Sorry all!