Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect DIO line change on PCI-6250

Using Visual C++ how can I detect when a digital line goes high on a NI PCI-6250 M-series board? I want to make a loop that will cycle each time a digital input goes high (with millisecond or better accuracy).
Thanks,
Mark
0 Kudos
Message 1 of 7
(3,926 Views)
Hello Mark,

I don't know of a way that the DAQ board can "trigger" your while loop to execute. You will have to do a software poll of the line and monitor if the digital input goes high (or you could setup a counter operation if you are interested in detecting edges). This will have millisecond accuracy at its best because that is the resolution of the system clock. I hope this helps!
Eric
DE For Life!
0 Kudos
Message 2 of 7
(3,923 Views)
Hi E. Lee,

Thanks for the reply. If I want to detect edges, what kind of counter operation are you suggesting? I would be interested in having my VC loop controlled by the speed of a counter. The Lab View "Timed Loop" seems to do this, so would it be possible to also do this in VC?

Best Regards,
Mark
0 Kudos
Message 3 of 7
(3,911 Views)
Actually, there are two ways to do this, if your card supports Digital Change Detection timing. Unfortunately the PCI-6250 does not, but the following cards do: PCI-6509, PXI-6509, PCI-6510, PCI-6511, PXI-6511, PCI-6514, PXI-6514, PXI-6514, PCI-6515, PXI-6515, PCI-6518, PCI-6519, PCI-6527, PXI-6527, PCI-6528, PXI-6528, PXI-6533, PCI-6533, PXI-6534, PCI-6534, and perhaps others.

In any case, if you do have one of these cards with hardware support for Digital Change Detection timing, then you can do one of the following:
a) Create a DI channel on your task, and then configure digital change detection timing using CNiDAQmxTiming::ConfigureChangeDetection(). Then perform either synchronous or asynchronous single-sample reads; when one of the digital lines of interest changes, then the blocking synchronous read will finish or the asynchronous read will call your callback. This is demonstrated with the Digital \ Read Values \ ReadDigChan_ChangeDetection example.
b) Create a DI channel on your task, configure digital change detection timing, and then set up a Digital Change Detection event on the task. This is demonstrated with the Digital \ Read Values \ ReadDigChan_ChangeDetection_Events example, although (a) is the preferred method.

Since the PCI-6250 doesn't support hardware digital change detection, what you have to do instead is to continuously read the status of the digital lines, and check to see if the lines went high programmatically. If you do not explicitly configure the timing for the acquisition, then the timing mode will be on-demand and the data will be read as fast as possible. You also have the option of calling CNiDAQmxTiming::ConfigureSampleClock() to configure the clock rate based off of another signal, such as PFI7. Here's a sample:


try
{
CNiDAQmxTask t("");

t.DIChannels.CreateChannel("6250/port0/line7:0", "", DAQmxOneChannelForAllLines);
t.Timing.ConfigureSampleClock("/6250/PFI7", 0,
DAQmxSampleClockActiveEdgeRising,
DAQmxSampleQuantityModeContinuousSamples, 1);
CNiDAQmxDigitalSingleChannelReader reader(t.Stream);

bool stopLoop = false;
while (!stopLoop)
{
CNiBoolVector data;
reader.ReadSingleSampleMultiLine(data);

for (unsigned int i = 0; i < data.GetSize(); i++)
{
if (data[i])
{
MessageBox("Went high.");
stopLoop = true;
break;
}
}
}
}
catch (CNiDAQmxException* ex)
{
ex->ReportError();
ex->Delete();
}

Hope this helps,
Hexar Anderson
Measurement Studio Software Engineer
National Instruments
Hexar Anderson
Measurement Studio Staff Software Engineer
National Instruments
Message 4 of 7
(3,894 Views)
Hello Mark,

You could do simple event counting to count the number of edges that are arriving at the counter. Instead of polling the state of the digital line, you would just poll the value of the count register. I do not know of any way to implement the LabVIEW timed loop in VC. I would take a look at the code that Hexar posted to see a good way to monitor the line.
Eric
DE For Life!
0 Kudos
Message 5 of 7
(3,889 Views)
Thanks for the code and answers guys,   If I want to be able to trigger a software loop written in C++ with a clock on a National Board, what board would you suggest using.  Is a card with Digital Change Detection timing what I want, or is polling just as good or better?  I plan on using a 3Ghz PC with a PCI Express bus.

I want to be able to trigger several software threads all at the same time based on an input clock or the clock of an IO board.
Thanks,
Mark
0 Kudos
Message 6 of 7
(3,786 Views)
Hello Mark,

The DIO help file has information on which boards support change detection with DAQmx 7.4 (and later) using text-based languages.  Just do a search or look in the index for "change detection"

The 6527 is very similar to the 6528, and it also supports change detection.

The 653x boards also support change detection in DAQmx 7.4 (and later), but they will be able to acquire changes much more quickly than all of the other boards because they can store some number of samples on the board instead of relying on a software transfer for every sample.

I don't think any of these boards are offered in the PCIe form factor, so hopefully you have some PCI slots in your computer 😄

You can find out more about change detection my looking at the DAQmx Help file as well as the DAQmx C Reference Help file.  There are also some text-based examples of change detection that install with the NI DAQmx driver.


Eric
DE For Life!
0 Kudos
Message 7 of 7
(3,774 Views)