From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

9402 DAQmx C: Write Clock and Data on two diferrent lines.

I am working with NI 9402 (4 I/O lines) and coding with DAQmx c (I AM NOT USING LABVIEW).

 

I am trying to output the the data signal by port0/line1. Period required of each bit: 1us.(1 MHz)

 

At the same time I am trying to output the clock signal by port0/line0. Period of each bit: 0,5us (2 MHz).

 

For that purpose I have tried to write the data on port0/line1 with DAQmxWriteDigitalLines() and use the function DAQmxCfgBurstHandshakingTimingExportClock() to export the clock to port0/line0. 

 

 

DAQmxWriteDigitalLines(taskData,DATA_SIZE,1,30.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

DAQmxCfgBurstHandshakingTimingExportClock(taskData,DAQmx_Val_ContSamps,2000000,1000.0,"cDAQ1Mod1/port0/line0",DAQmx_Val_ActiveHigh,DAQmx_Val_Low,DAQmx_Val_ActiveHigh));

 

When exectuing I get this error message:

 

DAQmx Error: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.

Property: DAQmx_SampTimingType

Requested Value: DAQmx_Val_BurstHandshake

You Can Select: DAQmx_Val_SampClk, DAQmx_Val_OnDemand

Task Name: taskData

Status Code: ­200077

 

I guess that this mean that function DAQmxCfgBurstHandshakingTimingExportClock  is not supported on NI 9402..

 

As I have not been able to solve this problemI decided to use DAQmxCfgSampClkTiming() instead of DAQmxCfgBurstHandshakingTimingExportClock().

 

Since I will be using a SampClkTiming function I have created 2 separate tasks, with different clock rates for each one, and try to write separately the clock and the

data arrays in line0 and line1.

 

I am having troubles when I try to write both lines at the same time, this is the important part of the code I am using:

 

TaskHandle  taskData=0,taskClock=0;

              /*********************************************/

              // DAQmx Configure Code

              /*********************************************/

              DAQmxErrChk (DAQmxCreateTask("taskData",&taskData));

              DAQmxErrChk (DAQmxCreateTask("taskClock",&taskClock));

              DAQmxErrChk (DAQmxCreateDOChan(taskClock,"cDAQ1Mod1/port0/line0","clkOut",DAQmx_Val_ChanPerLine));

              DAQmxErrChk (DAQmxCreateDOChan(taskData,"cDAQ1Mod1/port0/line1","",DAQmx_Val_ChanPerLine));

 

              DAQmxErrChk (DAQmxCfgSampClkTiming(taskData,NULL,1000000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,DAQmx_Val_ContSamps)); //to define the 1 micro secnd Time of bit.

              DAQmxErrChk (DAQmxCfgSampClkTiming(taskClock,NULL,2000000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,DAQmx_Val_ContSamps));

//2000000 because I want the clock array to be sent twice faster than the data array

/*********************************************/

              // Set data & clock Arrays

              /*********************************************/

Define the clock array:             

              for(i=0;i<1000;i++)              {clockD[i]=i%2;} /'1' and '0'

Define data array:             

              for(i=0;i<1000;i++)              {data[i]=1;} // or whatever random values..

/*********************************************/

              // Write digital lines

              /*********************************************/

 

while(1)              {

                            DAQmxErrChk (DAQmxWriteDigitalLines(taskData,1000,1,30.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

                            DAQmxErrChk (DAQmxWriteDigitalLines(taskClock,1000,1,30.0,DAQmx_Val_GroupByChannel,clockD,NULL,NULL));

              }

After executing this code I get the error:

DAQmx Error: NI Platform Services:  The specified resource is reserved. The operation could not be completed as specified.

Task Name: taskClock

 

Status Code: ­50103

 

Nevertheless, If I just  use one of the DAQmxWriteDigitalLines function, the program works fine, and it send out the information ).

 

By the way I noticed that if I Write a digital line in a for loop instead of while(1), if the number of iterations of the for loop is low (i.e. 10), I get the same error even if I just write call the DAQmxWriteDigitalLines() function once.

 

Could these two errors be related ?

 

To sum up:

Could anyone give me a clue how two output a data signal and a clock signal  to 2 different ports with different clock rates for each signal ?

 

Thank you very much

0 Kudos
Message 1 of 3
(5,231 Views)

Solved just with one task, but not sure how efficient is that..

 

I added one more channel to the task and set the numSampsPerChan on the DAQmxCreateDOChan function to the half size of the buffer I originally wanted to write, i.e. let's say 32 bits.

 

I can write the clock at 2MHz and the data at 1 MHz by duplicating all the data values. The data sequence at 1 MHz : 11010001 would have to  be: 1111001100000011 if I am sending it at 2 MHz.

For every 8 bits of useful data I am actually sending 16 bits of data + 16 bits of Clock ('1' and '0'). So data array of 32 bits is :  [10101010101010101111001100000011] (16 bits of clock+16 bits of useful data duplicated)

 

When Writing :

DAQmxErrChk (DAQmxWriteDigitalLines(taskData,16,1,30.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));

The first 16 bits would be writen in one line (that represents the clock at 2MHz) and the other 16 bits in the other line (data at 1MHz ).

 

If anyone knows a more efficient way to do it help would be appreciated

 



0 Kudos
Message 2 of 3
(5,208 Views)

One quick question about how you setup your timing:

 

Spoiler
DAQmxErrChk (DAQmxCfgSampClkTiming(taskData,NULL,1000000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,DAQmx_Val_ContSamps));

 

If you are only going to write 1000 finite samples, then why are you specifying the number of samples to write here as "DAQmx_Val_ContSamps" and not 1000? See: Sample Clock Timing Reference

 

Also, I gather what you are trying to do is output the DO task's sample clock on line0, at the same time that the DO task is running. If that's true, you should be able to export your sample clock using the export signal function. See: Export Signal Reference

 

Hope this helps.

0 Kudos
Message 3 of 3
(5,188 Views)