ampere-dieter
New member
Hi,
for my motor application I have to modify the PIT-timer period on the fly.
Upto Version 1.13 this was possible, but since Version 1.14 IntervalTimer is part of Core.
How can I shutdown IntervalTimer in Core, or move him to lib?
Or other possibilities?
Thanks, Dieter
for my motor application I have to modify the PIT-timer period on the fly.
Upto Version 1.13 this was possible, but since Version 1.14 IntervalTimer is part of Core.
How can I shutdown IntervalTimer in Core, or move him to lib?
Or other possibilities?
Thanks, Dieter
Code:
// Change Period of IntervalTimer before Version Teensyduino 1.14
// ( since Teensyduino 1.14 the IntervalTimer is part of Core )
#define FREQ 1 // Frequency (Hz) to run the interrupt
#define LEDPIN 13 // Pin for LED
volatile int ledVal;
void timer_setup() { // Teensy 3.0 version (PIT-timer0, PIT-timer1, PIT-timer2, PIT-timer3)
SIM_SCGC6 |= SIM_SCGC6_PIT; // Activates the clock for PIT
PIT_MCR = 0x00; // Turn on PIT
// Set the period of the timer. The uC runs at 48MHz
// So interrupt length can be determined by F_BUS=48Mhz/FREQ.
PIT_LDVAL0 = 48000000*20; // set timer0 to 1/20 Hz fix
PIT_TCTRL0 = 3; // Enable interrupts and start timer0
NVIC_ENABLE_IRQ(IRQ_PIT_CH0); // enable ARM interrupt controller NVIC for PIT channel 0 interrupts
PIT_LDVAL1 = 48000000/FREQ; // set timer1 to FREQ
PIT_TCTRL1 = 3; // Enable interrupts and start timer1
NVIC_ENABLE_IRQ(IRQ_PIT_CH1); // enable ARM interrupt controller NVIC for PIT channel 1 interrupts
}
void pit0_isr(void) {
digitalWrite(LEDPIN, ledVal ^= 1); // toggle LED
Serial.print(" T0=");
Serial.println(millis());
PIT_TFLG0 = 1;
}
void pit1_isr(void) {
// digitalWrite(LEDPIN, ledVal ^= 1); // toggle LED
Serial.print("T1=");
Serial.println(millis());
PIT_TFLG1 = 1;
}
void setup(){
pinMode(LEDPIN, OUTPUT);
ledVal = 0;
digitalWrite(LEDPIN, ledVal); // Start the LED off
cli();
timer_setup();
sei();
}
void loop() {
// page 823: PIT_LDVALn field Timer Start Value:
// Sets the timer start value. The timer will count down until it reaches 0, then it will generate an interrupt
// and load this register value again. Writing a new value to this register will not restart the timer;
// instead the value will be loaded after the timer expires.
// To abort the current cycle and start a timer period with the new value, the timer must be disabled and enabled again.
delay(10000);
PIT_TCTRL1 = 2; // disable PIT-timer1
PIT_LDVAL1 = 48000000; // timer1 to 1Hz, change reg on the fly
PIT_TCTRL1 = 3; // ensable PIT-timer1 again
delay(10000);
PIT_TCTRL1 = 2; // disable PIT-timer1
PIT_LDVAL1 = 4800000; // timer1 to 10Hz, change reg on the fly
PIT_TCTRL1 = 3; // ensable PIT-timer1 again
}