1
\$\begingroup\$

The C# application I'm working on needs to be able to be able to call a function within 5 milliseconds of a digital input signal's state change (0V = off, 5V = on).

Rather than using software to repeatedly poll that input's state, I would like some hardware to simply call a software function when the hardware detects a state change (like how hardware interrupts work).

Does anyone know how to do this (what ports to use) on a standard PC tower? Or does anyone know of any hardware peripherals that allow this functionality?

Occasional latencies are fine. I need <5ms average.

I basically need to take as many samples as possible of the input digital waveform. (preferably in the C# program, rather than in a peripheral micro-controller, although I am open to suggestions).

For instance, I found out the Labjack U3 can poll its digital input in less than a millisecond. This is a valid answer to the question, but I am interesting in more answers, especially ones that don't use polling or poll faster than 1ms.

High input impedance would be nice (digital inputs).

\$\endgroup\$
26
  • 3
    \$\begingroup\$ 2ms hard realtime response? Under Windows? \$\endgroup\$ Commented Jun 1, 2015 at 21:12
  • 1
    \$\begingroup\$ No way you are doing it. If you tell us the real problem, we might help you to come up with appropriate solution. \$\endgroup\$
    – Eugene Sh.
    Commented Jun 1, 2015 at 21:17
  • 2
    \$\begingroup\$ @ilkhd the C# or C++ program trying to do the data sampling and timestamping would have failed horribly at the task, as you say - but it has nothing to do with garbage collection. It's the operating system and the random 10ms delays come OS (kernel) level operations which ruin the performance \$\endgroup\$
    – KyranF
    Commented Jun 1, 2015 at 23:14
  • 2
    \$\begingroup\$ @ilkhd you must be doing something wrong mate, sorry. \$\endgroup\$
    – KyranF
    Commented Jun 1, 2015 at 23:19
  • 2
    \$\begingroup\$ @ilkhd My experience proves otherwise, you overestimate the delays. It may not be guaranteed performance but 1 minute random delays? No. I had amazing speed, zero delays, AND all running in a Windows Forms GUI application to boot. \$\endgroup\$
    – KyranF
    Commented Jun 1, 2015 at 23:27

3 Answers 3

2
\$\begingroup\$

Do you need to perform a specific real-time action, or just record the event?

If the former, you will never accomplish this using commodity hardware and consumer-grade interfaces. You will need both a laboratory-grade signal processor ( it will be a card that can access hardware interrupts directly) and a real-time operating system like VxWorks. A user-centric OS won't interrupt a disk write just because the USB bus wants some attention.

If the latter, get yourself a signal recorder and post-process the buffer output at your convenience.

\$\endgroup\$
1
  • \$\begingroup\$ I do not need to do anything in real-time, I simply need to time-stamp and record falling and rising edges, as they occur. I'm not sure what you mean by "signal recorder", but I really don't want do put the digital line into any ADCs, analog functionality is not really what I want. \$\endgroup\$
    – JoseOrtiz3
    Commented Jun 2, 2015 at 16:31
2
\$\begingroup\$

If your signal does not have too much of DC (long pauses with no data), use the sound card.

\$\endgroup\$
4
  • \$\begingroup\$ Explain why.... \$\endgroup\$
    – Null
    Commented Jun 2, 2015 at 0:50
  • \$\begingroup\$ @Null what exactly you want me to explain? \$\endgroup\$
    – ilkhd
    Commented Jun 2, 2015 at 2:43
  • \$\begingroup\$ My signal has long periods of low DC (10 seconds of low). A sound card is an innovative idea, however I would have to scale my digital input down to 400mV, and I don't really need all the analog capability, would be better to go directly to something with a Digital Input pin. \$\endgroup\$
    – JoseOrtiz3
    Commented Jun 2, 2015 at 16:29
  • \$\begingroup\$ @OrangeSherbet well, a standard modern PC does not have a buffered digital input. Sound card is the only option. to limit the digital signal all you need is a diode and 3 resistors. If you decide to go the sound card way, I'll explain how to deal with DC. \$\endgroup\$
    – ilkhd
    Commented Jun 3, 2015 at 1:33
0
\$\begingroup\$

I ended up using an Arduino Uno's Timer Input Capture Interrupt Service Routine to set data over USB to a C# SerialPort object immediately upon input capture. The SerialPort fires a serialdatareceivedeventhandler immediately upon detecting an End Of File Character (0x1A), and a new thread launches to process the input data (such as assigning a timestamp to it).

To all the neighsayers, What the Heck? Obviously you were wrong that it couldn't be done.

\$\endgroup\$
2
  • \$\begingroup\$ Have you verified your max 5ms latency?? \$\endgroup\$ Commented Jun 11, 2015 at 18:04
  • \$\begingroup\$ I'm not sure how I would measure that (how to synchronize arduino and computer...), but it appears that I have a resolution of about 2 milliseconds (not latency, instead that's how much the latency varies). I really needed a latency that didn't vary by more than a few milliseconds, a constant latency was desirable. \$\endgroup\$
    – JoseOrtiz3
    Commented Jun 11, 2015 at 21:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.