nano second counting

t_n_k

Joined Mar 6, 2009
5,455
How we can make a counter with accurate nanosecond and picosecond steps measurement
Pretty small time frame. To put it in some sort of context, in one picosecond light travels about 300 μm.

That's getting to be quite sophisticated technology. There are oscilloscopes commercially available with timebase control down to that order of magnitude. Interval counters with similar specs are also available.

The attached link is to a paper which discloses a PC based system with 200ps resolution.

http://www.dtic.mil/cgi-bin/GetTRDoc?AD=ADA427911&Location=U2&doc=GetTRDoc.pdf
 

beenthere

Joined Apr 20, 2004
15,819
Good luck. Apparently Intel has pushed a processor to just over 5 GHz using LN2 cooling. That is a clock pulse width of around 100 picosceonds (50% duty cycle). To do counting, though, some internal register must be able to increment at the rate you wish. Programming is not a really significant factor.

What is your interest?
 

Thread Starter

sytem_recon

Joined Apr 21, 2009
52
I tried to count in C++ and assembly but the problem is that in actual the processor ticks with clock of Mhz and Ghz is only processor cycles so to count in ps or ns i have some problem. I have an application that has totla time to run is from 2ns to 12ns and i want measure that with computer so how i can do that.
 

eng1ne

Joined Dec 4, 2009
97
I am certainly no expert in computer programming or computer engineering but 2 ns is 500 Mhz.

What processor does your computer have?

As I understand it, the actual clock on even the more recent Intel Core i7 is only 133 Mhz.

The Ghz speeds for processors are quoted based upon an internal multiplier. If the internal multiplier is 24 on a 100 Mhz clock, the processor is said to run at 2.4 Ghz.

Presumably, if you can gain acess the internal clock speed, i.e. 2.4 Ghz or whatever your processor runs at then you would have a pretty good resolution.

How to access it... (if it's at all possible) is not something I can help you with!

You could however, find a 500 Mhz oscillator (example) and interface with that - but then your problem is finding some application quick enough to read it!
 

Papabravo

Joined Feb 24, 2006
21,225
In order to count in those time frames you need to find devices that can be clocked at those rates. I don't know of any current logic family that has flip-flops that clock at over 1 GHz. In my recollection 500 MHz. is about the top for F-series or ECL logic.

Next on my list of things to research would be a CMOS FPGA with a low core voltage and the capability of using a high speed clock. I hope your pockets are deep because I don't think this is going to come on the cheap.

Other than that I believe you are SOL, unless you know something that all of us do not. In the words of Judy Tanuta: "It could happen!"
 

eng1ne

Joined Dec 4, 2009
97
You are doing the project so you are likely to have investigated our solutions and your own.

Yes it's possible - but with your resources, I don't know! Only you can comment.

Naturally then, you should tell us if it's possible.
 

CVMichael

Joined Aug 3, 2007
419
I don't understand why does it have to be a processor that does the counting ?

All you need is some flip flops that are fast enough. And if not, then find some transistors that are that fast, and make your own flip flops.

Since for every flip flop the frequency gets cut in half, then only the first few have to be fast.

Reading the bits on the flip flops will be tricky, you have to "freeze" (or just stop counting) while you read the bits using a slower processor.

I think it all depends what you need this for.
 

davebee

Joined Oct 22, 2008
540
Is this on a Pentium or a related CPU? If so, then have you tried accessing the RDTSC register before and after the code runs to get the count of CPU clocks that the code took?

I've used that instruction in the past on older pentiums. But even on the older CPUs, it was sometimes hard to get the correct permissions to execute the instruction, and I remember warnings about pipeline flushing that I didn't completely understand. I don't even know if the newest CPUs even still support that instruction, or allow users access to it.

But if you can access it, then it will tell you how many CPU clock ticks have elapsed between any two reads of the register, which sounds like what you need. That will be sub-nanosecond resolution if you're running a machine with a clock over a gigahertz.

I think it does funny stuff like flushing the CPU pipeline when it is called, but for your purposes that may not matter.
 
If you wish to use a computer for high frequency counting, then I recommend using the API suitable for your operating system.

If you are using Windows, almost everyone uses the QueryPerformanceCounter() and QueryPerformanceFrequency() functions. As mentioned here, it has a frequency of 838 ns at its minimum resolution. It may in fact be better.

Here is some code that uses QueryPerformanceCounter() to get you started:

Rich (BB code):
__int64 freq, start, end, diff;

// start
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
QueryPerformanceCounter((LARGE_INTEGER*)&start);

// code to measure
Sleep(1234);

// end
QueryPerformanceCounter((LARGE_INTEGER*)&end);
diff = ((end - start) * 1000) / freq;

unsigned int milliseconds = (unsigned int)(diff & 0xffffffff);
printf("It took %u ms\n", milliseconds);
(taken from here)

If programming on Linux, I have used clock_gettime() function and it works well. Here is some reference on that.

Basically, I would avoid using any code that is dependent on the CPU clock frequency. What happens when you give your program to a friend whose CPU is slower/faster than yours? Then it won't work. Sure, you can try to determine the CPU frequency before running the dependent code, and then scaling the count as appropriate... But really that would only work if the CPU is faster. If it is much slower, then it may not provide resolution required.

It is almost always preferable to use the timing APIs provided by the host operating system than to roll your own, since in a multi-tasking environment your application does not necessarily get real-time updates and also, the OS writers likely know more about interacting with what's under the hood than you do. However, if you do have a RTOS, or raw timing hardware, then you've taken out a lot of the variables (like the effects of other programs running in the background) and it is easier to work with.

But as you mentioned in an earlier post, you seem to want this high resolution clock accessible on a computer platform. In which case, you are advised to use the API functions I listed above (e.g., QueryPerformanceCounter, if using Windows, and clock_gettime if using Linux).

Here are some additional links:

http://www.songho.ca/misc/timer/timer.html

http://www.devx.com/cplus/Article/35375/1954
 

sceadwian

Joined Jun 1, 2009
499
Perhaps trying to contact a moderator might be in order. A post in the forum is probably not a good idea, they don't moderate every single last post that comes through so they might not see this one. Use the boards contact section to leave a message to a moderator.
 
Perhaps trying to contact a moderator might be in order. A post in the forum is probably not a good idea, they don't moderate every single last post that comes through so they might not see this one. Use the boards contact section to leave a message to a moderator.
Ah, it seems the message has been posted now. It just took longer than expected (~23 hours).
 

sceadwian

Joined Jun 1, 2009
499
I don't know how this forum operates, but it would be common practice on a generally open forum to have posts containing certain keywords or combination of them to go to a moderator que. There may have been nothing wrong with your post but it went to the que because of whatever words triggered it, probably at the bottom, and after 23 hours it expired and went to the forum.
 
Top