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

Subversion Repositories uart_block

[/] [uart_block/] [trunk/] [hdl/] [iseProject/] [divisor.vhd] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leonardoar
--! Unsigned division circuit, based on slow division algorithm (Restoring division)
2
--! http://en.wikipedia.org/wiki/Division_%28digital%29
3
library IEEE;
4
use IEEE.STD_LOGIC_1164.ALL;
5
use IEEE.std_logic_arith.all;
6
 
7
entity divisor is
8
    Port ( rst : in  STD_LOGIC;
9
           clk : in  STD_LOGIC;
10
           quotient : out  STD_LOGIC_VECTOR (31 downto 0);
11
                          reminder : out  STD_LOGIC_VECTOR (31 downto 0);
12
           numerator : in  STD_LOGIC_VECTOR (31 downto 0);
13
           divident : in  STD_LOGIC_VECTOR (31 downto 0);
14
           done : out  STD_LOGIC);
15
end divisor;
16
 
17
architecture Behavioral of divisor is
18
 
19
begin
20
 
21
        -- Division algorithm Q=N/D
22
        process (rst, clk)
23
        variable Q : unsigned(quotient'length-1 downto 0);
24
        variable R : unsigned(reminder'length-1 downto 0);
25
        variable D : unsigned(reminder'length-1 downto 0);
26
        variable N : unsigned(reminder'length-1 downto 0);
27
        variable iteractions : integer;
28
        begin
29
                if (rst = '1') then
30
                        quotient <= (others => '0');
31
                        reminder <= (others => '0');
32
                        done <= '0';
33
 
34
                        -- Initialize variables
35
                        iteractions := quotient'length;
36
                        D := unsigned(divident);
37
                        N := unsigned(numerator);
38
                        -- initialize quotient and remainder to zero
39
                        Q := (others => '0');
40
                        R := (others => '0');
41
                elsif rising_edge(clk) then
42
                        if iteractions > 0 then
43
                                iteractions := iteractions - 1;
44
                                -- left-shift R by 1 bit 
45
                                R := (R((R'HIGH - 1) downto 0) & '0');
46
 
47
                                --set the least-significant bit of R equal to bit i of the numerator(dividend)
48
                                R(0)     := N(iteractions);
49
 
50
                                if (R >= D) then
51
                                        R := R - D;
52
                                        Q(iteractions) := '1';
53
                                end if;
54
                        else
55
                                done <= '1';
56
                                quotient <= CONV_STD_LOGIC_VECTOR(Q,32);
57
                                reminder <= CONV_STD_LOGIC_VECTOR(R,32);
58
                        end if;
59
                end if;
60
        end process;
61
 
62
end Behavioral;
63
 

powered by: WebSVN 2.1.0

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