i want to stop the execution of my .net application for about 20nanoseconds
so i am trying to measure time needed for specific samples of code, and i want a code that takes only 20nanoseconds, can any one help please????
because i want to interface 3 wire spi analog switches with parallel port
and this is the time to wait between high and low of the clk signal that has a maximum frequency of 30MHz.
so do you think i can use less clock frequency so as to have greater time period the switches i have has a maximum frequency of 30MHz, do you think i can use less than that??
There's a lot of confusion around here about Timers and Ticks. For a start, there are two kinds of Tick in dotNet: DateTime ticks which are 100 nanoseconds, and Stopwatch ticks which depend on the hardware but are typically 280 nanoseconds or so (on >="Vista ready" PCs, which have high-res timers).
Both of these are the smallest units for representing time, but they do not have any bearing on the accuracy of measuring time. Even a stopwatch, supposedly the most accurate measurement, has an overhead of about 8 ticks just to read it, as you can easily tell by running the following code:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
That means you can't even measure time anything more accurately than about 8 ticks or 2 microseconds.
When it comes to doing anything with those measured timings it's a different ballpark. Managed languages like VB.Net and Csharp are event based, and events can only be fired with an accuracy of about 55 milliseconds. The Forms.Timer, which fires on the GUI, is prone to interruption by other threads, so it may be even less accurate. The Timers.Timer is more accurate because it fires on its own thread, but you can't use it to Refresh (only Invalidate) the GUI. Timer intervals as low as about 10 milliseconds can still be useful, but they cannot be relied on to be regular.
Windows also has a timer called the Multimedia Timer, which is used for things like high-speed game loops, video and audio. According to msdn it provides the most accurate timing possible with the given hardware, and suggests intervals like 1 millisecond are achievable. You can only use it directly from unmanaged code (C++ or the like) or indirectly though DirectX, WPF, XNA etc. There are several articles on the CodeProject by people who claim to take advantage of the MM timer in Csharp, but I wonder whether they are really useful.
To sum up, there is no way of triggering anything like a nanosecond delay in VB.Net. Of course, if you have special hardware with a 50MHz clock, you might be able to start and stop it with VB.Net.
BB
Last edited by boops boops; Dec 31st, 2010 at 08:11 AM.
Reason: 2 microseconds, not 20
No, you will never get such resolution without any real time extensions or a hardware solution.
Regardless, what you are trying to achieve with a parallel port is impossible: you will need additional hardware.
"Ok, my response to that is pending a Google search" - Bucky Katt. "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk. "Before you can 'think outside the box' you need to understand where the box is."
Why do you think you need an 'external clock' of 50mhz? What is it you are trying to do?
That kind of frequency is in the high speed DAQ range, where hardware costs range from a few hundred to $10k or more.
The hardware required is dependent on what you want to achieve.
"Ok, my response to that is pending a Google search" - Bucky Katt. "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk. "Before you can 'think outside the box' you need to understand where the box is."
what am trying to do is to use my parallel port to interface 3 wire spi analog switches, because i can't afford the cost of an spi interface,
so i thought of programming it by myself. the clock for these switches has a maximum frequency of 30MHz, now am thinking of using less frequency and i don't know if it will affect the performance of these switches????
i have been working in this project for 5 months and i have only one month left and am stuck !!!!!
You cannot come close to that resolution. AND there is no reason to try.
1. The latency/timing uncertainty in dlls used to access the parallel port far exceed 20 nS. A single statement of even the simplest form (probably) exceeds 20 nS
2. Parallel port hardware is not capable of the 30 MHz speed that you want - not even close (1 MHz, perhaps).
Dick
Richard Grier, Consultant, Hard & Software
Microsoft MVP (Visual Basic)
Okay, You meant SPI not spi (I thought spi was a spelling mistake): as in Serial Peripheral Interface?
Why not simply work up from 1 second clock cycle and see how far you get before your bus becomes unstable through the parallel port?
Because of the highly synchronous nature, you aren't going to achieve anything remotely close to the Khz range. Unless there's a lower limit on clock frequency, you can at least get your protocol established and tested.
The frequency specced is an UPPER frequency limit at which performance will degrade. I would suspect the lower frequency limit is effectively DC; you can test that with physical switches (this is all assuming you know what you are doing, electrically).
"Ok, my response to that is pending a Google search" - Bucky Katt. "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk. "Before you can 'think outside the box' you need to understand where the box is."