masoud.malekzadeh
Member level 1
I have defined a component as an adder how can i add rows of ROM ?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I wonder why the IP generates using a "clk" for your adder design. I think couldbe because to make the latency finite say 1 clks. Fine, but
why does the output width seem to be same as input 32 bits, but it shouldbe 33, if you dont want to omit the carry bit. Or have you set it IP parameters?.
everything in an FPGA should be clocked - so why wouldnt an adder have one?
Floating point takes several clock cycles to complete in any decent amount of time. For altera FP cores, the default value for a floating point square root is 48 clocks IIRC.
Yes I see what you're saying, but why go to the bother of adding them externally when its just cleaner to contain them internally. Many IP cores like this have a pipeline parameter which allows you to set the pipeline length - for timing reasons and also to ensure pipe lneghts match across parralllel pipelines. You can usually set this to 0 if you really want it unregistered (but why bother if you're going to add them externally)?
In addition, some compilers allow register retiming, which mean they can pull registers into the IP if they fail to meet timing, but its much easier just to set a pipe length and let the retiming deal with those, rather than working out which external registers it is allowed to use.
Then finally - some multiply/accumulators have embedded registers. In the past I have seen these registers only used when you included them in the IP. Synthesisors are better now, but why not us the embedded ones? And remember IP cores usually cover different FPGAs, so architecture can vary, and one IP block covers them all.
So many many reasons to have a clock input (and you'd be silly not to use it).
I would be thankful if you suggest me a way to add Rows of this rom toghether using this component , the clock is not my issue !
for a rom on hardware using internal BRAMs, you can only ever access one element at a time, so you need to create a design that reads the elements from the rom and feeds them into the adder.
I would be thankful if you suggest me a way to add Rows of this rom toghether using this component , the clock is not my issue !
That's not the code I posted, that's what you modified a bit and came up with.process(clk)
begin
if rising_edge(clk) then
if (i <= 9) then
Prev_Sum <= t;
w<=ram(i);
i <= i + 1;
end if;
end if ;
end process;
g1 : adder port map (a => Prev_Sum,b=>w,clk => clk,result =>t);
i used the code above as you said but the Prev_Sum signal some how is always zero and t equals to w ,
Not a clue how you think that what you did is the only way to solve this problemthe only way to solve this problem i modified the length of my array to 8 and used 3 successive For Generate to add the data :
And now you've completely changed whatever the problem is to something completely different. You have many new undeclared signals and no definition now of just what you're trying to do.----------------------- Mean calculation for data 1
GEN_ADDERS1 : for i in 0 to 3 generate
g1:adder port map (a => data1(2*i),b=>data1((2*i)+1),clk => clk,result =>ram1(i));
end generate;
GEN_ADDERS2 : for i in 0 to 1 generate
g1:adder port map (a => ram1(2*i),b=>ram1((2*i)+1),clk => clk,result =>ram2(i));
end generate;
g1:adder port map (a => ram2(0),b=>ram2(1),clk => clk,result =>mean1);
GEN_Subtractor : for i in 0 to 7 generate
g1:subtractor port map (a => data1(i),b=>mean1,clk => clk,result =>res1(i));
end generate;
----------------------- end calculation for data 1
Whatever that is supposed to mean...but my real length of data is 1024 and i have to do this arithmetic so many times ........
library IEEE;
use ieee.std_logic_textio.all;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity adder is
port (
a: in std_logic_vector(31 downto 0);
b: in std_logic_vector(31 downto 0);
clk: in std_logic;
result: out std_logic_vector(31 downto 0));
end adder;
architecture rtl of adder is
begin
result <= std_logic_vector(unsigned(a) + unsigned(b));-- when rising_edge(clk);
end rtl;
library IEEE;
use ieee.std_logic_textio.all;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
use std.textio.all;
entity ROM is
port (
-- x_out: inout std_logic_vector(31 downto 0 );
-- x_in: inout std_logic_vector(31 downto 0 );
clk: in std_logic;
reset: in std_logic
);
end ROM;
architecture Behavioral of ROM is
type ram_type is array (9 downto 0 ) of std_logic_vector(31 downto 0 );
signal ram :ram_type;
signal i : integer range ram_type'range;
signal w:std_logic_vector(31 downto 0);
signal y:std_logic_vector(31 downto 0);
signal t:std_logic_vector(31 downto 0);
signal Prev_Sum:std_logic_vector(31 downto 0);
component adder
port (
a: in std_logic_vector(31 downto 0);
b: in std_logic_vector(31 downto 0);
clk: in std_logic;
result: out std_logic_vector(31 downto 0));
end component;
begin
process
FILE infile : TEXT is in "in_code.txt";
FILE outfile : TEXT IS OUT "out_code.txt";
VARIABLE out_line: LINE;
variable my_line : line;
variable int: std_logic_vector(31 downto 0 ) ;
begin
for i in 0 to 9 loop
readline(infile,my_line);
read (my_line,int);
ram(i)<=int;
write(out_line,int);
writeline(outfile,out_line );
end loop ;
wait; -- Waits forever
end process;
process(clk)
begin
if rising_edge(clk) then
if (reset = '1') then -- Something that resets the accumulated sum to 0
Prev_Sum <= (others => '0'); -- The accumulated sum
i <= 0;
elsif (i <= 8) then
Prev_Sum <= t; -- Save the updated sum
i <= i + 1;
end if;
end if;
end process;
w <= ram(i);
g1 : adder port map (a => w,b=>Prev_Sum,clk => clk,result =>t);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_ROM is
end tb_ROM;
architecture RTL of tb_ROM is
signal clk: std_logic := '0';
signal reset: std_logic;
signal sim_complete: std_logic;
begin
reset <= '1', '0' after 10 ns;
sim_complete <= '0', '1' after 200 ns;
clk <= not(sim_complete) and not(clk) after 5 ns;
DUT : entity work.ROM
port map (
clk => clk,
reset => reset);
end RTL;