OpenCores
URL https://opencores.org/ocsvn/tcp_ip_core_w_dhcp/tcp_ip_core_w_dhcp/trunk

Subversion Repositories tcp_ip_core_w_dhcp

[/] [tcp_ip_core_w_dhcp/] [trunk/] [bin_to_bcd.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 craighaywo
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    15:14:45 01/21/2015 
6
-- Design Name: 
7
-- Module Name:    bin_to_bcd - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.NUMERIC_STD.ALL;
23
 
24
-- Uncomment the following library declaration if instantiating
25
-- any Xilinx primitives in this code.
26
--library UNISIM;
27
--use UNISIM.VComponents.all;
28
 
29
entity bin_to_bcd is
30
    Port ( CLK_IN                       : in  STD_LOGIC;
31
           CONV_IN                      : in  STD_LOGIC;
32
           BIN_IN                       : in  STD_LOGIC_VECTOR (7 downto 0);
33
           BCD_OUT                      : out  STD_LOGIC_VECTOR (11 downto 0);
34
           CONV_DONE_OUT        : out  STD_LOGIC);
35
end bin_to_bcd;
36
 
37
architecture Behavioral of bin_to_bcd is
38
 
39
signal export_bcd : std_logic := '0';
40
signal state : unsigned(3 downto 0) := X"0";
41
 
42
signal hex_src : unsigned(7 downto 0);
43
signal bcd, bcd_calcd : unsigned(11 downto 0);
44
 
45
begin
46
 
47
        BCD_OUT <= std_logic_vector(bcd_calcd);
48
 
49
        process (CLK_IN)
50
        begin
51
                if rising_edge(CLK_IN) then
52
                        if state = X"0" then
53
                                if CONV_IN = '1' then
54
                                        state <= X"1";
55
                                end if;
56
                        else
57
                                state <= state + 1;
58
                        end if;
59
                        if state = X"F" then
60
                                export_bcd <= '1';
61
                        else
62
                                export_bcd <= '0';
63
                        end if;
64
                        if export_bcd = '1' then
65
                                CONV_DONE_OUT <= '1';
66
                        else
67
                                CONV_DONE_OUT <= '0';
68
                        end if;
69
                        if export_bcd = '1' then
70
                                bcd_calcd <= bcd;
71
                        end if;
72
                end if;
73
        end process;
74
 
75
        process (CLK_IN)
76
        begin
77
                if rising_edge(CLK_IN) then
78
                        if CONV_IN = '1' then
79
                                hex_src <= unsigned(BIN_IN);
80
                                bcd <= (others => '0');
81
                        elsif state(0) = '0' then
82
                                if bcd(3 downto 0) > "0100" then
83
                                        bcd(3 downto 0) <= bcd(3 downto 0) + "0011";
84
                                end if;
85
                                if bcd(7 downto 4) > "0100" then
86
                                        bcd(7 downto 4) <= bcd(7 downto 4) + "0011";
87
                                end if;
88
                                if bcd(11 downto 8) > "0100" then
89
                                        bcd(11 downto 8) <= bcd(11 downto 8) + "0011";
90
                                end if;
91
                        else
92
                                bcd <= bcd(10 downto 0) & hex_src(7);
93
                                hex_src <= hex_src(6 downto 0) & '0';
94
                        end if;
95
                end if;
96
        end process ;
97
 
98
end Behavioral;
99
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.