Gray-code counters and arithmetic【Wikipedia 】

Gray-code counters and arithmetic

origianl link: http://en.wikipedia.org/wiki/Gray_code#Gray-code_counters_and_arithmetic

A typical use is building a fifo (first-in, first-out) data buffer that has read and write ports that exist in different clock domains. 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.[9] The updated read and write pointers need to be passed between clock domains when they change, to be able to track fifo empty and full status in each domain. Each bit of the pointers is sampled non-deterministically for this clock domain transfer. So for each bit, either the old value or the 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. Typically gray codes of power-of-two length are used.

Sometimes digital buses in electronic 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 code 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 source 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 code, 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 wildly 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 1962 US3020481, and there have been many others since. 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 have 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 into 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 1996 [10] Some issues in gray code addressing and then subsequently patented by someone else in 1998 US5754614. Other, potentially much faster methods of counting in Gray code are discussed in the report The Gray Code by R. W. Doran, including taking the output from the first latches of the master-slave flip flops in a binary ripple counter.

Gray-code counters and arithmetic【Wikipedia 】_第1张图片 

 

 

你可能感兴趣的:(count)