Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronization of multiple tasks?

Hello,

 

I am currently working on a project that requires analog output signals and counter tasks to be synchronized.  The board I am using is the NI-6363 X series.  I am doing this in C++.

 

I called the start tasks one after the other, and then the read code like this:

 

DAQmxStartTask(taskHandlAO);

DAQmxStartTask(taskHandlCtr1);

DAQmxStartTask(taskHandlCtr2);

 

DAQmxReadCounterU32(taskHandlCtr1);

DAQmxReadCounterU32(taskHandlCtr2);

 

The AO clock and the counter read clock are driven by the same digital signal obtained by dividing the 20Mhz master time base using another counter.

 

Obviously the software timing delays between the start tasks and the read functions are causing my results to be inaccurate.

 

Is there a way i could group all the tasks together and force them to start at the same time?

 

Thank you in advance.

 

HT

0 Kudos
Message 1 of 6
(7,593 Views)

Hi HT,

 

I'm not sure what type of counter measurements you are making, but if you start the clock source after the Analog Output and the Counter Input tasks then all of the tasks should take their first sample at the same time.  By clock source I mean the counter you are using to divide down the 20 MHz timebase.

 

Depending on what you are doing you might also want to configure an Arm Start trigger (see X Series User Manual page 7-45).  I'm not sure what you mean by inaccurate results, but any issues you are seeing should be able to be overcome by effectively synchronizing the tasks together.  There is not a way to group the AO and Counter tasks together and have DAQmx automatically synchronize them.

 

 

-John

 

John Passiak
0 Kudos
Message 2 of 6
(7,576 Views)

Hi John,

 

Thanks for your timely reply.

 

I am using two counters to perform buffered counting edges in TTL pulse inputs.  I tried to start the clock source after all the tasks but there is still a problem.  Here's an updated snipet of my code:

 

DAQmxStartTask(taskHandleCtr);

DAQmxStartTask(taskHandleCtr2); 

DAQmxStartTask(taskHandleAO);

 

DAQmxReadCounterU32(counter1)

DAQmxReadCounterU32(counter2)

 

DAQmxStartTask(taskHandleClk); //Clock source

 

In theory none of the first three tasks would not start until the clock got started which would mean they would all be synchronized.  However the program seems to be stuck waiting for a measurement in the DAQmxReadCounterU32 function and never even reaches the start task code for the clock.

 

If I change rearragne the code to look like this:

 

DAQmxStartTask(taskHandleCtr);

DAQmxStartTask(taskHandleCtr2); 

DAQmxStartTask(taskHandleAO);

 

DAQmxStartTask(taskHandleClk);

 

DAQmxReadCounterU32(counter1)

DAQmxReadCounterU32(counter2)

 

The program would run but the time delay between the start clock and DAQmxReadCounterU32 functions would cause the same problem i had initially.

 

The results are inaccurate because the analog output tasks are driving scanners, if the analog output tasks were started before the counter tasks, the counter tasks would record counts that corresponding to the wrong scanner position and there would be no way of telling how much the results were shifted by.

 

I took a look at the Arm Start Trigger section of the manual, but I am confused as to where I would find this signal (external source?) to trigger the tasks and if there is a specific function I use to set that? I couldnt find that function in the C reference file. 

 

My apologies if I overlooked anything, I am quite new to using DAQ boards.

 

 

Thank you again

 

HT

 

 

 

 

 

0 Kudos
Message 3 of 6
(7,570 Views)

Hi HT,

 

The 2nd code snippet is more in line with what you should be doing.

 

The Read is just pulling data that has already been acquired from a buffer (so it will timeout if the task hasn't started yet).  So, your counters and your AO task should update off of the same clock.  The problem you are probably seeing is that since there is no Arm Start configured, each counter will begin counting at different times.  They will be sampled together, but not armed together (see below):

Buffered_Edge_Count.png

 

 

To configure the counters to arm together, you will need to add the following four lines of code before you start your tasks (adjust for your actual device name):

DAQmxSetArmStartTrigType(taskHandleCtr, DAQmx_Val_DigEdge);

DAQmxSetDigEdgeArmStartTrigSrc(taskHandleCtr, "/Dev1/ao/StartTrigger");

 

DAQmxSetArmStartTrigType(taskHandleCtr2, DAQmx_Val_DigEdge);

DAQmxSetDigEdgeArmStartTrigSrc(taskHandleCtr2, "/Dev1/ao/StartTrigger");

 

This will set the counters to arm off of the start of the analog output task.  Right now they are arming immediately when they are started in software.

 

 

Best Regards,

John

John Passiak
0 Kudos
Message 4 of 6
(7,566 Views)

I'm doing the same kind of things but in matlab using callib function.  When I run my programme with :

 

 errorVal=calllib('myni','DAQmxSetArmStartTrigType',uint32(Rtaskh1),10150);

 errorVal=calllib('myni','DAQmxSetDigEdgeArmStartTrigSrc',uint32(Rtaskh1),'/Dev1/PFI7');

 

I receive the error 200452 wich is :   Measurements: Specified property is not supported by the device or is not applicable to the task.

 

My card is a pci-6111

 

Can I do this kinf of synchronisation with that card ??

 

Thank you 

 

Christian

0 Kudos
Message 5 of 6
(7,121 Views)

Hi Christian,

 

Unfortunately the 6111 does not support the use of an Arm Start Trigger.

 

More information about what you need to accomplish might be helpful so we can determine if there is a suitable workaround.

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 6 of 6
(7,113 Views)