U6 Streaming AIN and counter at the same time from Matlab? | LabJack
 

U6 Streaming AIN and counter at the same time from Matlab?

6 posts / 0 new
Last post
Claes
Claes's picture
U6 Streaming AIN and counter at the same time from Matlab?

Hi,

I'm trying to sample data from 2 analog sensors and one digital incremental rotary encoder at the same time. (from Matlab)

Could you please inform me if this is possible?

I have managed to sample the digital output from the rotary sensor on a third analog input, but with the risk of missing pulses.

Would it be possible to connect the rotary sensor to one of the counter inputs or even better use the quadrature feature at the same time as streaming is ongoing?

I have used a slightly modified example file from you, see attached file.

 

 

File Attachment: 
LabJack Support
labjack support's picture
Yes, see the following:

Yes, see the following:

https://labjack.com/support/datasheets/u6/operation/stream-mode/streamin...

Note that quadrature decoding is processor intensive.  You only need quadrature decoding if you need to track absolute position while the encoder is changing directions.  Otherwise just use a simple counter.

Claes
Claes's picture
Thanks for the answer,

Thanks for the answer,

I manage to get it to work with 2 analog inputs and one counter, very nice.

However I would like to increase the angular resolution by using quadrature decoding.

I tried to add the following row in the matlab example:

ljudObj.AddRequestS(ljhandle, 'LJ_ioPUT_TIMER_MODE', 0, 'LJ_tmQUAD', 0, 0);

But Matlab says:

"UD Driver Version = 3.5
No method 'AddRequestS' with matching signature found for class 'LabJack.LabJackUD.LJUD'."

Could you please give me an example how to set up this on one of the counters?

You say that quadrature decoding is processor intence, does this means that I have to decrease the overall sampling rate in streaming mode?

 

LabJack Support
labjack support's picture
We have a general example for

We have a general example for configuring timers and counters in the MATLAB examples download which demonstrates AddRequestS with a timer:

https://labjack.com/support/software/examples/ud/matlab

The 4th parameter is a double data type, so the string you are passing is not valid causing the error you are seeing. Quadrature input mode takes up two timers and need to be on adjacent even/odd channels pairs (0/1, 2/3):

LJ_tmQUAD = ljudObj.StringToConstant('LJ_tmQUAD');  % LJ_tmQUAD = 8

% Quadrature input on timers 0 and 1
ljudObj.AddRequestS(ljhandle, 'LJ_ioPUT_TIMER_MODE', 0, LJ_tmQUAD, 0, 0);
ljudObj.AddRequestS(ljhandle, 'LJ_ioPUT_TIMER_MODE', 1, LJ_tmQUAD, 0, 0);

For more details on the quadrature input look here:

https://labjack.com/support/datasheets/u6/hardware-description/timers-co...

You only need to stream one of the timers as both timers return the same count when using quadrature input.

Regarding the sampling rate, timers require two channels to get the one 32-bit value. Otherwise the decoding does not decrease the sample rate. Note that the quadrature input count is a signed 32-bit integer value when doing your conversion from the two 16-bit unsigned values from stream mode.

Regarding the timer's edge rate, stream mode does lower this rate as stream mode has higher priority than the timer firmware processing. The edge rates are mentioned in Appendix A of the datasheet,  "Input Timer Total Edge Rate":

https://labjack.com/support/datasheets/u6/appendix-a

 

Claes
Claes's picture
Thanks for the quick response

Thanks for the quick response,

I have looked at the example "u6_timer_counter.m" and also lookad at the sections you refer to, but I'm unable to get it to work.

Should the counter 0 and 1 be enabled or disabled during quadrature usage?

I have tried to update the script as attached, but I get the Matlab error:

"UD Driver Version = 3.5
UD Error: Timer sharing error                                                                                                                                                                                                                                            
Error using u6_simplestream_CG6 (line 97)
Message: Exception of type 'LabJack.LabJackUD.LabJackUDException' was thrown.
Source: LJUDDotNet
HelpLink: 
>> "

Do you have any advise?

File Attachment: 
LabJack Support
labjack support's picture
The two timers need to be

The two timers need to be enabled before configuring them. My previous code was only showing quadrature mode configuration. So something like this before configuring the two timer modes/values:

ljudObj.AddRequestSS(ljhandle, 'LJ_ioPUT_CONFIG', 'LJ_chNUMBER_TIMERS_ENABLED', 2, 0, 0);