DAQ Toolbox Counter Input integer overflow problem

9 visualizaciones (últimos 30 días)
Matt Kindig
Matt Kindig el 20 de Dic. de 2011
Hello everyone,
I am trying to sample a counter output from a position encoder attached to a servo motor. I am sampling the counter through an National Instruments USB-6259 acquisition unit, using the daq.Session object in MATLAB 2011b/DAQ Toolbox 2011b. I have set up a counter input on a channel in the Session object.
I have observed that when using the counter in MeasurementType= 'Position' mode, the counter correctly tracks the position clockwise, and the Z-Reset works correctly (i.e. the position returns to zero once the maximum counts per revolution is exceeded). However, when the motor is rotated counterclockwise, the counts go to ~4.3billion. I discovered that this number is the intmax for an unsigned 32-bit integer, so I suspect integer overflow when the motor is rotated in one direction past the "zero" position. Is there a way to avoid this overflow, and instead allow negative positions?
The properties of the channel are as follows:
EncoderType: X4
ZResetEnable: 1
ZResetValue: 0
ZResetCondition: BothHigh
TerminalA: 'PFI8'
TerminalB: 'PFI10'
TerminalZ: 'PFI9'
Name: empty
ID: 'ctr0'
Device: [1x1 daq.ni.DeviceInfo]
MeasurementType: 'Position'
Thank you for your assistance.
Regards, Matt
  1 comentario
Walter Roberson
Walter Roberson el 20 de Dic. de 2011
MathWork's documentation on this topic is certainly sparse! I had to go to NI's site to find out what Z-Indexing was. Regrettably I was not able to figure out what combination of phases corresponds to the condition you are interested in. BothLow maybe. I do not see any mechanism for resetting on two different phase conditions.

Iniciar sesión para comentar.

Respuestas (1)

Bart
Bart el 16 de Oct. de 2012
Editada: Walter Roberson el 16 de Oct. de 2012
I had the same problem, with a NI USB-6216. This is not an overflow problem in Matlab, but a 'feature' of the NI hardware. The values are actually correct, when you subtract 2^32 from the (negative) measured values.
this should do the trick:
>>data(data>2^31) = data(data>2^31)-2^32
This divides the range into 2 parts, the part from 0 to 2^31 (unchanged), and the part from 2^31 to 2^32 (the 'negative' values). By subtracting 2^32 from the second set, these values become negative and can be used as normal.
  3 comentarios
Bart
Bart el 16 de Oct. de 2012
Thanks for the hint, but I don't think that would work. The data is already in double format. I think the NI device internally turns these values in uint32. Some values I encountered: pos2 =
1.0e+09 *
0.000000024000000
0.000000013000000
0.000000014000000
0.000000008000000
4.294967283000000
4.294967254000000
4.294967226000000
4.294967212000000
when you plot this, or look at it in short format, it looks like total crap. but when you subtract 2^32 from the last 4 entries, the values make sense: pos3 =
24
13
14
8
-13
-42
-70
-84
David
David el 19 de Mzo. de 2013
Since the data comes in double format, you can just convert it to uint32 format first. I just solved it using the following code
typecast(uint32(data), 'int32')

Iniciar sesión para comentar.

Categorías

Más información sobre Data Acquisition Toolbox Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by