03-10-2019 04:20 AM
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
03-11-2019 05:29 AM
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.
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":
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.
03-11-2019 12:46 PM
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
03-12-2019 08:37 AM
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:
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.