Code Converters in VHDL.

The availability of a large variety of codes for the same discrete elements of information results in the use of different codes by different digital systems. It is sometimes necessary to use the output of one system as the input of another. A conversion circuit is inserted in between the two systems if each uses different codes for the same information.

So in this blog, we are going to design a very simple BCD to Excess 3 code converter. BCD or Binary Coded Decimal is the 4 bit binary value for each of the decimal numbers from 0 to 9. Excess 3 Code is the BCD plus 3. So if inp=0000, Excess 3 code is 0000+0011(3)=0011.

Here is the truth table for BCD to Excess 3 Code Converter.

  INPUT BCD  (A,B,C,D)                                            OUTPUT  EXCESS 3 CODE(w,x,y,z)

A B C D w x y z
0 0 0 0 0 0 1 1
0 0 0 1 0 1 0 0
0 0 1 0 0 1 0 1
0 0 1 1 0 1 1 0
0 1 0 0 0 1 1 1
0 1 0 1 1 0 0 0
0 1 1 0 1 0 0 1
0 1 1 1 1 0 1 0
1 0 0 0 1 0 1 1
1 0 0 1 1 1 0 0

VHDL CODE:

 

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

 

—- Uncomment the following library declaration if instantiating

—- any Xilinx primitives in this code.

–library UNISIM;

–use UNISIM.VComponents.all;

 

entity CODE_CONVERTER is

port (a: in std_logic_vector (3 downto 0);

y: out std_logic_vector (3 downto 0));

end CODE_CONVERTER;

 

architecture Behavioral of CODE_CONVERTER is

 

begin

process(a)   –BEHVIORAL MODELING

begin

case a is                — USE THE TRUTH TABLE, VERY EASY TO CODE IN THIS WAY

when “0000” => y <= “0011”;

when “0001” => y <= “0100”;

when “0010” => y <= “0101”;

when “0011” => y <= “0110”;

when “0100” => y <= “0111”;

when “0101” => y <= “1000”;

when “0110” => y <= “1001”;

when “0111” => y <= “1010”;

when “1000” => y <= “1011”;

when “1001” => y <= “1100”;

when others =>  y<=”0000″;

end case;

end process;

 

end Behavioral;

 

RTL SCHEMATIC:

cc1.PNG

cc2.PNG

So, the RTL schematic clearly shows that the circuit consists of a look up table in the form of ROM which takes a as an input and check for the corresponding output from the look up table and give it to the y.

 

TEST BENCH:

tb : PROCESS

BEGIN

a <=”0111″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

 

— Place stimulus here

a <=”1111″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

a <=”0101″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

a <=”0001″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

a <=”0000″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

a <=”0100″;

— Wait 100 ns for global reset to finish

wait for 100 ns;

wait; — will wait forever

END PROCESS;

 

END;

 

OUTPUT:

CC3.PNG

So, as we can see from the outputs, if we have a circuit which only performs operations on EXCESS 3 CODE, this code converter circuit can be used to convert first binary data into excess 3 and then proceed with it.

 

QUIZ:

A. How is 5 represented in 8,4,-2,-1 code?

A) 0111

B) 1011

C) 1111

D) 0000

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: