Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I control sampling rate from C#, i.e of times I read a variable in a sec

How can I control sampling rate from C#, i.e of times I read a variable in a sec

Scheduled Pinned Locked Moved C#
questioncsharphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    longnights
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • L longnights

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups