Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger or start two counters

Using a USB6212 M series, I have two quadrature encoders feeding into the two counters. I use the freqout source to provide a 6250Hz clock signal for both, and run continuous sampling of the fifo at 200 samples per  loop. The code, in its most basic form, is attached.

I am having real problems getting any of the DAQmx vis to start the two counters at the same time. The purpose is to measure the relative rotation of the two encoders. Evidence is that one counter starts fairly randomly around 30 counts or 5ms before the other, which ruins my relative rotation measurement.

I'll take any suggestions. I don't care whether the trigger has to be a digital input, or a front panel event or whatever.

Thanks in advance.

Chris

 

0 Kudos
Message 1 of 4
(2,907 Views)

Hey Chris,

Thank you for attaching a minimal example!

The issue you have is that the two Start Task nodes execute at "random" points in time; they don't have any dependency to each other, same for the two tasks.2019-03-11_11-13-58.png

Basically, the upper and lower branch of your code are independent. The only dependency they have comes from the error wire on the left ("1"). That the Start Task nodes 2 and 3 execute only 5ms apart from each other is pure luck. You can improve this a bit by creating a dependency closer, e.g. wrapping both start noes in a flat sequence structure. However, this way your hardware tasks will still be started by software (relying on LabVIEW and Windows), which can still create a delay between both tasks of up to a second or two.

 

 

A better solution is to create a dependency in hardware, which is a hardware trigger (as you already guessed correctly). You normally don't need external wiring for this, as NI hardware also has internal triggers. The one you need here is the implicit "StartTrigger" which is fired whenever a task starts.

There is a shipped example showing how to set this up, you can find it in menu "Help » Fund Examples » Browse by Task » Hardware Input and Output » DAQmx » Synchronization » Analog Input - Synchronization.vi". Have a look at the section commented "Send Trigger":

2019-03-11_11-24-17.png

Basically you define a "slave" task to wait for the trigger fired by the other, "master" task. Start the slave first, then the master, and your tasks should start at the exact same moment (not taking into account the time it takes a signal to move along a wire, so there will still be some ns of delay for this trigger propagation).

 

Please note that this only starts the tasks at the same time - to keep them fully in sync they need to share also a common clock. Looks like you are already doing this, externally. You can normally route a clock signal internally as well, have a look at the same example VI, the section called "Synchronization". Haven't tested if you can derive a clock of 6250Hz on your hardware to use here, or if that is the reason you use external wiring.

 

 


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 2 of 4
(2,877 Views)

I'd add a little amendment to the prior reply.

 

Yes you should sync their start times by configuring them to react to a trigger signal.  However, for counter input tasks, you won't be able to use the regular Start Trigger.  Instead, you'll need to configure your encoder tasks for an Arm Start Trigger.  This is done with a DAQmx Trigger property node, as illustrated in the first example here.

 

As already mentioned, for certain sync both counter tasks also need to be configured to share a sample clock (you've already handled this), and need to be started *before* the trigger pulse is generated.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 3 of 4
(2,871 Views)

Kevin is right. Also, due to the Timing Engines and routes available on the USB-6212 there are some limitations I took not into account in my previous posting.

 

Attached is a VI. I derived this from your code. I removed some of the analysis code which you of course want to keep. These are the main differences:

  • Instead of using a PFI terminal, I route the CO clock signal to /Dev5/freqout and use this as Sample Clock source for both CI tasks. It's called /Dev5/FrequencyOutput there, but that is the same.
  • I use Arm Start Trigger to set up triggers for both CO task.
  • I use /Dev5/FrequencyOutput as the trigger source.
  • I start the CO task after the CI task. This way there are no clock ticks for the CI tasks so no samples are generated, and I have a defined trigger happening after both slave tasks' Start Task nodes have finished executing, so that the counters have also not started counting yet.
  • Please note the OR node I inserted into the loop to stop it in case an error happened.
  • Normally I'd move the task definitions into a re-used subVI to make the main VI much more readable, however I opted to leave everything in our diagram so its easier to spot the small differences.

I used an USB-6216 to confirm the two counter tasks are fully synchronized. Notice the two wait VIs I inserted to do testing. You can remove them safely.


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
Download All
Message 4 of 4
(2,863 Views)