Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Syncronized Digital Output

Hi Everyone,

 

I'm currently trying to write some C code to control a 3-port digital device.  I have a M-series DAQ card and would like to do the following:

 

1.)  Use 3 lines (Dev1/port0/line0, Dev1/port0/line1, Dev1/port0/line2)

2.)  Do digital output of a custom 8-bits on each line independently at a specified clock rate, but syncronized to start at the same time.

 

Is this possible to do?  If so, are there examples available?

 

Please let me know..I appreciate the help!   Thanks!

0 Kudos
Message 1 of 6
(3,896 Views)

Hello,

 

This should be possible with your card. One possible solution is to use the sample clock for one of your signals, and then output on the counters pulse trains that you will then import as your sample clock. Other possibility is to divide down your clock and use that. We do not have any specific examples relating to this, but if you go to <National Instruments>/NI-DAQ/Text Based Code Support/ ANSI C Examples. This is where our examples for C programing in DAQmx are located. Have a great day!

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 2 of 6
(3,863 Views)

Hi Adam,

 

Could you elaborate more on the suggestion of  "One possible solution is to use the sample clock for one of your signals, and then output on the counters pulse trains that you will then import as your sample clock"?

 

Are you saying to output a signal that is clocked by the sample clock on the board, which I would then use as the clock signal to my other digital signals on other lines?  I.e if I have 3 signals, I would output the signal on line0 that is clocked by the sample clock, which i would use as a clock for digital signals on line 1 and line 2?

 

 

I don't know if I phrased my question correctly the first time, but I'm essentially trying to do the following steps shown in the pseudo code below:

 

CreateTask(taskHandle)

CreateDigitalOutputChannel(taskHandle, Dev1/port0/line0, binArray0)

CreateDigitalOutputChannel(taskHandle, Dev1/port0/line1, binArray1)

CreateDigitalOutputChannel(taskHandle, Dev1/port0/line2, binArray2)

SetExternalClock(taskHandle, setTo1kHz)

 

StartTask

StopTask

CloseTask

 

With the code above:

 

1.)  Would the 3 digital signals start at the same time?

2.)  Would the frequency for the 3 signals be set to 1 kHz?

 

 

If not, would the method you described above be the solution?  Please let me know!

 

Thanks!

 

0 Kudos
Message 3 of 6
(3,853 Views)

Hello,

 

Sorry I misunderstood what your first question was. I thought you were trying to output 3 digital signals at different rates. I believe the pseudo code you wrote is the direction you want to go in. The 3 signals should start at the same time, and the clock for them would be set to 1KHz. Have a great day!

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 4 of 6
(3,817 Views)

After doing more coding, I've had to program using the following pseudo code below:

 

CreateTask(taskHandle1)

CreateTask(taskHandle2)

CreateTask(taskHandle3)

 

CreateDigitalOutputChannel(taskHandle0, Dev1/port0/line0)

CreateDigitalOutputChannel(taskHandle1, Dev1/port0/line1)

CreateDigitalOutputChannel(taskHandle2, Dev1/port0/line2)

 

SetExternalClock(taskHandle0, setTo1kHz)

SetExternalClock(taskHandle1, setTo1kHz)

SetExternalClock(taskHandle2, setTo1kHz)

 

WriteDigitalLines(taskHandle0, binArray0)

WriteDigitalLines(taskHandle1, binArray1)

WriteDigitalLines(taskHandle2, binArray2)

 

StartTask(taskHandle0)

StartTask(taskHandle1)

StartTask(taskHandle2)

 

At this point, the digital output isn't sychronized now right?  I've read some posts on using the DAQmxWriteDigitalLines function.  Is it possible to send a 2D array as the data input? Where if I have the following psuedo code in order to write 5 different bits on 3 separate lines

 

binArray0[3][5] = {{1, 0, 1, 0, 1}, {1, 1, 1, 0, 0}, {0, 0, 0, 1, 1}};

 

CreateTask(taskHandle0)

CreateDigitalOutputChannel(taskHandle0, Dev1/port0/line0:2)

SetExternalClock(taskHandle0, setTo1kHz)

WriteDigitalLines(taskHandle0, binArray0)

StartTask(taskHandle0)

 

Thanks Adam!

 

Jonathan

0 Kudos
Message 5 of 6
(3,812 Views)

Hello,

 

You should be able to create 1 digital tasks for all 3 of the output channels you wish to do. You can then specify what will be written out to the channels and start that one task which will sync up all the digital output channels. If you are using CVI to do your programming I would recommend to take a look in the example finder at some of the digital generation examples to see how that code is constructed. Have a great day!

 

Best Regards,

 

Adam G 

National Instruments
Applications Engineer
0 Kudos
Message 6 of 6
(3,794 Views)