!The Messenger Must Not Stumble
When two digital systems operate on different clocks, they cannot talk directly. One might be running at a blistering gigahertz, while the other lumbers along at a few megahertz. To pass data between them, you must use a buffer—an Asynchronous FIFO.
The fast system blindly writes data into the buffer, while the slow system blindly reads it out.
To prevent the buffer from overflowing or running dry, the two systems must constantly tell each other where they are. They pass pointers back and forth across the clock boundary.
But crossing a clock boundary is violent. If the fast system tries to read a binary pointer exactly as the slow system is updating it, it might catch the bits mid-flip, reading a catastrophically wrong number and crashing the entire system.
The solution is to encode the pointers in Gray code before sending them across the abyss.
Because Gray code only changes one bit at a time, there is no mid-flip chaos. If the receiver catches the pointer during a transition, it either reads the old value or the new value. Both are safe. Both are true.
The data is safe because the messenger cannot stumble.
The messenger must not stumble.