Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Quadrature counter dividing and triggering

I'm currently looking into using an NI USB 6353 device in a project, and I'm confused about its capabilities. Here is what I'm trying to achieve:

 

1. Reading an A/B (no Z) quadrature input to increment/decrement a counter (preferrably in X4 mode).

2. Produce a digital output signal with transitions on each counter increment/decrement.

3. Frequency dividing the counter transitions to produce a digital signal used to trigger various external hardware. The divider should be specifiable (probably around a few thousand).

4. Using another frequency divided version of the counter to trigger simultaneous analogue/digital sampling on the device.

5. Have the ability to make the counter time based (just incrementing at a set frequency), rather than using the quadrature input. The resulting signals should all still be divided and output correctly.

 

Being able to use the digital outputs on the device independently (on demand, timing isn't particularly important here) would be great, too.

 

Is this possible using the DAQmx C or C# API? Are there any other devices I should be looking at?

0 Kudos
Message 1 of 9
(8,199 Views)

 

Hello Matthew,
All of these functions can be performed using the NI USB-6353.  However, you may have an insufficent amount of counters for your system setup if you intend to execute these functions simultaneously.  The NI USB-6353 has 4 counters.
1) We provide a shipping example that shows how to read an x4 quadrature output.  In the NI Example finder, go to Hardware Input and Output -> DAQmx -> Counter Measurements -> Position -> Measure Angular Position.vi.  Please note that performing quadrature decoding in x4 mode, you will need to use two counters.
2) Please refer to another example: Hardware Input and Output -> DAQmx -> Events -> Gen Event for Ext Signal.vi.  This example will require another counter.
3)  Are you trying to frequency divide the x4 quadrature signals?  Since that configuration requires two counter inputs, you may want to consider creating a circuit that merges the signals to one output frequency line to do frequency division.  Nevertheless, below is some information about frequency division:
Divide External Clock by Two Using Counter in DAQmx
Furthermore, below is a forum post that may be helpful:
4) Please refer to another example: Hardware Input and Output -> DAQmx ->Analog Measurements -> Voltage ->Acq&Graph Voltage-Int Clk-Retriggerable.vi
5) You can do a clock divide based on internal base clocks 100MHz, 20 MHz, 0.1MHz.  However, doing so will also require a counter.  Below is a KnowledgeBase article that explains this:
How Do I Program the Frequency Output (FREQ OUT) Signal Using NI-DAQmx
I hope this is helpful.  Take care.

 

Regards,
Roman Sandoval | National Instruments | RF Systems Engineer
0 Kudos
Message 2 of 9
(8,174 Views)

Regarding item 1, only one counter is necessary.  However, for higher precision applications, two counters can be used:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGk4CAG&l=en-US

 

Furthermore, below is a link that explains the process of setting up the reading of the quadrature encoder:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x1riCAA&l=en-US

Regards,
Roman Sandoval | National Instruments | RF Systems Engineer
0 Kudos
Message 3 of 9
(8,162 Views)

I just wanted to clarify/correct a couple of points:

 

    1.  The 6353 is capable of reading quadrature encoders as X4.  You do not need to use 2 counters to read a X4 encoder (X Series User Manual, page 7-24)

 

    2.  It sounds like you want to output a pulse on every rising/falling edge of either A or B.  You'll probably find the section on Change Detection helpful--this can be used to do what you want if you export the Change Detection Event (page 6-23).

 

    3.  You can configure a Counter Output Task (on a 2nd counter) to pulse or toggle its state after every N counts (N is between 2 and 2^32-1).  The source of the counts could be A, B, the Change Detection event, or many other signals.

 

    4.  This would be another counter output task (using a 3rd counter) assuming the divisor is different.  You can use the counter Internal Output as a sample clock source for your AI and DI tasks.

 

    5.  You can configure a Counter Output Task using one of the internal timebases as a source.  The internal output of this counter could be routed to the source of the other two counters.

 

 

You can use the digital outputs either buffered or on demand independent of the other subsystems.  Clocked DIO is only available on port 0, but the lines are bi-directional and DI and DO can be clocked independently.

 

 

X Series looks like a good place to be looking for what you are asking to do--the 4 counters should give enough to do what you need.  Keep in mind that the counters have the same specs on all X Series, so I would try to base your decision on the analog specs.  The 6341 is the lowest cost USB X Series (also be aware that it only has 8 clocked DIO lines instead of 32 on the 63x3).

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 9
(8,159 Views)

Many thanks John and Roman.

 

It sounds like the X-Series can do what we need. We'll probably stick with the 6353, because we need at least 20 analogue inputs, and sampling rates of at least 1MSps.


I'm slightly confused as to how to use the change detection to implement what we want. Essentially, we'd like to take the X4 quadrature input and convert it to a step signal (as in, step/direction) that will be used to control a hardware variable antialiasing filter. Will this require another counter? If this can't easily be done on the USB DAQ device, we can do it using external hardware.

 

