Can some kind soul help me adressing the Timer1 in arduino instead of IDE-Preset functions?
I want higher res on external interrupt. This below needs to be rewritten the hardcore way.
I dont understand and would like it to be rewritten....
Best!
//
int mic1 = 2;// using leonardo for external interrupts on theese pins.
int mic2 = 3;
int mic3 = 7;
volatile unsigned long tid1 = 0; //Var to store time-stamp in micros in.
volatile unsigned long tid2 = 0;
volatile unsigned long tid3 = 0;
volatile int stop1 = 0;//Flags in interrupts to not trigger again.
volatile int stop2 = 0;
volatile int stop3 = 0;
void setup() {
pinMode(mic1, INPUT);
pinMode(mic2, INPUT);
pinMode(mic3, INPUT);
pinMode(11, OUTPUT);//Eg Buzzer to beep when all triggs ar OK!
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(mic1), trig1, FALLING);//How to write this in the hardcore way removing IDE presets???
attachInterrupt(digitalPinToInterrupt(mic2), trig2, FALLING);
attachInterrupt(digitalPinToInterrupt(mic3), trig3, FALLING);
}
void loop() {
if (stop1 == 1 && stop2 == 1 && stop3 == 1) {
stop1 = 20;//Avoid triggs by changing state to 20 or anything but 0...
stop2 = 20;
stop3 = 20;
// These things write to an external application.
Serial.print("A");
Serial.write((byte)0x00);
Serial.print(tid1);
Serial.write((byte)0x00);
Serial.print("B");
Serial.write((byte)0x00);
Serial.print(tid2);
Serial.write((byte)0x00);
Serial.print("C");
Serial.write((byte)0x00);
Serial.print(tid3);
Serial.write((byte)0x00);
Serial.println();
//End writing to external application....
delay(250); //ECHO-Delay.
//reset states.
tid1 = 0;
tid2 = 0;
tid3 = 0;
stop1 = 0;
stop2 = 0;
stop3 = 0;
}
}
void trig1() {
if (stop1 == 0);
tid1=micros();// How to write this the hardcore way adressing timer1 to get the value based om clockcycles?
tid1=tid1;// Just so it doesent rely on function micros that gives error for me.
stop1 = 1; //Raise flag to avoid more/future interruppts....
}
void trig2() {
if ( stop2 == 0);
tid2=micros();
tid2=tid2;
stop2 = 1;
}
void trig3() {
if ( stop3 == 0);
tid3=micros();
tid3=tid3;
stop3 = 1;
}