Search This Blog

Saturday, 5 December 2015

VHDL Code of (7,4) Hamming Code Encoder

Name of Pins
Direction
Width
Datain
Input
4
Hamout
Output
7


Hamming code is useful in Error Correction in Linear Block Code. This code will encode four bits of data and generate seven bits of code by adding three bits as parity bits. It was introduced by Richard W. Hamming. This algorithm can detect one and two bit error and can correct one bit error. Given below code will generate (7,4) Systematic Hamming Encoder. This encoder will use Least Significant 4 bits as data inputs and Most 3 significant bits as a parity bits.
Parity bits equations are given below

p0 = datain(0) xor datain(1) xor datain(3)
p1 = datain(0) xor datain(2) xor datain(3)
p2 = datain(1) xor datain(2) xor datain(3)



library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

ENTITY hamming_encoder IS
 PORT(datain : IN BIT_VECTOR(0 TO 3); --d0 d1 d2 d3
  hamout : OUT BIT_VECTOR(0 TO 6)); --d0 d1 d2 d3 p0 p1 p2
END hamming_encoder;

ARCHITECTURE beh OF hamming_encoder IS
SIGNAL p0, p1, p2 : BIT; --check bits
BEGIN
--generate check bits
 p0 <= (datain(0) XOR datain(1)) XOR datain(3);
 p1 <= (datain(0) XOR datain(2)) XOR datain(3);
 p2 <= (datain(1) XOR datain(2)) XOR datain(3);

--connect up outputs
hamout(4 TO 6) <= (p0, p1, p2);
hamout(0 TO 3) <= datain(0 TO 3);

END beh;

No comments:

Post a Comment