Sequential Hamming Distance counter using VHDL.
Authors:
Eduardo Robson Cardoso Guedes Filho
José de Deus e Silva Neto
In this lab, we aim to implement the calculation of the Hamming distance for two 8-bit binary words on a BASYS 3 FPGA board using the Xilinx XC7A35T-ICPG236C chip. The result is displayed both in binary using the LEDs and in decimal using 7-segment displays. The design constraint is that the result must remain visible until the user restarts the system.
The circuit has inputs d1 and d2 (the 8-bit words to compare), the clock signal clk, and a start signal start. Its outputs are dh (the Hamming distance, represented as a 4-bit binary word) and ready (indicating when the machine is not operating).
We start by describing the ASM (Algorithmic State Machine) and datapath, where i is a counter. Essentially, the machine compares each bit of the two words and increments dh until the sequence is finished.
After syntesis, the implementation of an ASM can be seen as a control machine which manages a series of classical components, such as registers, adders and multiplexers.
Figure 2 – Control state machine

Knowing the number of states in the control section, the number of flip-flops can be calculated as FF ⌈log2 S⌉ where S is the number of states.
FF_control = ⌈log2 3⌉ = 2- Operational part bits:
ready= 1 bitaandb= 8 bits eachdh= 4 bitsi= 4 bits
Total operational flip-flops: FF_operational = 25
Total machine flip-flops: FF_total = 27.
The machine computes each bit in two clock cycles; after loading data with start = 1, the ready signal is asserted only after 16 clock cycles.
The Hamming circuit does not directly control the 7-segment displays, so hamming_to_display is implemented to connect the project to the display control code.
Figure 3 – Hamming with display

Test examples:
d1 = 00000000andd2 = 00000000→dh = 0d1 = 11111111andd2 = 00000000→dh = 8
Three tests were performed:
d1 = 00010001,d2 = 00011010→dh10 = 3(decimal display),dh2 = 0011(binary LEDs)
Figure 5 – Basys dh=3
2. d1 = 01000110, d2 = 00100000 → dh = 4
Figure 6 – Basys dh=4
3. d1 = 01101111, d2 = 00000000 → dh = 7


