# Arduino Forum

## Topics => Science and Measurement => Topic started by: Jimanator on May 07, 2018, 07:36 am

Title: Measuring nanoseconds
Post by: Jimanator on May 07, 2018, 07:36 am
Does anyone know of any arduino attachments
that can keep track of the amount of nanoseconds that have passed? I know that
there is the Millis() and Micros() function but I would like to have the functionality of a Nanos() function.

Thanks
Title: Re: Measuring nanoseconds
Post by: TolpuddleSartre on May 07, 2018, 09:11 am
Multiply micros() by 62.5
Title: Re: Measuring nanoseconds
Post by: ard_newbie on May 07, 2018, 01:04 pm
Multiply micros() by 62.5
That is weird math !!

If the OP wants to measure nanoseconds, I guess that's because he needs a precision of a few nanoseconds.

With AVR arduinos  clocked at 16MHz, you can't expect this precision. With an arduino DUE clocked at 84 MHz, the best you can expect is a 12 ns precision. Therefore the question is : what sort of nanoseconds precision are you looking for ?
Title: Re: Measuring nanoseconds
Post by: Jimanator on May 08, 2018, 12:07 am
I need to go as precise as 1 nanosecond. I know the arduino can't do it on its own, but do you know of any realtime clocks or anything that I can connect to it? I've looked but no luck.
Title: Re: Measuring nanoseconds
Post by: AWOL on May 08, 2018, 12:17 am
A 16 MHz Arduino executes its fastest instructions in 62.5 ns.
The fastest it can respond to any external stimulus is therefore at least 62.5 ns.

If you need to record shorter times, you'll be looking at external hardware.

Title: Re: Measuring nanoseconds
Post by: Jimanator on May 08, 2018, 02:21 am
So, basically I am trying to get the difference in time received  between 2 rf pulses from the same source. All I need is a timestamp from each in nanoseconds to be passed to the arduino. The arduino will do the math for the 2 timestamps to get the difference, that part is fine if it is slower. I did the math and as long as the receiver is more than 0.26 meters from the transmitter it  won't be quicker than a nanosecond, so I don't need to worry about picoseconds.

What sort of external hardware do you mean?
Title: Re: Measuring nanoseconds
Post by: jremington on May 08, 2018, 04:45 am
To get 1 ns time resolution, you will need some pretty high end hardware for the "front end".

A programmable gate array with a clock rate of 10 GHz or higher should be serviceable.
Title: Re: Measuring nanoseconds
Post by: slipstick on May 08, 2018, 01:53 pm
I did the math and as long as the receiver is more than 0.26 meters from the transmitter it  won't be quicker than a nanosecond, so I don't need to worry about picoseconds.
Surely it's the difference in distance of the two receivers that counts not the distance from the transmitter. If the difference is always considerably greater than 0.3m then you don't need better than nanosecond resolution otherwise...

Steve
Title: Re: Measuring nanoseconds
Post by: larryd on May 08, 2018, 09:22 pm
This is not a Arduino solvable problem.

Title: Re: Measuring nanoseconds
Post by: Jimanator on May 08, 2018, 11:54 pm
Thanks for all the info. I just don't understand why if a 16 MHz clock can do 62.5 ns, why do I need to jump all the way to 10 GHz to get 1 ns?
Title: Re: Measuring nanoseconds
Post by: jremington on May 09, 2018, 12:17 am
Assuming a gate array or computer takes, say 10 processor cycles to recognize and store event times to a resolution of 1 nanosecond (1 GHz rate), then the processor clock must be at least 10 times faster.

The Arduino doesn't "do" 62.5 nanoseconds. That simply the time for one cycle of the processor clock. See above.
Title: Re: Measuring nanoseconds
Post by: pito on May 29, 2018, 10:29 pm
You can measure ~nanoseconds with arduino.
You would need an additional piece of hardware, a pulse_width ->voltage converter.
Title: Re: Measuring nanoseconds
Post by: MarkT on Jun 07, 2018, 09:30 pm
Sometimes phase differences are easier to measure than time differences. Perhaps a phase detector
could be part of the mix - but we need to know much more about the problem.  For instance 2 isolated
RF pulses have very poor temporal resolution if the bandwidth is low or the signal/noise ratio is poor.
Title: Re: Measuring nanoseconds
Post by: allanhurst on Jun 26, 2018, 01:00 am
What frequency is your RF? What risetime are the pulses? What detector electronics are you using?

I suspect an X-Y problem - Further details required.

Any way an arduino isn't going to be a lot of help except as a display driver.....

Allan
Title: Re: Measuring nanoseconds
Post by: wvmarle on Jun 28, 2018, 12:54 pm
GPS receivers do better than 1 ns. In a way. They receive signals of 1.5 GHz and measure difference in flight time down to a single wave, so that's less than 1 ns. Unsure what OP really tries to accomplish but it appears to be some kind of time of flight measurement.
Title: Re: Measuring nanoseconds
Post by: MarkT on Jul 05, 2018, 12:58 pm
The GPS hardware that does that is not a 5V 20MHz CMOS part!  And its using correlation primarily,
ie phase measurement, not time measurement.

If you want time of flight with RF then you're asking for something like pozyx.io or one of the UWB chips
that are starting to appear.

UWB = ultra wide band, which is what you need for time of flight - narrow band has very poor time resolution
by its very nature.