I am learning to use the timers on the Due. This library is a very good start, but needs some work.
My question is: How can I cooperate to improve the library?
For example: I added some routines in my local version:
void setupTC2(byte tcClock);
unsigned long read_TC2();
void setupTC2_InterruptN(unsigned long period, byte tcClock, void (*isr)()); //now period is unsigned long
For example: this sketch starts timer and times the atanf function.
#include <DueTC.h>
unsigned long startt, endt, difft;
float x = 100.0;
float y = 200.0;
float d = 0.0;
void setup() {
setupTC2(0);
Serial.begin(115200);
}
void loop() {
startt = read_TC2();
d = atan2f(y,x);
endt = read_TC2();
difft = endt - startt;
Serial.println(difft,DEC);
Serial.println(d,DEC);
delay(1000);
}
This routine turns on a LED on pin9, and turns off after an interrupt when the period is complete.
Uses tcClock0, ie 42Mhz, and runs for max time (2^32 -1). Takes 1 min 42 secs +.
#include <DueTC.h>
boolean la = true;
void offPin9() {
static byte flg;
digitalWrite(9,LOW);
stop_TC2();
la = true;
}
unsigned long timeto = 4294967295
;
byte selclk = 0;
void setup() {
pinMode(9,OUTPUT);
delay(10);
digitalWrite(9,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if (la) {
setupTC2_InterruptN(timeto,selclk,offPin9);
la = false;
}
}