Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

On demand quadrature encoder issues

Hello--

I'm trying to write (what I thought was) a simple program in VB.net to read 2 quadrature encoders using an NI USB-6221 (OEM)--this card has 2 counters.  I don't need hardware timing, so on demand works just fine.  Essentially, I just need to query the position from 2 encoders from time to time. 

 

I tried doing this based on some code I had that was hardware timed, but since my board only has 2 counters, I (think I) can't generate a pulse train as the source for the hardware timing.  I tried using the internal 100kHz clock, but apparently this can only be used for 1 encoder--it can't be used for 2.

 

So...I was hoping to just go with on demand.  I'm able to do this just fine in MAX (see configuration screenshot attached).  However, when I try to do this in my VB code, I get this odd behavior where the displayed position (via the debug.print function) reverts back to 99 (the initial position).  That is, the program will begin by streaming the position starting with 99.  Then if I move the encoder, the values will change correspondingly, and as soon as I stop moving the encoder, the stream of values returns to 99.  I don't know why the data reverts to the "initial value"?  Can someone please explain what I'm doing wrong?

 

FYI...I'm running VS 2010, DAQmx v16.0.1, Win10x64.  

 

LinEncTask = New NationalInstruments.DAQmx.Task()
LinEncTask.CIChannels.CreateLinearEncoderChannel(DAQName & LinChannel, "", CIEncoderDecodingType.X4, False, 88.0, CIEncoderZIndexPhase.AHighBLow, DistPerPulse, 99.0, CILinearEncoderUnits.Meters)
LinEncReader = New CounterSingleChannelReader(LinEncTask.Stream)
Do
     Debug.Print(LinEncReader.ReadSingleSampleDouble)
Loop

 Thank you so very much!

Sandheep

0 Kudos
Message 1 of 5
(2,793 Views)

I am stuck with nearly the same problem in C#, with the NI PCIe6321 card. ReadSingleSampleDouble nearly always returns the initial value of the counter. Sometimes it is moved one step. It is as if it is constantly reset.

The example program for the quadrature encoder works. But when I remove the ConfigureSampleClock command and the BeginMemoryOptimizedReadMultiSampleDouble, and call ReadSingleChannelDouble from a timer instead, it also only returns 0 values.

Did anyone find a solution?

0 Kudos
Message 2 of 5
(2,502 Views)

It is also the same problem if, in the Quadrature Encoder Example, if I change the SampleQuantityMode in the ConfigureSampleClockfunction from ContinuousSamples to FiniteSamples. The position count is always reset to 0 when a new readout starts.

Only the ContinuousSamples setting works. This means that the program has to keep up with the produced data. And if I use one of the encoder channels as sample clock the program only reveives data every two encoder cycles, instead of 4 position updates per cycle. If a faster external clock is used it produces quite large amounts of data, which are not needed.

What is going wrong? Is there a good solution?

0 Kudos
Message 3 of 5
(2,494 Views)

My solution was to fix my very stupid bug--I forgot to add the start command for the task--in my example above, that would be:

 LinEncTask.Start()

Hope that helps,

Sandheep

0 Kudos
Message 4 of 5
(2,490 Views)

Thanks, that worked.

There is no Start command in the example program, but it works without that for continuous acquisition. For the other acquisition modes it does not though.

0 Kudos
Message 5 of 5
(2,482 Views)