Example Code

Converting Gray Codes to Their Corresponding Standard Binary Numbers in LabVIEW

Code and Documents

Attachment

Overview:
This VI converts a binary number in gray code to a standard binary representation.
Description:

Gray-coded binary is used widely with absolute encoders in industry due to the property that each transition involves only a single bit change, ensuring that there are no indeterminate states. For more information on gray codes, see the wikipedia article here: http://en.wikipedia.org/wiki/Gray_code.

Requirements:

  • LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code:

  1. Run the VI.

 Additional Information or References:

Screenshot_2.png

 

.

"**This document has been updated to meet the current required format for the NI Code Exchange.**" 

Verne D. // Software R&D // National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
JB
Trusted Enthusiast
Trusted Enthusiast
on

Here is Ed Dicken's inverse function to generate the Gray code of a number.

Number to Gray Code.png

BASE10
Member
Member
on

Here is a version suitable for single-cycle execution on an FPGA.

Gray to Binary.png

BASE10
Member
Member
on

Here is an efficient version of the inverse function.

Binary to Gray.png

JB
Trusted Enthusiast
Trusted Enthusiast
on

Thank you for this version. About 25x faster on my machine !

BASE10
Member
Member
on

No problem, thanks wikipedia!