How can I control sampling rate from C#, i.e of times I read a variable in a sec
-
I need help in controlling the sampling rate of different pins/channels on a parallel 32 pin interface So my question is how can I set the hertz or sampling rate to read a variable or a certain register. ;P
-
I need help in controlling the sampling rate of different pins/channels on a parallel 32 pin interface So my question is how can I set the hertz or sampling rate to read a variable or a certain register. ;P
Three ways in C#: 1. you can use a timer to get an event at some rather low frequency (well below 1 kHz); it wouldn't be very reliable, there would be some jitter (you might want to read my timers article). 2. you can choose a realtime thread priority, and cause a busy loop to monopolize one CPU core to read a parallel pin at high frequency (hundreds of kHz); the exact frequency would depend on the number of instructions in your loop and your CPU frequency. 3. you can provide an external clock, then choose a realtime thread priority, and cause a busy loop to monopolize one CPU core to read a parallel pin at high frequency (hundreds of kHz). By waiting on the external clock, your code would be independent of the exact instructions and your CPU frequency. Other ways would include writing a specialized driver (not in C# though). None of the above is likely to be acceptable as far as behavior and results quality go. If you want to create say an oscilloscope, you need more external hardware, including some memory, so the communication doesn't have to be real-time at all. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.