00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/coin/division.vhd,v $
00015 --* $Revision: 1.3.2.3 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:42 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023
00024 library ieee;
00025
00026 use ieee.std_logic_1164.all;
00027
00028 use ieee.numeric_std.all;
00029
00030
00031
00032
00033
00034 entity division is
00035
00036 generic (
00037 DIVISOR : := 4096
00038 );
00039 port (
00040 CLK : in ;
00041 RES : in ;
00042 A : in (15 downto 0);
00043 C : out (15 downto 0)
00044 );
00045
00046 end division;
00047
00048
00049
00050
00051
00052 architecture division_arc of division is
00053
00054
00055 function safe_div (
00056 A : )
00057 return is
00058 variable Ai : ;
00059 variable ret : := 2;
00060 begin -- safe_div
00061 Ai := A;
00062 while 0 < 1 loop
00063 if Ai < 2 then
00064 ret := 2;
00065 exit;
00066 else
00067 if Ai mod 2 /= 0 then
00068 Ai := Ai - 1;
00069 else
00070 ret := Ai;
00071 exit;
00072 end if;
00073 end if;
00074 end loop;
00075 return ret;
00076 end safe_div;
00077
00078
00079 constant c_divisor : := safe_div(DIVISOR);
00080
00081 begin -- division_arc
00082
00083
00084 div : process (CLK)
00085 begin -- process div
00086 if CLK'event and CLK = '1' then -- rising clock edge
00087 if RES = '1' then
00088 C <= (others => '0');
00089 else
00090 C <= A / c_divisor;
00091 end if;
00092 end if;
00093 end process div;
00094
00095 end division_arc;