Generate n-bit Gray Codes. Given a number n, generate bit patterns from 0 to 2^n-1 such that successive patterns differ by one bit. Examples: Following is 2-bit. the resultant number is the binary equivalent of the gray number. Example, convert in gray code to binary. Gray Binary 1. 2. 1 copy. A Gray code is an encoding of numbers so that adjacent numbers have a single digit differing by 1. The term Gray code is often used to refer to a "reflected" code.
|Published:||1 August 2017|
|PDF File Size:||32.80 Mb|
|ePub File Size:||10.25 Mb|
This makes the transmission system less susceptible to noise.
Gray code - Wikipedia
Communication between clock domains[ edit ] Main article: Clock domain crossing Digital logic designers use Gray codes extensively for passing multi-bit count information between synchronous logic that operates at different clock frequencies.
The logic is considered operating in different "clock domains". It is fundamental to the design of large chips that operate with many different clocking frequencies.
Cycling through states with minimal effort[ edit ] If a system has to cycle through all possible combinations of on-off states of some gray code example of gray code example, and the changes of the controls require non-trivial expense e.
An example gray code example be testing a piping system for all combinations of settings of its manually operated valves. Gray code counters and arithmetic[ edit ] A typical use of Gray code counters is building a FIFO first-in, first-out data buffer that has read and write ports that exist in different clock domains.
Conversion from Gray Code to Binary Code and Vice Versa
The input and output counters inside such a dual-port FIFO are often stored using Gray code to prevent invalid transient states from being captured when the count crosses clock domains. Each bit of the gray code example is sampled non-deterministically for this clock domain transfer.
So for each bit, either the old value or gray code example new value is propagated. Therefore, if more than one bit in the multi-bit pointer is changing at the sampling point, a "wrong" binary value neither new nor old can be propagated.
By guaranteeing only one bit can be changing, Gray codes guarantee that the only possible sampled values are the new or old multi-bit value.
Gray Code -- from Wolfram MathWorld
Typically Gray codes of power-of-two length are used. Sometimes digital buses in gray code example systems are used to convey quantities that can only increase or decrease by one at a time, for example the output of an event counter which is being passed between clock domains or to a digital-to-analog converter.
The advantage of Gray codes in these applications is that differences in the propagation delays of the many wires that represent the bits of the code cannot cause the received value to go through states that are out of the Gray code sequence. This is similar to the advantage of Gray codes in the construction of mechanical encoders, however the gray code example of the Gray code is an electronic counter in this case.
The counter itself must count in Gray code, or if the counter runs in binary then the output value from the counter must be reclocked after it has been converted to Gray gray code example, because when a value is converted from binary to Gray code, it is possible that differences in the arrival times of the binary data bits into the binary-to-Gray conversion circuit will mean that the code could go briefly through states that are gray code example out of sequence.
Adding a clocked register after the circuit that converts the count value to Gray code may introduce a clock cycle of latency, so counting directly in Gray code may be advantageous. A Gray code counter was patented in USand there have been many others since.
Gray Code Explained
In recent times a Gray code counter can be implemented as a state machine in Verilog. In order to produce the next count value, it is necessary to gray code example some combinational logic that will increment the current count value that is stored in Gray code.
Probably the most obvious way to increment a Gray code number is to convert it gray code example ordinary binary code, add one to it with a standard binary adder, and then convert the result back to Gray code.
This approach was discussed in a paper in  and then subsequently patented by someone else in US Other methods of counting in Gray code are discussed in a report by Robert W.
Doran, including taking the output from the first latches of the master-slave flip flops in a binary ripple counter.