ISR timing and measurement question

I am transmitting a pulse from PIN9 on an UNO and I am counting a series of pulses returned with an ISR on PIN3. Is it possible to determine the time when the pulses start and finish? I am getting consistent readings but the time WHEN they call the ISR varies. I am watching the transmit and receive signals on an oscilloscope and I can see the gap opening and closing between the send and receive pulses. How do I measure that gap? This is the value that I need to measure in my experiment.

Thanks,

What is the length of time gap are you trying to measure? You should be able to store a value of micros() when the pin 9 signal is sent. Then the first thing to do in the ISR is to record another value of micros(). Micros() only has a resolution of 4 us.

If micros() is not going to give you the precision you need, you should be able to use Timer1 input capture mode. You could enable the counter when the pin9 signal is sent, and capture TCNT to the first rising edge seen in the reply.

use a long type variable that is volatile to store the millis() in the interrupt vector function (millis method puts out the amount of time since the arduino was powered on/reset) and then in the loop() again store the millis() in another long type variable , deduct the bigger one from smaller one to get the time spent in the interrupt.

I am starting to see that I need to measure this differently than I originally thought. Once I send the pulse from PIN9 there is about a 100 microsecond delay before the first receive pulse is measured. The receive pulses ring for about 475 microseconds. As my sensor reading changes this group of pulses moves out to span from 475 microseconds to 1000 microseconds. The period of the pulses is consistent, its the time that changes. Do I need to use micros() at each pulse to determine the ballpark time frame and subtract from a starting micros() point? Not sure how to proceed...

Pulses/micros() or counts per 100us snap shots?

There's not enough information to really say. What is the frequency and individual widths of the "ringing" set of pulses. How precisely do you need to measure the width of the whole set? What else is your sketch doing when this is happening?

You may be able to just poll like crazy and store the values of a hardware timer for when the pulses start and stop.

jboyton:
There's not enough information to really say. What is the frequency and individual widths of the "ringing" set of pulses. How precisely do you need to measure the width of the whole set? What else is your sketch doing when this is happening?

You may be able to just poll like crazy and store the values of a hardware timer for when the pulses start and stop.

The pulses are approximately 20us in width. I would like to know WHEN they are starting and stopping. And if possible how many... Thanks for your advice!

Is it an animal vegetable or mineral?

jboyton:
Is it an animal vegetable or mineral?

Hahaha! I wish 20Q could help...

Turnbull22:
The pulses are approximately 20us in width. I would like to know WHEN they are starting and stopping. And if possible how many... Thanks for your advice!

Look at the Input Capture feature of Timer/Counter1. When it sees the relevant edge (RISING or FALLING) It will store the timer count in a register and signal an interrupt. In the interrupt you read the register and save it in an array, then flip the edge type (from RISING to FALLING) and return. Each edge will record the time. If the counter prescale is set to 1 you will be recording times in 1/16th of a microsecond intervals.

The Input Capture pin for Timer/Counter1 is PORTB bit 0 (Arduino Pin 8). No other pin can be used for this.

johnwasser:
Look at the Input Capture feature of Timer/Counter1. When it sees the relevant edge (RISING or FALLING) It will store the timer count in a register and signal an interrupt. In the interrupt you read the register and save it in an array, then flip the edge type (from RISING to FALLING) and return. Each edge will record the time. If the counter prescale is set to 1 you will be recording times in 1/16th of a microsecond intervals.

The Input Capture pin for Timer/Counter1 is PORTB bit 0 (Arduino Pin 8). No other pin can be used for this.

Thank you John, I will give this a shot today and post my results! I appreciate your response.

Rob