ard_newbie:
When the light is emitted, you start a timer counter, and as soon as the photodiode detects the arrival of light, you trigger an interrupt and stop your timer.
I can find a TIMER1 CAPT (timer capture event interrupt). This can be for detection of signal at photodiode. But I could not find how to initiate the timer as light is emitted.
anshul_p:
I can find a TIMER1 CAPT (timer capture event interrupt). This can be for detection of signal at photodiode. But I could not find how to initiate the timer as light is emitted.
You probably need to find out in general what the arduino is capable of ..... in terms of what minimum time differences between interrupts that an arduino can measure relatively accurately. If the arduino doesn't have the resolution you need, then you might need a dedicated timer circuit system --- designed by yourself, or some available one from somewhere.
anshul_p:
Sorry I did not measure the speed of light in fiber. I do not have means to calculate it. I assume it to be 3x10^8 m/s. btw why do you ask so??
Well no. Assuming you have single mode, silica fiber, then the speed of light is gonna be closer to 2x108 m/s. If it's not single mode c(fiber) will be even slower, and less precise (that is a pulse after 3km will be much wider coming out than it was going in.) If you know your fiber's characteristics, you won't need to measure the time, you can calculate it.
Plus, is your fiber coiled on a spool, or are your transmitter and detector separated by 3km? The signal from one to the other (or from both to a point in between) will also take an appreciable amount of time.
Not saying this can't be done. In fact, it's done all the time, but the calcs are not quite s simple as they first seem.
AWOL:
If you think about it, the best you can hope for is a single clock cycle - 62.5ns, or about 20 metres.
If it's through clear quartz (aka silica) with an index of refraction (n) of about 1.4, a pulse will only go 13 meters in 62.5 nanoseconds. Most fiber optics are made with silica. Some are plastic, and c only gets slower.
anshul_p:
But can i measure time between triggering of laser diode(through digital pin) and reading photodiode (at analog pin) using timer1??
Of course. Easiest is to set the TCNT1 register to 0 the moment you trigger your laser (use direct pin register writes rather than the slower digitalWrite to handle the pin). Then whatever value TCNT1 has the moment the pulse comes back, that's the time it took in clock cycles, assuming you set the TCCR1x registers to no prescaler.
There will be a few clock cycles delay between setting the pin and the register, but this is a fixed number so can easily be corrected for.
wvmarle:
Of course. Easiest is to set the TCNT1 register to 0 the moment you trigger your laser (use direct pin register writes rather than the slower digitalWrite to handle the pin). Then whatever value TCNT1 has the moment the pulse comes back, that's the time it took in clock cycles, assuming you set the TCCR1x registers to no prescaler.
There will be a few clock cycles delay between setting the pin and the register, but this is a fixed number so can easily be corrected for.
Ok
can I get any tutorial on how to use timer1 function??
Being new to arduino programming, I am not able to think how to use it with my code.
This is actually beyond Arduino (which abstracts this with the convenient millis() and micros() timer functions), this is a processor specific topic. Assuming you use the Uno or derivative you have to look at the ATmega328p processor. Download the data sheet if you didn't do so yet - all the info you need is in there, a great reference.
And of course lots of tutorials out there. As far as I know the Timer1 works identical for all ATmega processors, but there may be differences so beware when looking at tutorials about other ATmega processors. The pin for the input capture interrupt is also processor specific.
Late to the party but I have used the AMS GP22 to accurately measure very short durations of the time a pulse took to travel down a length of open ended wire and the reflection coming back. From the below image you can maybe see I could mostly calculate the cable length to within a centimetre.
You would need to know the velocity factor of your fibre optic cable to calculate the speed of light in the fibre.
I need find error on power cable witch one lenght is 50m. I need precision 1ns for find error with precision 30cm. I like do it with Arduino with frequency 16MHz, or with ESP with frequency 160Mhz. But it look, i and also guy with optical fibre, we need any external counter with incrementing of bits every 1ns, so with frequency 300MHz and after signal is comming back, counter will stop. And we can read it from device/counter from LED's on the top or also with beloved Arduino.
Or decompose laser measure meter and make measurment device from this?
Also, on page Riva posted about AMS GP22 is:
" TDC-GP22 1K T&R
starting with $3.22*
*per unit for 1,000 units and above Not in stock"
This is no way.
for 1 ns resolution you need at least 1 GHz clock frequency.
The AMS GP22 is available as "evaluation kit" at ¥690 or "demo kit" at ¥2350 on Taobao; likely can be found on Ebay, Amazon, Aliexpress etc. as well. You obviously don't know what you're up against with this job so buying bare chips is just about the last thing you should consider.
don't hijack - start your own thread for new questions.