Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

detecting changes in digital I/O lines

I am currently using the digital input lines on a DAQ6225 to poll for changes in the input line.  I would like to eliminate this "polling' process as changes in the digital input lines are being missed by my application.   My application is written in C++ and uses NIDAQmx.
 
My requirements are fairly simple.  All digital input lines will typically be held low.  At varying times intervals ( >50ms) 1 or more of the input lines will be set high for about 1ms and then set low again.   I would like to be able to determine which lines were set and the time at which this occurred.
 
1. The 6225 has 80 analog input channels which can be sampled continuously.  Can the digital input lines also be configured so that they are sampled continuously.  If so could this approach be used to determining what digital input lines have changed as well as the time at which they changed?  If this is the case, would you be able to refer me to sample C/C++ code that illustrates how this is programmed?
 
2. I would like to eliminate the processing of polling the digital input line and replace it with, say, an interrupt based process.   For example, when a selected line goes high, this would generate an interrupt which would then execute my callback routine.  I believe the comparable operations on the NI digital I/O cards are referred to as 'pattern matching' and 'change detection' and that they might provide a solution.  How does pattern matching work?  How does change detection?  What is the difference between them? 
 
 
 
Thanks in advance,
 
Ian
0 Kudos
Message 1 of 14
(5,936 Views)
Ian,

What you want is a "Change Detection" operation, which your M Series card supports as of NI-DAQmx 8.0. Please check the ReadDigChan-ChangeDetection.c example located in the C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Read Values\Read Dig Chan-Change Detection directory. By configuring "risingEdgeChan" and "fallingEdgeChan" in the DAQmxCfgChangeDetectionTiming function, you indicate when you want to latch the state of the lines specified in the task. More information can be found in the NI-DAQmx C Reference help.

"Pattern Matching" is a little different as it can be used to start a hardware-timed digital operation whenever the state of the port matches a certain pre-defined pattern.

In your case, it sounds like change detection is the best method. In order to get accurate timestamps of when the data was latched, you will need to call the DAQmxReadDigitalLines() function with the numSampsPerChan input set to a single sample. Whenever this function returns, you should query Windows for the time. This will be the closest to "timestamping" that you can get. In this manner, you application will wait at the DAQmxReadDigitalLines() function call until the device detects a change, signals the driver, and the driver returns the data to your application.

Hope this helps,


Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 2 of 14
(5,907 Views)
Hello Ryan,
 
If I understand correctly, the idea behind change detection is simply that the state of the selected digital input lines are latched on the rising and/or falling edges.  Is this correct?  The NIDAQ function DAQmxReadDigitalLines waits until the specified number of samples are recorded and then returns to the calling function.  Is this correct?  
 
The sample you referred me to, 'Read Dig Chan-Change Detection' sets the driver to record a sample on both the rising and falling edges.  In the case where an input line is held high for a few microseconds and the pulled low, this suggests that the function DAQmxReadDigitalLines  will return 1 sample for the rising edge signal and then the same sample value for the falling edge value.  Is this correct?
 
The function DAQmxReadDigitalLines  is passed a timeout value.  If a timeout occurs and then immediately after the timeout a line change occurs, is the line status still latched or is it missed?
 
Thanks for your assistance
 
Ian
0 Kudos
Message 3 of 14
(5,897 Views)
Ian,

You are correct on all accounts. Additionally, if you specify -1 samples to read, the function will return all samples available in the buffer at the time of the read. If you specify a -1 as the timeout, the function call will wait forever for the requested number of samlpes. With a finite timeout value, If you do timeout, the task will continue to run and subsequent changes should be latched. Finally, if you want a callback whenever changes do occur, take a look at the ReadDigChan-ChangeDetectionEvent.c example located in the C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Events\Signal\Change Detection\Read Dig Chan-Change Detection Event directory. This should provide the event-based functionality you desire. Please let me know if you have any additional questions.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 4 of 14
(5,884 Views)
Hello Ryan,
 
This is what I was looking for.   Thanks! 
Ian
 
0 Kudos
Message 5 of 14
(5,875 Views)
Hi Ryan,

This thread has been interesting.

But going by the past experience I think one needs to go for the right hardware if he is looking to be able to react to a change Detection event. For instance I have two cases where I used PCI-6229 + LV7.1 and required one such facility at a later stage. ( The state Machine is updated inside of a 50ms timed loop ) and there was no gurantee that I will read a specific digital input accuratley  and  stop a drive. Thus the stopping point was never sharp and got worse as the traverse speed was increased.

I would have simply loved some kind of interrupt facility on such a powerful software as LV to work with ANY of  thier DAQ cards..

Regards

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 14
(5,823 Views)
Hello Raghunathan,
 
Thanks for leaving your posting.  In your opinion, did you find the change detection mechanism to be useful or did you end up discarding it and using a work around solution?  You mentioned the stopping point was never sharp - what type of response times did you get (e.g. < 1ms, < 50ms, < 100ms)?
 
Ian
0 Kudos
Message 7 of 14
(5,818 Views)
Raghunathan,

Actually, with NI-DAQmx 8.0, you can now dynamically register DAQ events and handle them with LabVIEW's event structure. Try wiring a task to a "Register for Events" node, you will be given the option of selecting which event. If you chose signal, you can then set the signalType to be a change detection event. This sounds like it would work perfectly for your application. For an example of how to use DAQmx events, have a look at the Acq&Graph Voltage-Int Clk-EveryN&DoneEvent.vi shipping example. Let me know if you have any questions.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 8 of 14
(5,804 Views)
Ian,

I don't have any benchmarks, but provided your computer is not doing much else, I would expect a response time on the order of milliseconds, if not lower. Do you have any results yet?

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 9 of 14
(5,804 Views)

Hello Ryan,

I have not yet implemented and tested the change detection.  I am finishing up a project and expect to begin working with the change detection in 2 weeks.   At that point I will likely have a few more questions for you.

 

Ian

0 Kudos
Message 10 of 14
(5,798 Views)