Guest
hi..
I want to design a MAC(multiply-accumulator).I have written the
following code.The problem is ,when I do place & route in Xilinx ISE
7.1version,I get too many timing errors(around 30).My clock is 70Mhz.
entity mac is
generic(
input_width1 : integer:= 16;
input_width2 : integer:= 16;
output_width : integer := 36;
mac_cycle_width : integer := 4
);
port (
RESET : IN STD_LOGIC;
CLK : IN STD_LOGIC;
FD : IN STD_LOGIC;
ND : IN STD_LOGIC;
A : IN STD_LOGIC_VECTOR(input_width1-1 DOWNTO 0);
B : IN STD_LOGIC_VECTOR(input_width2-1 DOWNTO 0);
Q : OUT STD_LOGIC_VECTOR(output_width-1 DOWNTO 0);
RDY : OUT STD_LOGIC
);
end entity mac;
architecture rtl of mac is
signal cycle : STD_LOGIC_VECTOR(mac_cycle_width-1 DOWNTO 0);
signal rdy1 : std_logic;
signal sum : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
signal temp2 : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
signal prod : STD_LOGIC_VECTOR (input_width1 + input_width2 -1
DOWNTO 0);
begin
-- cycle determines the no of mac accumulations
-- fd indicates the start of new accumulation
process(reset,clk)
begin
if reset = '1' then
cycle <= (others =>'0');
elsif(clk'event and clk = '1')then
if ( fd = '1')then
cycle
<=conv_std_logic_vector((1),cycle'length);--"0001";--conv_std_logic_vector((1),cycle'length);
--;
else
cycle <= cycle +'1';
end if;
end if;
end process;
-- ND indicates that the new data is ready at the input.
-- the 2 inputs are multiplied and the product is added
-- to the previous accumulator result .
-- In the last cycle the accumulator result is given out and at
-- same time the accumulator is reset to zeros.
-- here the accumulator is variable temp1.
-- SUM holds the final accumulated result and temp2 holds the
-- intermediate results.
process(reset,clk)
variable temp1 : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
begin
if(reset ='1')then
sum <= (others => '0');
prod <= (others => '0');
temp1 := (others => '0');
elsif( clk'event and clk ='0')then
if (nd ='1')then
prod <= A * (B);
temp1 := temp1 + prod;
if( cycle=conv_std_logic_vector((0),cycle'length))then
--"0000"--conv_std_logic_vector((0),cycle'length)
sum <= temp1;
temp1 := (others => '0');
end if;
end if;
end if;
temp2 <= temp1;
end process;
-- here Q indicates the accumulator output during all cycles
-- SUM holds the final accumulated result and temp2 holds the
-- intermediate results. both are combined to form Q.
process(clk)
begin
if( clk'event and clk ='1')then
if (
cycle=conv_std_logic_vector((0),cycle'length))then--"0000"--conv_std_logic_vector((0),cycle'length)
q <= sum;
else
q <= temp2;
end if;
end if;
end process;
--q <= sum;
-- At the end of MAC cycle rdy is generated to indicated
-- that the MAC output is ready.
process(reset,clk)
begin
if(reset ='1')then
rdy1 <= '0';
elsif( clk'event and clk ='1')then -- ori '1'
if( cycle=conv_std_logic_vector((0),cycle'length))then
--"0000"conv_std_logic_vector((0),cycle'length)
rdy1 <= '1';
else
rdy1 <= '0';
end if;
end if;
end process;
rdy <= rdy1;
end rtl;
I want to design a MAC(multiply-accumulator).I have written the
following code.The problem is ,when I do place & route in Xilinx ISE
7.1version,I get too many timing errors(around 30).My clock is 70Mhz.
entity mac is
generic(
input_width1 : integer:= 16;
input_width2 : integer:= 16;
output_width : integer := 36;
mac_cycle_width : integer := 4
);
port (
RESET : IN STD_LOGIC;
CLK : IN STD_LOGIC;
FD : IN STD_LOGIC;
ND : IN STD_LOGIC;
A : IN STD_LOGIC_VECTOR(input_width1-1 DOWNTO 0);
B : IN STD_LOGIC_VECTOR(input_width2-1 DOWNTO 0);
Q : OUT STD_LOGIC_VECTOR(output_width-1 DOWNTO 0);
RDY : OUT STD_LOGIC
);
end entity mac;
architecture rtl of mac is
signal cycle : STD_LOGIC_VECTOR(mac_cycle_width-1 DOWNTO 0);
signal rdy1 : std_logic;
signal sum : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
signal temp2 : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
signal prod : STD_LOGIC_VECTOR (input_width1 + input_width2 -1
DOWNTO 0);
begin
-- cycle determines the no of mac accumulations
-- fd indicates the start of new accumulation
process(reset,clk)
begin
if reset = '1' then
cycle <= (others =>'0');
elsif(clk'event and clk = '1')then
if ( fd = '1')then
cycle
<=conv_std_logic_vector((1),cycle'length);--"0001";--conv_std_logic_vector((1),cycle'length);
--;
else
cycle <= cycle +'1';
end if;
end if;
end process;
-- ND indicates that the new data is ready at the input.
-- the 2 inputs are multiplied and the product is added
-- to the previous accumulator result .
-- In the last cycle the accumulator result is given out and at
-- same time the accumulator is reset to zeros.
-- here the accumulator is variable temp1.
-- SUM holds the final accumulated result and temp2 holds the
-- intermediate results.
process(reset,clk)
variable temp1 : STD_LOGIC_VECTOR (output_width-1 DOWNTO 0);
begin
if(reset ='1')then
sum <= (others => '0');
prod <= (others => '0');
temp1 := (others => '0');
elsif( clk'event and clk ='0')then
if (nd ='1')then
prod <= A * (B);
temp1 := temp1 + prod;
if( cycle=conv_std_logic_vector((0),cycle'length))then
--"0000"--conv_std_logic_vector((0),cycle'length)
sum <= temp1;
temp1 := (others => '0');
end if;
end if;
end if;
temp2 <= temp1;
end process;
-- here Q indicates the accumulator output during all cycles
-- SUM holds the final accumulated result and temp2 holds the
-- intermediate results. both are combined to form Q.
process(clk)
begin
if( clk'event and clk ='1')then
if (
cycle=conv_std_logic_vector((0),cycle'length))then--"0000"--conv_std_logic_vector((0),cycle'length)
q <= sum;
else
q <= temp2;
end if;
end if;
end process;
--q <= sum;
-- At the end of MAC cycle rdy is generated to indicated
-- that the MAC output is ready.
process(reset,clk)
begin
if(reset ='1')then
rdy1 <= '0';
elsif( clk'event and clk ='1')then -- ori '1'
if( cycle=conv_std_logic_vector((0),cycle'length))then
--"0000"conv_std_logic_vector((0),cycle'length)
rdy1 <= '1';
else
rdy1 <= '0';
end if;
end if;
end process;
rdy <= rdy1;
end rtl;