Home › Practice › RTL Design › A dial that changes one bit at a time
A dial that changes one bit at a time
EasyRTLcombinational
A rotating knob reports its position in binary. Going from 7 (0111) to 8 (1000) flips four bits at once, and a reading taken in the middle of the flip can be garbage.
Concept first. Gray code is a way to number positions so that neighbouring numbers differ in exactly one bit. For 2 bits the order is 00, 01, 11, 10: each step changes one bit, even from the last back to the first. Because only one bit changes at a time, a reading caught mid-change is at worst off by one position, never wild. Work out the 3-bit Gray sequence by hand from the 2-bit one. Then put each binary number next to its Gray partner and look for a pattern that links a Gray bit to the binary bits around it.
What to build.
bin2gray(b)converts a 4-bit binary number to its Gray code.- Output
g[3:0]. The Gray code of 0 is 0000, of 1 is 0001, of 2 is 0011, of 3 is 0010, and so on. Neighbouring numbers differ in one bit. - No clock.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.