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 11

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 9 leonardoar
use IEEE.std_logic_arith.all;
6
 
7
--! Use CPU Definitions package
8
use work.pkgDefinitions.all;
9 5 leonardoar
 
10
entity divisor is
11
    Port ( rst : in  STD_LOGIC;
12
           clk : in  STD_LOGIC;
13 9 leonardoar
           quotient : out  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
14
                          reminder : out  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
15
           numerator : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
16
           divident : in  STD_LOGIC_VECTOR ((nBitsLarge-1) downto 0);
17 5 leonardoar
           done : out  STD_LOGIC);
18
end divisor;
19
 
20
architecture Behavioral of divisor is
21
 
22
begin
23
 
24
        -- Division algorithm Q=N/D
25
        process (rst, clk)
26
        variable Q : unsigned(quotient'length-1 downto 0);
27
        variable R : unsigned(reminder'length-1 downto 0);
28
        variable D : unsigned(reminder'length-1 downto 0);
29
        variable N : unsigned(reminder'length-1 downto 0);
30
        variable iteractions : integer;
31
        begin
32
                if (rst = '1') then
33
                        quotient <= (others => '0');
34
                        reminder <= (others => '0');
35
                        done <= '0';
36
 
37
                        -- Initialize variables
38
                        iteractions := quotient'length;
39
                        D := unsigned(divident);
40
                        N := unsigned(numerator);
41
                        -- initialize quotient and remainder to zero
42
                        Q := (others => '0');
43
                        R := (others => '0');
44
                elsif rising_edge(clk) then
45
                        if iteractions > 0 then
46
                                iteractions := iteractions - 1;
47
                                -- left-shift R by 1 bit 
48
                                R := (R((R'HIGH - 1) downto 0) & '0');
49
 
50
                                --set the least-significant bit of R equal to bit i of the numerator(dividend)
51
                                R(0)     := N(iteractions);
52
 
53
                                if (R >= D) then
54
                                        R := R - D;
55
                                        Q(iteractions) := '1';
56
                                end if;
57
                        else
58
                                done <= '1';
59
                                quotient <= CONV_STD_LOGIC_VECTOR(Q,32);
60
                                reminder <= CONV_STD_LOGIC_VECTOR(R,32);
61
                        end if;
62
                end if;
63
        end process;
64
 
65
end Behavioral;
66
 

powered by: WebSVN 2.1.0

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