Convertidor binario to bcd (VHDL)
Publicado por ramon (1 intervención) el 11/03/2015 16:22:38
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... :-\
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... :-\
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
- TRABAJO1.rar(241,3 KB)
Valora esta pregunta
0