Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

C# Digital Output updated data in precise intervals

Hello,
 
I am currently using the NI PCI-6220 M SERIES DAQ ( Item# 779065-01 ) with the BNC-2110 ACCESSORY ( Item# 777643-01 ). I am programming in Visual Studios 2005 with C# and the newest ( I believe ) version of Measurement Studios. I posted a somewhat similiar question previously, but I have revised what I am asking because I do not think I made it clear in the last post. What I need to do is write digital output in precise intervals of 1/40000 of a second. In between those outputs though, I need to update the data that will be outputted( the digital lines that will be turned on or off). So I need to:
 
1.) Do a digital write to Port 0 for all lines.
2.) Update the data array used for the write
3.) Output again at EXACTLY 1/40000 of a second from the time the write from step 1 was completed.
4.) Repeat.
 
What I am trying to do is:
1.)Turn on Port0/Line0
2.)Update data array to also turn on Port0/Line1 on next write
3.)Do the next digital write exactly 1/40000 of a second from when we turned on Port0/Line0, so that Port0/Line0 and Port0/Line1 are now both on.
4.) Continue doing these steps, turning on another line after each iteration untill all lines are on.
5.)After all lines are on, turn off Port0/Line7 1/40000 of a second from when it was turned on
6.) Update data array to turn off Port0/Line6 as well on next write.
7.) Do the next digital write exactly 1/40000 of a second from when we turned off Port0/Line7, so now Port0/Line7 and Port0/Line 6 are both off.
8.)Continue doing these steps, stepping down through the lines and turning each off untill all are off.
9.)Start over at step 1.
 
Now I know how to do a digital write. I have figured out how to make a digital pulse that will generate a pulse based on a static (predefined) set of data. It seems to me that all methods of synchronizing the digital output with AI or AO, or sharing the AI or AO sample clock only allow you to use a static (predefined) data set for output. I need to be able to output a dynamic (updateable) data set in precise intervals. Is it even possible to do this on a PC using your board? It seems the only way to even update the data would be to use a callback function, but that will not allow for precise timing since you hand control over to the PC's processor which is subject to interrupts and processor scheduling. If the callback function was to be called twice (or more) and update the data multiple times before the next digital write then the data will be totally off. Or vice versa, if the callback function is not called fast enough before the next digital write then the data will be off as well. Do you have any ideas for a way around this? I am at a dead end. I don't suppose I can use some sort of software lock (like a semaphore) that uses the onboard counter for a locking mechanism could I? I suppose that might work in the callback function to possibly (but probably not) solve the problem of multiple updates before the next output, but it wont solve the problem of multiple outputs before the next update. Any ideas would be very helpful. Thank you so much.
0 Kudos
Message 1 of 4
(3,227 Views)
Hi Brian,

It sounds like you know exactly what you want to write to the digital port at each time increment. Each set of digital states on the port can be converted to a integer. For more information on this, see the NI-DAQmx Help under NI_DAQmx Key Concepts » Reading and Writing Data » Selecting Read and Write Data Format and Organization » Digital Data (Integer Format). Since you know the array of integers which you want to write to the PCI-6220, you can write this array to the card before the generation actually starts and then have the port update from the transferred array. A function that you may want to look at is CNiDAQmxDigitalSingleChannelWriter::WriteMultiSamplePort().

This hardware timed digital output will require an clock to keep timing. This can be done by using a counter task which is set to generate a pulse at the frequency you want. This pulse can then be chosen as the sample clock for the digital output task. For more information on clocked digital generation, see the Digital I/O section in the M Series User Manual.

Regards,
Kent
Applications Engineer
0 Kudos
Message 2 of 4
(3,199 Views)
Hi Kent,
 
Thank you for your response. Once again I asked what I didn't mean to and realized it afterwards. I do understand that if I know exactly the information that I need to output during the entire program that I can put the data array onto the board before program execution. Here is exactly what my job eventually wants me to do ( you may have a laugh when you read it 😞
 
1) Read in from an AI at 40khz
2) Run these values through a computational algorithm
3) Output to multiple DO in exact 1/40000 of a second intervals with information that is based on the computed input information from step 2
4.) Do these operations simultaneously
 
To break it down and make it a little more simple, is it even possible with a non-deterministic machine to:
 
1)Output to a DO
2)Do a computation or lookup
3)Output again EXACTLY 1/40000 of a second later from the first DO, having the ports that are outputted to based on information from the calculation performed in step 2
 
It seems to me that this is completely impossible with a non-deterministic machine. As soon as you hand control over to the PC's processor, all notions of time precision will be lost due to interrupts and processor scheduling. Even with a deterministic machine, it seems it will still be incredibly difficult to achieve. I am pretty sure I am right and have had one of your engineers on the phone say the same thing. But I would like to get opinions from multiple people so that my boss does not think I am making this stuff up, as his expertise are in ME/EE and he is not very computer savvy. Basically my question boils down to this:
 
If I do not know ahead of time what data I will be outputting, is it possible to output in PRECISE (1/40000 of a second) time intervals? So output, calculate, output, calculate, etc., in precise time intervals.
 
Thank you.
 
-Brian
SDSM&T Adaptive Dynamics Lab
0 Kudos
Message 3 of 4
(3,189 Views)
Hi Brian,

You are correct in saying that your current setup will not be able to input signals, process them, and then output them at 40kHz. However, you may want to look at the R-series cards which have a FPGA. Since you can load your processing algorithms onto the FPGA, you should be able to achieve the deterministic output rates you need. I hope this gives you some direction for your project.

Regards,
Kent
Applications Engineer
0 Kudos
Message 4 of 4
(3,168 Views)