Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

quadrature encoder based triggering

I'd like to use a position encoder to trigger a line scan camera.  I have a NI X Series PCIe board that I am using for AO, so if possible I am hoping to use it for triggering from the quadrature signal. 


Following tutorials online, I can easily read the position of the encoder with the X series.  However, less clear to me is if I can feed the position data to another counter such that every X net distance I get trigger that can be routed to the camera?  Obviously I could just read one phase and trigger from that, but I'd be sensitive to false counts while the device was stopped or dithering.  If this is possible, could someone suggest the approximate way to do it or provide an example?




Message 1 of 21

The following NI Community example provides a method for triggering a counter with another counter.


'NI Community: How Trigger Counter and Analog Input Simultaneously'



0 Kudos
Message 2 of 21

Unfortunately, I can't open labview 12 files, so I'm not sure exactly what that example does.  

0 Kudos
Message 3 of 21

You can configure a counter to issue a pulse every N encoder ticks in a somewhat roundabout manner.  


Use Z indexing to reset the counter to a known value (the encoder interval between your triggers) every time the Z index signal is received.  Use the counter's own internal output as the Z index signal.  When the counter reaches 0, it will issue a pulse on its output, resetting itself back to the desired interval and starting the process over again.  It will only fire in one direction--make sure A and B are such that the counter is counting down while travelling in the direction in which you wish to fire.


You may export the counter's internal output to a PFI line directly (the pulse is short though so you'll probably need to use it to trigger a second counter output that generates a longer pulse, or if you were talking about just using this to trigger the analog output then there wouldn't be any issue).



I'm using this in one of my applications and can verify that it works on X Series (PCIe-6320 and PCIe-6351).  Here is a screenshot of how I am configuring the counter task (I have digital filtering in there for good measure so that the input signals are synched to the internal timebase / Z index signal, I'm not sure if it's necessary or not):





Best Regards,

John Passiak
Message 4 of 21

Hi John,


Thanks for the detailed reply.  I'm not great with labview, but I should hopefully be able to manage.  One question though, when I try this, I get an error routing the counter output to the Z index:


Source terminal to be routed could not be found on the device.

Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.

Property: CI.Encoder.ZInputTerm
Source Device: Dev2
Source Terminal: Dev2/ctr0/InternalOutput


I'm on the pcie-6323, which I thought should be the same as your 6320.  Looking at the device routes in NI MAX, this route is permitted, so I am probably doing something wrong.  

0 Kudos
Message 5 of 21

Sorry, had the backslash in the wrong place.  Now it works.


0 Kudos
Message 6 of 21

I'm not great with labview (only used daqmx through the c or .net interface), but I tried putting together an example to see if it would work:




Unfortunately I get no output on the Ctr2 Out (which is PFI 14 on the 6323).  If I run a counter example program, I do see ticks being registered on those PFI lines, so I assume I'm wired correctly.  Any idea what I'm missing?

0 Kudos
Message 7 of 21

Sorry I left this out of my original post, if you want to export the counter output directly you can do so with DAQmx Export


Untitled 5 Block Diagram _2015-04-29_09-10-23.png



In my program I'm using the counter's internal output to trigger another task.



Best Regards,

John Passiak
0 Kudos
Message 8 of 21

Thanks, that fixed it.  In case anyone is interested, here is the complete working example:




I tested and it produces a uniformly spaced (in distance) sampling waveform as a linear motor accelerates.  I added the data indicator for completeness.  One note: in X4 mode it actually counts full cycles as far as I can tell, not individual edges, so to do one trigger per 100 edges, you have to divide by 4 (hence the 25 above).  

0 Kudos
Message 9 of 21

I've implemented this method, and while it mostly works, it often fails and generates just a single trigger after which it will not respond until I've reset the counter.  I was surprised, so I investigated and what I've found is that when it works, the counter iterates between 0 and the value counting down from, but when it fails, the value hits zero, generates the trigger event, but does not reset and instead counts down towards negative infinity.


So after triggering when the hardware is working, the counter value might be:






But when it fails, I get:






Anyone have an idea how this is possible?  My understanding is that it should be impossible to go below zero given that the Z-index value will reset the counter when it hits zero.  

0 Kudos
Message 10 of 21