I tried to use built in 64 bits hardware timers to measure pulse width inside interrupts using following method:
Pseudo code:
Code: Select all
timer = timerBegin(0, 80, true);
attach interrupt RISING;
rising_interrupt() {
t_now = timerRead(timer);
attach interrupt FALLING;
}
falling_interrupt() {
Pulse_Width = timerRead(timer) - t_now;
attach interrupt RISING;
}
...
Also I tryed this simple example to find out an explanation:
Code: Select all
long t_now;
long t_now2;
uint16_t Time_To_Read = 500;
hw_timer_t * timer = NULL;
void setup() {
Serial.begin(250000);
timer = timerBegin(1, 80, true);
}
void loop() {
t_now = micros();
t_now2 = (long)timerRead(timer);
delayMicroseconds(Time_To_Read);
Serial.print((long)timerRead(timer) - t_now2);
Serial.print("\t");
Serial.println(micros() - t_now);
delayMicroseconds(10);
}
I tryed to change timer number with timer = timerBegin(x, 80, true); without effect.
Something I missed?
Thanks in advance,
Denis