I am using an interrupt with a timer, and measure the micros() for the interrupt.
I recently started getting odd values for micros. For instance here's some output:
I realize that this is like it's rolling over, cause the value is about at the maximum value of an unsigned int.
I was using a micros() call in the loop, so I took out all other references to micros().
I now separated it out as time1, time2, and time.
I also removed from the interrupt that it does anything except measuring micros().
I'll start a new sketch that just does the timing, but I haven't done that yet.
Oddly with this code:
I get this:
But if I take out the test for >10, I get this:
the interrupt is at 4096Hz.
When I do the test if it's >10, I don't know why t2 is SMALLER than t1.
I recently started getting odd values for micros. For instance here's some output:
Code:
volatile unsigned long time1;
/**
* For recording timing of interrupt function
*/
void captureSamplesTimed() {
time1=micros();
captureSamples();
time1= micros() - time1;
Serial.print("t: ");
Serial.println(time1);
Serial.flush();
}
Code:
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 4294966297
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 1
t: 2
t: 1
t: 1
I realize that this is like it's rolling over, cause the value is about at the maximum value of an unsigned int.
I was using a micros() call in the loop, so I took out all other references to micros().
I now separated it out as time1, time2, and time.
I also removed from the interrupt that it does anything except measuring micros().
I'll start a new sketch that just does the timing, but I haven't done that yet.
Oddly with this code:
Code:
/**
* For recording timing of interrupt function
*/
void captureSamplesTimed() {
time1=micros();
//captureSamples();
time2=micros();
time=time2-time1;
if(time>10) {
Serial.print("t1: ");
Serial.println(time1);
Serial.print("t2: ");
Serial.println(time2);
Serial.print("t: ");
Serial.println(time);
Serial.flush();
}
}
I get this:
Code:
t1: 8026999
t2: 8026000
t: 4294966297
t1: 8087999
t2: 8087000
t: 4294966297
t1: 8148999
t2: 8148000
t: 4294966297
t1: 8209999
t2: 8209000
t: 4294966297
t1: 8270999
t2: 8270000
t: 4294966297
t1: 8331999
t2: 8331000
t: 4294966297
t1: 8392999
t2: 8392000
t: 4294966297
t1: 8453999
t2: 8453000
t: 4294966297
t1: 8514999
t2: 8514000
t: 4294966297
t1: 8575999
t2: 8575000
t: 4294966297
t1: 8636999
t2: 8636000
t: 4294966297
t1: 8697999
t2: 8697000
t: 4294966297
t1: 8758999
t2: 8758000
t: 4294966297
But if I take out the test for >10, I get this:
Code:
t1: 8032798
t2: 8032799
t: 1
t1: 8033042
t2: 8033043
t: 1
t1: 8033286
t2: 8033287
t: 1
t1: 8033530
t2: 8033531
t: 1
t1: 8033774
t2: 8033775
t: 1
t1: 8034018
t2: 8034019
t: 1
t1: 8034262
t2: 8034263
t: 1
t1: 8034506
t2: 8034507
t: 1
t1: 8034750
t2: 8034751
t: 1
t1: 8034994
t2: 8034995
t: 1
t1: 8035238
t2: 8035239
t: 1
the interrupt is at 4096Hz.
When I do the test if it's >10, I don't know why t2 is SMALLER than t1.