Reading an Absolute Encoder with National Instruments Motion Control

Publish Date: Nov 10, 2008 | 16 Ratings | 3.31 out of 5 | Print | Submit your review

This example shows you how to read various types of absolute encoders. It uses the subVI gray2bin for converting gray encoded data to binary encoded data. You can use this example with the following absolute encoder types: 

  • binary absolute encoders
  • gray absolute encoders
  • 12-bit binary absolute encoders
  • 12-bit gray absolute encoders

For information about connecting to NI 73xx motion controllers, see the Related Links section for a document about encoders and NI products.

In this VI, the data from a 16-bit encoder is read from ports 1 and 2. The data from the encoder can be of various types. The data connected to port 1 represents the lower byte of the word and port 2 the upper byte. The VIs that read the digital ports return the data as a cluster of Booleans. The data is first converted to an array of Booleans, and then to a number. These numbers are formatted as unsigned 8-bit and then concatenated to form a single 16-bit or 32-bit number depending on what type of encoder is used. This implies that we are using the 0 position of the encoder as a midpoint between two limits of travel. We could also use the 0 position as one extreme and the 65,535 position as the other limit. Since the position registers are 32-bit signed numbers, we now have to format the 16-bit number to 32 bits. The example implements this functionality by first checking to see if the 16-bit number is negative. If not, it is passed straight into the position registers with 0's in all the bits above 16 bits. If it is negative, then all the bits above 16 are set to 1's before being passed to the position registers.

For an encoder that produces gray code, the procedure is very similar. The process is almost the same as for the natural binary encoder except there is the addition of a VI which simply takes the 16 bit gray code and converts it to 32-bit binary. In this case, the binary value is placed into the position registers directly.


Related Links:
Absolute Encoders and NI Products


Back to Top

Bookmark & Share





Rate this document

Answered Your Question?
Yes No