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

Subversion Repositories image_component_labeling_and_feature_extraction

[/] [image_component_labeling_and_feature_extraction/] [trunk/] [serial_div2.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 malikpearl
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
 
6
entity serial_div2 is
7
        generic (       M_PP    :       natural := 34;                          -- Size of dividend
8
                                        N_PP    :       natural := 19;                          -- Size of divisor
9
                                        R_PP    :       natural := 0;                                    -- Size of remainder
10
                                        S_PP    :       natural := 0;                                    -- Skip this many bits (known leading zeros)
11
                                        COUNT_WIDTH_PP  : natural       := 6;           -- 2^COUNT_WIDTH_PP-1 >= (M_PP+R_PP-S_PP-1)
12
                                        HELD_OUTPUT_PP  : natural       := 1            -- Set to 1 if stable output should be held
13
        );                                                                                                                              -- from previous operation, during current operation.
14
        port (  clk_i                   : in std_logic;
15
                          clk_en_i              : in std_logic := '1';
16
                          rst_i                 : in std_logic := '0';
17
                          divide_i              : in std_logic := '1';
18
                          dividend_i    : in std_logic_vector(M_PP-1 downto 0) := (others => '0');
19
                          divisor_i             : in std_logic_vector(N_PP-1 downto 0) := (others => '0');
20
                          quotient_o    : out std_logic_vector(M_PP+R_PP-N_PP+1 downto 0);                        --17
21
                          done_o                        : out std_logic
22
  );
23
end serial_div2;
24
 
25
architecture Behavioral of serial_div2 is
26
 
27
signal  divide_count    : std_logic_vector(COUNT_WIDTH_PP-1 downto 0) := (others => '0');
28
signal  divisor_node    : std_logic_vector(M_PP+N_PP-1 downto 0);
29
signal  quotient_node   : std_logic_vector(M_PP-N_PP+R_PP+1 downto 0);
30
signal  remainder_node  : std_logic_vector(M_PP+N_PP-1 downto 0);  -- Subtract node has extra "sign" bit
31
--signal  remainder_node2       : std_logic_vector(M_PP-1 downto 0);  -- Subtract node has extra "sign" bit
32
--signal msb_indicate           : std_logic ;
33
 
34
begin
35
        s_div : process(clk_i)
36
        begin   -- s_div
37
           if(clk_i'event and clk_i='1') then
38
                  if (rst_i = '1') then
39
               quotient_node            <=  (others => '0');
40
               divide_count     <=  (others => '0');
41
                         divisor_node   <=  (others => '0');
42
                         remainder_node <=  (others => '0');
43
--                  quotient_o  <=  (others => '0');
44
                         done_o                         <= '0';
45
--                       msb_indicate   <= '0';
46
                  else
47
                         if (clk_en_i = '1') then
48
                                 if (divide_i = '1') then
49
                                         done_o         <= '0';
50
--                                       quotient_o             <=  (others => '0');
51
                               quotient_node            <=  (others => '0');
52
                               divide_count     <=  (others => '0');
53
                                         divisor_node(M_PP+N_PP-1 downto M_PP)  <=  divisor_i;
54
                                         divisor_node(M_PP-1 downto 0)  <= (others => '0');
55
                                         remainder_node(M_PP+N_PP-1 downto N_PP)        <= dividend_i;
56
                                         remainder_node(N_PP-1 downto 0) <= (others => '0');
57
--                                       msb_indicate   <= '0';
58
 
59
                                elsif (conv_integer(divide_count) = (M_PP-11) ) then   --- works with (-11), no explanation right now   
60
 
61
                                        done_o  <= '1';
62
                                        quotient_o              <= quotient_node;
63
                                 else
64
                                        if (remainder_node > divisor_node) then
65
                                                remainder_node <= remainder_node - divisor_node;
66
                                                quotient_node   <= quotient_node(M_PP+R_PP-N_PP downto 0)         & '1';
67
                                        else
68
                                                quotient_node   <= quotient_node(M_PP+R_PP-N_PP downto 0)         & '0';
69
                                        end if;
70
 
71
                                                -- final shift...         TODO
72
                                        divide_count    <= divide_count + 1;            -- Advance the counter
73
                                        divisor_node    <= '0' & divisor_node(M_PP +N_PP-1 downto 1);
74
                                 end if;                        -- DIVIDE
75
 
76
                         end if;                        -- clk_en
77
                  end if;                       -- RST
78
                end if;                         -- CLK
79
        end process s_div;
80
 
81
                                  -- quotient_o                 <= quotient_node;       -- final shift...         TODO
82
 
83
end Behavioral;

powered by: WebSVN 2.1.0

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