Hola!!! Estoy aburrido ya, primero a no coge el valor de num_bin, si lo coge no me hace que si es mayor que 5 le sumo 3.
Por ejemplo para el numero binario 11010001 su bcd me sale en mi programa 11-1 con lo cual seria erroneo porque bcd solo llega hasta 9. No encuentro el fallo. Si me podeis ayudar, aver si hay alguna linea erronea del codigo, nose... :-\
entity bin2bcd is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
inicio : in STD_LOGIC;
num_bin : in STD_LOGIC_VECTOR (12 downto 0);
und : out STD_LOGIC_VECTOR (3 downto 0);
dec : out STD_LOGIC_VECTOR (3 downto 0);
cen : out STD_LOGIC_VECTOR (3 downto 0);
mil : out STD_LOGIC_VECTOR (3 downto 0);
fin : out STD_LOGIC);
end bin2bcd;
architecture Behavioral of bin2bcd is
begin
P1: process(reset,clk)
variable a: std_logic_vector(12 downto 0);
variable b: std_logic_vector(15 downto 0);
begin
if reset = '1' then -- si reset 1 pongo a cero las variables
a := (others => '0');
b := (others => '0');
elsif rising_edge(clk) then
if inicio = '1' then
a := num_bin; -- a "a" le asgino mi numero binario a convertir (proviene del test bench)
for i in 0 to 12 loop
b := b(14 downto 0) & a(12);
a := a(11 downto 0) & '0';
--b := b(2 downto 1) & '0';
-- voy desplazando y comprobando que si es mayor que 5 sumo 3
if (i<12 and b(3 downto 0) > "0100" ) then
b(3 downto 0) := b(3 downto 0) or "0011";
end if;
if (i<12 and b(7 downto 4) > "0100") then
b(7 downto 4) := b(7 downto 4) or "0011";
end if;
if (i<12 and b(11 downto 8) > "0100") then
b(11 downto 8):= b(11 downto 8) or "0011";
end if;
if (b(15 downto 12) > "0100") then
b(15 downto 12) := b(15 downto 12) or "0011";
end if;
end loop;
end if;
und <= b (3 downto 0);
dec <= b (7 downto 4);
cen <= b (11 downto 8);
mil <= b (15 downto 12);
end if;
end process ;
end Behavioral;
lo que te aconsejo yo personalmente con VHDL te aconsejo es que vayas a los mas sencillo porque a la hora de depurar es un infierno.
si fuese tu cogenería la entrada en binaria y la compararía con el numero numero en decimal 0-9 y luego prepararía el código BCD en la salida y listo.
algo así:
if num_bin = "1000" then
a <= "101010101"; -- 8 en BCD, ojo este representación es inventada
PD: a mi personalmente me desaconsejaron que utilizara variables en VHDL porque a veces da follon.