Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I trigger different digital output patterns at the rising and falling edge using NIDAQmxBase?

I have an application that uses an external clock to generate digital output patterns.  However, I need different patterns to be generated on the rising and falling edge of this external clock.  This is on a Mac using NIDAQmxBase in an Ansi C environment with a 6251 card. 

 

The example code ContWriteDigPort-ExtClk.c generates a digital pattern triggered by the rising edge of an external clock as desired.  However, I cannot find a way to also trigger on the falling edge.  I tried setting the parameter activeEdge in DAQmxBaseCfgSampClkTiming to  'DAQmx_Val_Rising & DAQmx_Val_Falling'to no avail (it behaves as if DAQmx_Val_Rising was set).  I also tried adding a second task that is triggered by the falling edge of the external clock.  However, it looks as if these two tasks do not run at the same time but alternate (i.e., first numSampsPerChan of the first task will be generated and the numSampsPerChan of the second task and so on).

 

Is there a way to generate a digital pattern at both the rising and falling edge of the external clock?

 

Thanks!

 

Nico

0 Kudos
Message 1 of 8
(4,046 Views)

Hi Nico,

 

I understand that you are trying to generate multiple digital output patterns using an external clock, and that you would like for one pattern to generate at the rising edge of the external clock source, while the other digital pattern generates at the falling edge of the external clock source.  I also understand that you have tried creating two digital output tasks, and that the tasks appear to run in series rather than parallel.  Would it be possible for you to post your code so that we can see how you are programming your 6251?

 

Best wishes,

Wallace F.

National Instruments
Applications Engineer
0 Kudos
Message 2 of 8
(4,030 Views)

Hi Wallace,

 

Yes, that summarizes my goal pretty well.  Below is the essential part of the code that I used (completely based on the ContWriteDigPort-ExtClk.c example in NI-DAQ-mxBase).    Thanks for your help!

 

   int32       error=0;
   time_t      startTime;
   TaskHandle  taskHandle=0;
   TaskHandle  offTaskHandle=0;
   uInt32      data[16]={1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2};
   uInt32      offData[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
   bool32      done=0;
   char        errBuff[2048]={'\0'};

   // Falling edge task
   DAQmxErrChk (DAQmxBaseCreateTask("",&offTaskHandle));

   DAQmxErrChk (DAQmxBaseCreateDOChan(offTaskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));      

   DAQmxErrChk (DAQmxBaseCfgSampClkTiming(offTaskHandle,"/Dev1/PFI0",1000.0,DAQmx_Val_Falling,DAQmx_Val_ContSamps,1000));  

   DAQmxErrChk (DAQmxBaseWriteDigitalU32(offTaskHandle,16,0,60.0,DAQmx_Val_GroupByChannel,offData,NULL,NULL));
   DAQmxErrChk (DAQmxBaseStartTask(offTaskHandle));

   // Rising edge task
   DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));

   DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));
   DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"/Dev1/PFI1",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
   DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandle,16,0,60.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
   DAQmxErrChk (DAQmxBaseStartTask(taskHandle));                        
 

0 Kudos
Message 3 of 8
(4,018 Views)

Hi Nico,

 

Thanks for posting your code.  After reviewing your code, it seems that the two digital output tasks are running in series because you configure the falling edge task and then start the falling edge task first before you configure and start the rising edge task.  I recommend that you configure the falling edge task and you configure the rising edge task first, followed by starting both tasks.  I have attached a text file that modifies the code that you posted in such a way that I think will accomplish running the two digital output tasks in parallel.

 

Best wishes,

Wallace F.

National Instruments
Applications Engineer
0 Kudos
Message 4 of 8
(4,010 Views)

Hi Wallace,

 

Thanks for the suggestion.  Regretfully, it does not work.  The two tasks still work in series (funnily enough, they keep on alternating forever).  Is this a limitation of NIDAQmxBase, MIDAQmxBase on the Mac, or the card I am using?

 

Thanks!

 

Nico

0 Kudos
Message 5 of 8
(4,001 Views)

Hi Nico,

 

I noticed that you are trying to run two digital output tasks that write digital data to the same digital port, port 0, at the same time using hardware timing.  Unfortunately, the device is limited to performing only one correlated digital output task at a time.  Furthermore, the 6251 multifunction DAQ device doesn't support writing digital data on both edges, rising and falling, of the sample clock in a single task.  Also, looking at your code, the tasks alternate indefinitely because you do not use the DAQmxBase Clear Task or stop task functions.

 

As a potential solution to your problem, you might consider running one digital output task, and including the array of zeros in that task so that your data array would look like

 

uInt32    data[32]={1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0,1,0,2,0}

 

Then you could sample twice as fast to get the same timing of the digital output samples.

 

Regards,

Wallace F.

National Instruments
Applications Engineer
Message 6 of 8
(3,984 Views)

Hi Wallace,

 

Sorry for the long delay.   I would love to run a single digital output task, however, the sample clock that I am using is not regular, but is in fact a camera with a TTL going high during exposure and low during the (much shorter) interval between exposures.  I would like to set the output to 0 in between exposures.  

 

I guess I could build a circuit that will transform a rising and a falling edge into a digital pulse and then run a single digital output, but would have hoped that this card could do the trick.  Is there another approach that I could use?

 

One more thing (please let me know if I should start a new thread on this instead):  When I change DAQmx_Val_ContSamps to DAQmx_Val_FiniteSamps in the abovecode, I get the runtime error:

DAQmx Base Error: Requested value is not a supported value for this property. (Sample Mode)
Does this mean that  I can not use DAQmx_Val_FiniteSamps at all?

 

Thanks for your help!

 

Nico

0 Kudos
Message 7 of 8
(3,930 Views)

Hi Nico,

 

Based on the description of the TTL pulse output of your digital camera, you will want to set up your sample clock so that the digital samples are written on the falling edge of the sample clock, and you would want to configure the the sample clock to be external with the TTL pulse output of the digital camera being wired to one of the PFI lines.

 

Regarding the error you are getting with trying to set up the timing mode to finite samples; DAQmx Base only supports continuous mode sampling for the M-series DAQ boards. For more information, please see the knowledgebase article titled 'M-Series Correlated Digital I/O Sample Modes with NI-DAQmx Base.'

 

Best wishes,

Wallace F.

National Instruments
Applications Engineer
0 Kudos
Message 8 of 8
(3,902 Views)