You are on page 1of 2

library ieee;

use ieee.numeric_bit_unsigned.all;
entity gray2bcd is
port (gin : in bit_vector(3 downto 0) := "0000";
clk : in bit;
bcdout : out bit_vector(4 downto 0) := "00000");
end gray2bcd;
architecture gray2bcdarch of gray2bcd is
begin
process(clk)
variable gt9,temp_carry : bit:= '0';
variable temp : bit_vector(3 downto 0) := "0110";
variable bin : bit_vector(3 downto 0);
variable bcdout_temp : bit_vector(4 downto 0) := "00000";
begin
if clk'event and clk = '1' then
bin(3) := gin(3);
for i in 2 downto 0 loop
bin(i) := bin(i+1) xor gin(i);
end loop;

gt9 := bin(3) and(bin(2) or bin(1));


if gt9 = '1' then
-- bcdout_temp(0) := bin(0);
-- for i in 1 to 3 loop
-- if i = 1 then
-- if bin(i) = '1' then
-- bcdout_temp(i) := '0';
-- temp_carry := '1';
-- elsif bin(i) = '0' then
-- bcdout_temp(i) := '1';
-- end if;
-- elsif i = 2 then
-- if bin(i) = '0' and temp_carry = '0' then
-- bcdout_temp(i) := '1';
-- elsif bin(i) = '1' and temp_carry = '0' then
-- bcdout_temp(i) := '0';
-- temp_carry := '1';
-- elsif bin(i) = '0' and temp_carry = '1' then
-- bcdout_temp(i) := '0';
-- temp_carry := '1';
-- elsif bin(i) = '1' and temp_carry = '1' then
-- bcdout_temp(i) := '1';
-- temp_carry := '1';
-- end if;
-- elsif i = 3 then
-- if temp_carry = '1' then
-- bcdout_temp(i) := '0';
-- temp_carry := '1';
-- elsif temp_carry = '0' then
-- bcdout_temp(i) := '1';
-- temp_carry := '0';
-- end if;
-- end if;
-- end loop;
-- bcdout_temp(4) := temp_carry;
bcdout_temp := ('0' & bin) + ('0' & temp);
else
bcdout_temp := ('0' & bin);
end if;
end if;
bcdout <= bcdout_temp;
end process;
end gray2bcdarch;

You might also like