گروه الکترونیک مدرس
گروه الکترونیک مدرس

گروه الکترونیک مدرس

الکترونیک

vhdl code for division of two fixed point numbers

dear all,

I need to do the division of two fixed point numbers.Can anybody help me to do coding for this.

eg: 1.75 /1.5

1.75 is 0000000111000000(16 bit representation)
1.5 is 0000000110000000(16 bit representation).

1.75 /1.5=1.166667. =0000000100101011.

تقسیم در vhdl

VHDL code for dividing integers

library ieee;
use ieee.std_logic_1164.all;

entity division is
port ( a : in integer range 0 to 255;
b : in integer range 0 to 17;
quo : out integer range 0 to 17);
end division;

architecture structure of division is

begin
process(a,b)
variable var : integer range 0 to 255;
variable count,i : integer range 0 to 127;

begin
i:=0; var:=a;count:=0;
for i in 127 downto 0 loop
if (var>=b) then var :=var-b;count:=count+1;
else
quo<=count;exit;
end if;
end loop;
end process;
end structure;

ماتریس در بردار


LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
entity DCT_beh is
    port (
            Clk :           in std_logic;
            Start :         in std_logic;
            Din :           in INTEGER;
            Done :          out std_logic;
            Dout :          out INTEGER
          );
 end DCT_beh;

architecture behavioral of DCT_beh is
begin
    process
            type RF is array ( 0 to 7, 0 to 7 ) of INTEGER;
 type RF is array ( 0 to 7, 0 to 7 ) of INTEGER;

            variable i, j, k        : INTEGER;
            variable InBlock        : RF;
            variable COSBlock       : RF;
            variable TempBlock      : RF;
            variable OutBlock       : RF;
            variable A, B, P, Sum   : INTEGER;

    begin

            COSBlock := (
    ( 125,  122,    115,    103,    88,     69,     47,     24  ),
    ( 125,  103,    47,     -24,    -88,    -122,   -115,   -69  ),
    ( 125,  69,     -47,    -122,   -88,    24,     115,    103  ),
    ( 125,  24,     -115,   -69,    88,     103,    -47,    -122  ),
    ( 125,  -24,    -115,   69,     88,     -103,   -47,    122  ),
    ( 125,  -69,    -47,    122,    -88,    -24,    115,    -103  ),
    ( 125,  -103,   47,     24,     -88,    122,    -115,   69  ),
    ( 125,  -122,   115,    -103,   88,     -69,    47,     -24  )
                    );
 InBlock := (
    ( 125,  0,    0,    0,    0,     0,     0,     0  ),
    ( 125,  0,    0,     0,    0,    0,   0,   0  ),
    ( 125,  0,     0,    0,   0,    0,     0,    0  ),
    ( 125,  0,     0,   0,    0,     0,    0,    0  ),
    ( 125,  0,    0,   0,     0,     0,   0,   0  ),
    ( 125,  0,    0,    0,    0,    0,    0,    0  ),
    ( 125,  0,   0,     0,     0,    0,    0,   0  ),
    ( 125,  0,   0,    0,   0,     0,    0,     0)
                    );

TempBlock      := (
    ( 0,  0,    0,    0,    0,     0,     0,     0  ),
    ( 0,  0,    0,     0,    0,    0,   0,   0  ),
    ( 0,  0,     0,    0,   0,    0,     0,    0  ),
    ( 0,  0,     0,   0,    0,     0,    0,    0  ),
    ( 0,  0,    0,   0,     0,     0,   0,   0  ),
    ( 0,  0,    0,    0,    0,    0,    0,    0  ),
    ( 0,  0,   0,     0,     0,    0,    0,   0  ),
    ( 0,  0,   0,    0,   0,     0,    0,     0)
                    );


    for i in 0 to 7 loop
        for j in 0 to 7 loop
            Sum := 0;
            for k in 0 to 7 loop
                A := COSBlock( i, k );
                B := InBlock( k, 0 );
                P := A * B;
                Sum := Sum + P;
                if( k = 7 ) then
                TempBlock( i, 0 ) := Sum;
                end if;
            end loop;
        end loop;
    end loop;


--Finishing

    wait until Clk = '1' and Clk'event;
    Done <= '1';

--Output Data

    for i in 0 to 7 loop
        for j in 0 to 7 loop
            wait until Clk = '1' and Clk'event;
            Done <= '0';
            Dout <=  tempblock(i,j);
        end loop;
    end loop;
end process;      
 end behavioral;