Search code examples
vhdl

How to make a simple 4 bit parity checker in VHDL?


I am trying to learn VHDL and I'm trying to make 4-bit parity checker. The idea is that the bits come from one input line (one bit per clock pulse) and the checker should find out if there is odd number of 1s in the 4-bit sequence (i.e 1011 , 0100 , etc.) and send an error output(e.g error flag: error <=´1´) if there is.

Would someone give me an example how it´s done, so that I can study it?

I have tried searching the web, but all the discussions I found were related to something way more complicated and I could not understand them.


Solution

  • VHDL 2008 standard offers a new xor operator to perform this operation. Much more simple than the traditional solution offered by Aaron.

    signal Data : std_logic_vector(3 downto 0) ;
    signal Parity : std_logic ;
    . . .
    Parity <= xor Data ;