TelephoneBill
Well-known member
Qtimer
I have run into T4 trouble while experimenting with a QTIMER QT3_0. I am making an assumption that QT3_0 is free to use?
I am using the QTIMER as a simple upcounter from 0 to COMPARE1 and then reset 0. I want a toggled sq wave output from the OFLAG, and wish to trigger an ISR.
I'm getting a sq wave output OK on pin 19, but the ISR does not seem to be working correctly and the Serial Monitor seems broken too.
It is entering the ISR because the LED comes on permanently from digitalWriteFast (and is off if I remove the statement within the ISR), but it looks as if the flag raising the interrupt is not getting reset within the ISR. This is probably the cause of the broken Serial Monitor.
There appears to be two flags in the mechanism which I don't properly understand - a "Compare" flag in TMR3_SCTRL0, and another one "Compare1" in TMR3_CSCTRL0. As you can see in my code, I'm trying to reset both (have attempted each one separately). But all attempts have failed so far.
Appreciate any assistance.
I have run into T4 trouble while experimenting with a QTIMER QT3_0. I am making an assumption that QT3_0 is free to use?
I am using the QTIMER as a simple upcounter from 0 to COMPARE1 and then reset 0. I want a toggled sq wave output from the OFLAG, and wish to trigger an ISR.
I'm getting a sq wave output OK on pin 19, but the ISR does not seem to be working correctly and the Serial Monitor seems broken too.
It is entering the ISR because the LED comes on permanently from digitalWriteFast (and is off if I remove the statement within the ISR), but it looks as if the flag raising the interrupt is not getting reset within the ISR. This is probably the cause of the broken Serial Monitor.
There appears to be two flags in the mechanism which I don't properly understand - a "Compare" flag in TMR3_SCTRL0, and another one "Compare1" in TMR3_CSCTRL0. As you can see in my code, I'm trying to reset both (have attempted each one separately). But all attempts have failed so far.
Appreciate any assistance.
Code:
//TESTT4005 - QTIMER TEST PROGRAM for T4
//======================================
//Author: TelephoneBill
//Date: 17 JUL 2019
//NOTES: Using QT3 as timer. Using QT3_0 OFLAG as sq wave output and triggering an ISR.
//definitions
byte Byte1;
volatile uint32_t ISRTicks = 0, LastISRTicks = 0;
//SETUP
//=====
void setup() {
//initialise general hardware
Serial.begin(115200); //setup serial port
pinMode(13, OUTPUT); //pin 13 as digital output
FlashLED(4);
//enable clocks for QTIMER3
CCM_CCGR6 |= 0xC0000000; //enable clocks to CG15 of CGR6 for QT3
//configure QTIMER1 Timer0 for test. Period = 65,536 = 436.9 uS (times 2) - rollover
TMR3_CTRL0 = 0b0000000000100000; // stop all functions of timer
TMR3_SCTRL0 = 0b0100000000000001; // 0(TimerCompareFlag),1(TimerCompareIntEnable),000000,00(Capture Disabled),00000,1(OFLAG to Ext Pin)
TMR3_CNTR0 = 0;
TMR3_LOAD0 = 0;
TMR3_COMP10 = 10000; // 6.7nS per clock = 66.7uS for 10,000 clocks on each half cycle
TMR3_CMPLD10 = 10000;
TMR3_CSCTRL0 = 0b0000000001000001; //Compare1 interrupt enable
TMR3_CTRL0 = 0b0011000000100011; // 001(Count rising edges Primary Source),1000(IP Bus Clock),00 (Secondart Source),
// 0(Count Once),1(Count up to Compare),0(Count Up),0(Co Channel Init),011(Toggle OFLAG on Compare)
//configure Teensy pin Compare output
IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_00 = 1; // QT3 Timer0 is now on pin 19
//enable GPT1 interrupt within NVIC table
attachInterruptVector(IRQ_QTIMER3, QT3_isr); //declare which routine performs the ISR function
NVIC_ENABLE_IRQ(IRQ_QTIMER3);
}
//ISR ROUTINE FOR GPT1
//====================
//FASTRUN puts this code into RAM to run twice as fast
FASTRUN void QT3_isr(void) {
TMR3_SCTRL0 |= 0b1000000000000000; //reset the compare flag
TMR3_CSCTRL0 |= 0b0000000000010000; //Compare1 interrupt enable
ISRTicks++;
digitalWriteFast(13, 1); //test that ISR is being entered
asm volatile("dsb");
}
//MAIN LOOP
//=========
void loop() {
//call KeyInput() routine
KeyInput();
if (ISRTicks>LastISRTicks) {
LastISRTicks = ISRTicks;
delay(100);
digitalWriteFast(13, 0);
delay(900);
}
}
//SUBROUTINES
//===========
//Flash LED routine
void FlashLED(int m) {
for (int n=0;n<m;n++) {
digitalWriteFast(13, 1); //set pin 13 high
delay(100);
digitalWriteFast(13, 0); //set pin 13 low
delay(100);
}
}
void KeyInput() {
//process any keystrokes available
if (Serial.available()>0) {
//read the incoming byte
Byte1 = Serial.read();
if (Byte1>0x20) {
switch (Byte1) {
case 'T': //print the ISRTicks value
//task goes here...
Serial.print("ISRTicks = "); Serial.println(ISRTicks);
break;
}
}
}
}