Quantcast
Channel: Digital I/O topics
Viewing all articles
Browse latest Browse all 2167

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

$
0
0

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


Viewing all articles
Browse latest Browse all 2167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>