vmstanford
Member
Using IntervalTimer to try and read ADC and write DAC on a regular interval (1kHz in this test). Step 1 is to simply gather time tags in an array. micros() failed earlier and I read where micros() in an interrupt service routine does not work because it sets off its own interrupts. But the Teensy 3.6 and 3.5 both crash after a few tens of thousands of timer interrupt activations.
Now using ARM_DWT_CYCCNT instead because of the recommendations I read on PJRC fora. Still getting crashes just as with micros(). I put a blinker on pin 13 to determine if the Teensy is crashing or the Serial Monitor of the Arduino IDE is crashing. The blinker stops dead. Pressing hardware reset on the Teensy gets the blinker going again, and Serial Monitor resumes without a restart of the IDE. The Teensy then runs for tens of thousands cycles (up to maybe 200k cycles) and crashes again.
Test code is as follows:
Any thoughts on how to fix this will be appreciated.
Vince Stanford
Now using ARM_DWT_CYCCNT instead because of the recommendations I read on PJRC fora. Still getting crashes just as with micros(). I put a blinker on pin 13 to determine if the Teensy is crashing or the Serial Monitor of the Arduino IDE is crashing. The blinker stops dead. Pressing hardware reset on the Teensy gets the blinker going again, and Serial Monitor resumes without a restart of the IDE. The Teensy then runs for tens of thousands cycles (up to maybe 200k cycles) and crashes again.
Test code is as follows:
Code:
/--------------------------------------------------------------------------
// Name: intervalTimerTest
//
// Purpose - This program instruments the performance of teensyduino object
// IntervalTimer during:
//
// 1. Simple activation and timestamping using micros();
// 2. Time Stamping, and analog reading
// 3. Time Stamping, analog reading (ADC), and analog writing (DAC).
//
// Instruments with timestamp, to allow investiation of read/write
// frequencies in offline analyses
//
// Authors:
//
// Michael Stanford, Senior Software Engineer, Del Rey Analytics, LLC
// Vincent Stanford, Chief Engineer, Del Rey Analytics, LLC
//
// Date: July 16, 2019
//
// Language: Arduino C++ Arduino IDE 1.8.9.
// Library: PJRC Teensyduino, Version 1.4.6 32bit ARM (Raspberry Pi)
//
//-----------------------------------------------------------------------
#define LINE_BUFF_SIZE (32)
#define MAX_SAMPS (1024)
#define MICRO_SECONDS_PER_SAMP (1000)
volatile unsigned long samp = 0;
volatile unsigned long timeTags[MAX_SAMPS] = {0};
volatile unsigned long totalSamps = 0;
// Create an IntervalTimer object
IntervalTimer intervalTimer1;
// blink to show it's alive
volatile int led=13;
void setup() {
// set up cycle counter for Teensy 3.6
ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
// blinker
pinMode(led,OUTPUT);
Serial.begin(115200);
intervalTimer1.begin(processSamplingEvent, MICRO_SECONDS_PER_SAMP);
}
void processSamplingEvent() {
if (samp < MAX_SAMPS) {
timeTags[samp++] = ARM_DWT_CYCCNT;
totalSamps++;
}
}
// The main program will print the accumulated time tags
// to the Arduino Serial Monitor
void loop() {
int i;
digitalWrite(led,LOW);
if (samp >= MAX_SAMPS) {
for (i = 0; i < MAX_SAMPS; i++) {
while(Serial.availableForWrite()<LINE_BUFF_SIZE) {
delay(1);
}
Serial.print(i);
Serial.print(" ");
Serial.print(totalSamps+i);
Serial.print(" ");
Serial.println(timeTags[i]);
}
noInterrupts();
samp = 0;
interrupts();
}
digitalWrite(led,HIGH);
delay(10);
}
Any thoughts on how to fix this will be appreciated.
Vince Stanford
Last edited by a moderator: