el_supremo
Well-known member
This Teensy3 code uses the Periodic Interrupt Timer to flash the onboard LED. It works if I run it from beta7 but it doesn't do anything when run from beta8.
Pete
Code:
// Pin for LED
#define LEDPIN 13
// Frequency to run the interrupt at
#define FREQ 2 // in Hertz
volatile int ledVal;
// Constants for bitvalues within the TCTRL1 register
#define TIE 2
#define TEN 1
void timer_setup()
{
// Teensy 3.0 version
SIM_SCGC6 |= SIM_SCGC6_PIT; // Activates the clock for PIT
// Turn on PIT
PIT_MCR = 0x00;
// Set the period of the timer. The µC runs at 50MHz
// So interrupt length can be determined by 50Mhz/FREQ.
PIT_LDVAL1 = 50000000/FREQ;
// Enable interrupts on timer1
PIT_TCTRL1 = TIE;
NVIC_ENABLE_IRQ(IRQ_PIT_CH1); // Another step to enable PIT channel 1 interrupts
// Start the timer
PIT_TCTRL1 |= TEN;
}
void setup()
{
pinMode(LEDPIN, OUTPUT);
ledVal = 0;
digitalWrite(LEDPIN, ledVal);
timer_setup();
}
void pit1_isr(void)
{
PIT_TFLG1 = 1;
digitalWrite(LEDPIN, ledVal ^= 1);
}
void loop()
{
}
Pete