From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mysterious counter control: How/why does it work?

I am trying to understand a VI called:

Position Meas Quadrature Encoder-Adv (NI-TIO).vi

There is an indicator on the front panel for "Measured Position"

If I probe the line going into this indicator I get a very large
number that is output by the Get Attribute (Count) VI. This number is
nothing like the numbers displayed by the indicator.

The indicator is scaled somehow. I need to be able to edit the
indicator and create similar functionality for other purposes. Can
someone explain this to me?

Many thanks,

Mike Ross
0 Kudos
Message 1 of 4
(2,375 Views)
Mike,

The raw position value coming out of the "Counter Get Attribute" VI is a U32 datatype. Since the U32 datatype does not support negative values, any "negative" position is going to be represented as a roll-over...so instead of -1, you'll get 2^32-1. If you take this U32 value and wire it into an I32 indicator, the rollover value will be "correctly" displayed as a negative position value. That's why you see a coercion dot on the indicator terminal for the "measured position" indicator...it is coercing a U32 value into an I32.

I hope this explanation makes sense. Please let me know if you need any more clarification. Have a nice day.

Darren
0 Kudos
Message 2 of 4
(2,375 Views)
Darren,

Thanks for your commenets. I can see that the conversion from
unsigned to integer is causing the change. I am still confused
though. How does the integer indicator know to turn 2^32-1 into -1?
Why doesn't it report back 4,294,967,295 as the probe does?

that progressions of the various numbering systems I32, U32, I16, U16,
I8, U8. I see how it works, now. Is this setup "normal" in
programming?>

My original need is to report position in degrees instead of encoder
lines (7200 per rev). If I divide by 20 or multiply by 0.05 the
unsigned, 0 to 2^32-1, number, I get just that. It is OK when the
numbers are positive from the original 0. But when I spin b
ackwards
in the negative direction I get 4,294,967,295/20 = 214,748,364.75.

I have a workaround (create a local variable and divide it), but I
hate not understanding how the coersion is working. I guess my only
complaint is that this seems inelegant.

Maybe my question should be: What is the best way to show degrees
from the output of an encoder?

At least I now have a clearer understanding of the various
representations of numbers.

Mike

Darren wrote in message news:<5065000000050000004E600000-1012609683000@exchange.ni.com>...
> Mike,
>
> The raw position value coming out of the "Counter Get Attribute" VI is
> a U32 datatype. Since the U32 datatype does not support negative
> values, any "negative" position is going to be represented as a
> roll-over...so instead of -1, you'll get 2^32-1. If you take this U32
> value and wire it into an I32 indicator, the rollover value will be
> "correctly" displayed as a negative position value. That's why you
> see a coercion do
t on the indicator terminal for the "measured
> position" indicator...it is coercing a U32 value into an I32.
>
> I hope this explanation makes sense. Please let me know if you need
> any more clarification. Have a nice day.
>
> Darren
0 Kudos
Message 3 of 4
(2,375 Views)
Mike,

The reason that the I32 doesn't report back 2^32-1 is because that number is out of the range of an I32. When you have 32 bits representing positive and negative numbers (as is the case with an I32), your maximum value is 2^31-1, or 2,147,483,647.

The underlying cause for all of these numerical conversion issues is the fact that the counter chip on the hardware only returns a number of counts, and you can never have a negative number of counts. So when you are using an encoder for positioning, you need to manipulate the numbers appropriately.

In order to get the numbers in I32 format for your degree calculations, you can simply use the "To Long Integer" function located in the Numeric >> Conversion subpalette.

I hope this help
s. Have a pleasant day.

Darren
0 Kudos
Message 4 of 4
(2,375 Views)