Hello All,
I am trying to generate a simple counter, using GPT2 timer and an interrupt. Currently, when GPT2_CNT reaches the Output Compare Value (GPT2_OCR1), the program stops executing.
Within my ISR, I only increment a counter value.
My Code for GPT2 Timer:
Also - Does anyone know how to define a ISR directly, instead of using attachInterruptVector(xx,yy) function? In AVR-world, I would use something like:
I am trying to generate a simple counter, using GPT2 timer and an interrupt. Currently, when GPT2_CNT reaches the Output Compare Value (GPT2_OCR1), the program stops executing.
Within my ISR, I only increment a counter value.
My Code for GPT2 Timer:
Code:
/*
* Teensy 4.1 General Purpose Timers Testing
* March 2, 2022
*/
const byte pin_LED = 13;
boolean LED_st = 1;
const unsigned long LED_time_ms = 100;
unsigned int ISR_Cnt = 0;
unsigned long t1,t2;
///////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);
pinMode(pin_LED,OUTPUT);
digitalWrite(pin_LED,HIGH);
Setup_GPT_Regs();
t1 = millis();
t2 = t1;
}
///////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
t1 = millis();
if(((t1-t2) >= LED_time_ms) || (t2 > t1))
{
LED_st = !LED_st;
digitalWrite(pin_LED,LED_st);
Serial.print(t1/1000);
Serial.print("\t");
Serial.print(ISR_Cnt);
Serial.print("\t");
Serial.println(GPT2_CNT);
t2 = t1;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void Setup_GPT2_Regs()
{
/* Initialize GPT2 */
CCM_CCGR0 |= CCM_CCGR0_GPT2_BUS(CCM_CCGR_ON) | CCM_CCGR0_GPT2_SERIAL(CCM_CCGR_ON);
GPT2_SR = 0x3F; // Clear all prior status - Not sure exactly how this works
GPT2_SR = 0x00; // Not sure if this is necessary
GPT2_CR |= GPT_CR_CLKSRC(1); // Set clocksource to Peripheral Clock
GPT2_CR |= GPT_CR_ENMOD; // Set Reset Mode
GPT2_IR |= GPT_IR_OF1IE; // Enable Output Compare for OCR1
GPT2_OCR1 = 0x10FFFF00; // Set Output Compare Value
GPT2_CR |= GPT_CR_EN; // Enable GPT2
/* Setup Interrupt */
attachInterruptVector(IRQ_GPT2, &Test_ISR);
//NVIC_SET_PRIORITY(IRQ_GPT2, 0);
NVIC_ENABLE_IRQ(IRQ_GPT2);
}
///////////////////////////////////////////////////////////////////////////////////////////////
inline void Test_ISR()
{
ISR_Cnt = ISR_Cnt + 1;
}
Also - Does anyone know how to define a ISR directly, instead of using attachInterruptVector(xx,yy) function? In AVR-world, I would use something like:
Code:
ISR(TIMER1_COMPA_vect)
{
//Do ISR Stuff Here
}