From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize 2 Counter tasks in .Net

I create 2 Counter tasks to measure the same square wave signal in c#. Task 1 will measure the signal's semi-peroid, sample size 20 and start at rising edge. Task 2 will measure the signal's peroid, sample size 10 and start at rising edge. I want the 2 tasks start at the same rising edge. If that, the each peroid result of task2 will equal to the sum of each 2 semi-peroid results of task1. So, how to set the 2 tasks start at the same rising edge in c#? Or, should I put the 2 measurements in one task? Regards, Daniel
0 Kudos
Message 1 of 2
(4,066 Views)

You can not start 2 VIs simultaneously, I would say the usual difference is ~ 1ms (good programming), but can reach several ms in worst case. If your pulse rate is 10 Hz, then failure chance is ~2%.

You need some kind of hardware synchronization:

1) daqmx route. set both tasks source terminal to PFIx (not input terminal PFIy). Use daqmx routing palette, disconnect terminals PFIx and PFIy, start both tasks - they will wait for the input pulse. Connect terminals, both tasks will start with the first pulse that arrives.

2) Use one more counter (single pulse generation task) as an arm trigger source for both tasks. Start tasks, they will not run untill receive arm pulse, then run that additional task.

0 Kudos
Message 2 of 2
(3,870 Views)