How hard is it to get the direction and also speed (or frequency) of the original quadrature input for each AI and DI sample taken? I assume that the frequency measurement would require another counter? How about direction?

0 Kudos
Message 5 of 9
(8,152 Views)

Also,

 

Wouldn't the change detection mean that I couldn't sample the digital input lines at a divided rate? Or can I simply implement the change detection using a single DIO port and still have the remaining DI lines to use?

0 Kudos
Message 6 of 9
(8,150 Views)

Hi Matthew,


@Matthew S wrote:

 

Wouldn't the change detection mean that I couldn't sample the digital input lines at a divided rate? Or can I simply implement the change detection using a single DIO port and still have the remaining DI lines to use?


I'm glad you brought it up--I guess I overlooked that you were planning to use clocked DI.  If you're using DI change detection you cannot sample the DI lines off of another clock source.  Unfortunately, port 0 is the only port that supports change detection (even though the manual currently implies otherwise) as well as the only port that supports clocked DIO.  You can still do static DI on other lines, but the clocked DI subsystem can only have one timing source.  You can always oversample your DI using the change detection, then index out 1 out of every N samples in software (the DI should be good at rates of up to at least 1 MHz continuously).

 

 


@Matthew S wrote:

 

It sounds like the X-Series can do what we need. We'll probably stick with the 6353, because we need at least 20 analogue inputs, and sampling rates of at least 1MSps.


Keep in mind the 6353 is multiplexed--the aggregate rate is 1 MHz, but sampling 20 lines at the same time would only give you 50 kHz per channel.

 

 


@Matthew S wrote:

 

I'm slightly confused as to how to use the change detection to implement what we want. Essentially, we'd like to take the X4 quadrature input and convert it to a step signal (as in, step/direction) that will be used to control a hardware variable antialiasing filter. Will this require another counter? If this can't easily be done on the USB DAQ device, we can do it using external hardware.


You can get the step from your x4 encoder with change detection easily enough, but I don't think there is a good way to get the direction as an external hardware signal.  I think the better option is to use a flip flop to latch the encoder state (either latch A using B as the clock or vice-versa) to obtain the direction.

 

 


@Matthew S wrote:

 

How hard is it to get the direction and also speed (or frequency) of the original quadrature input for each AI and DI sample taken? I assume that the frequency measurement would require another counter? How about direction?


If you're using a latching circuit to output the direction, you could just sample this off of one of the DI lines (assuming you have one available).  To measure the frequency of the encoder, I suggest looking into the method described in Figure 7-15 of the X Series User Manual to use another counter to measure the frequency of either A or B.  During each sample clock period the counter counts the number of encoder pulses as well as the number of internal timebase ticks that occurred during those pulses.  The driver uses this information to return the average frequency of your signal in between sample clock pulses.

 

 

 

So... you were right to have some concerns about using change detection alongside clocked DI.  You'll have to pick one or the other--I think I'd prefer to oversample DI and throw away samples, depending on the maximum frequency coming from your encoder.  Also of concern is the number of counters (there are 4 available on the board).  In addition to the 4 counters, keep in mind taht there is a Frequency Generator that can be used to output specific frequencies:

    {20 MHz, 10 MHz, 100 kHz} / {1:16}

 

 

Please don't hesitate to post back if you have any questions--there's alot you need to do so you might have to make some compromises.  We're starting to get into territory where an FPGA might be more suitable for your digital requirements.

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 9
(8,139 Views)

Thanks John.

 

I think the simplest solution is to just use a chip like the LS7184 to get step/direction. The step signal can adjust the variable hardware filter and also increment a counter on the DAQ device. The direction signal can be whacked into a DI. Then I have 3 counters to play around with to measure frequency, output a divided step signal and trigger the DI and AI sampling.

0 Kudos
Message 8 of 9
(8,126 Views)

Seems much more reasonable--it looks like the 7183 fills in all of the gaps I mentioned earlier.  So the four counters would be used for:

 

    1.  Quadrature Input:  The DAQ Card can take in the A and B signals directly (x1, x2, or x4) or could just take in the step signal (you can control the count direction with your external direction signal if you want as well).

 

    2.  Measure Frequency of the step signal.

 

    3.  Divide-down of step signal for external use.

 

    4. Sample Clock.  Divide-down of the step signal with a different divisor.  Used as sample clock for DI, AI, and Frequency measurement.  Could also be used to sample the encoder (or edge count) measurement.

 

 

You mentioned that you might just want to sample at a fixed rate sometimes.  You can do this with one of the built-in timing engines (AI, AO, DI, and DO all have them) so you can just configure the board to use the onboard clock and configure the rate directly on your AI or DI task using when you want to switch to this mode.

 

As long as the multiplexed board works for you (1 MHz aggregate) then it seems like we have all of the bases covered.  If you have any follow-up questions don't hesitate to ask though!

 

 

Best Regards,

John Passiak
0 Kudos
Message 9 of 9
(8,119 Views)