Altera_Forum
Honored Contributor
16 years agoTakes too long to get address
I'm writing a simple program that reads and writes to RAM. If I want to write, I provide the starting address and a valid signal and I write to memory starting at that address until valid is deasserted. If I want to read, I provide a starting address and a readEn signal and I read from memory starting at that address until readEn is deasserted. The problem is that for some reason, the way I'm incrementing starting addresses takes an extra clock cycle and I can't figure out why.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity framestore is
port
(
clk,reset : in std_logic;
input: in std_logic_vector(3 downto 0);
valid: in std_logic;
readEN: in std_logic;
rwaddressstart: in std_logic_vector(14 downto 0);
output : out std_logic_vector(3 downto 0);
addressout: out std_logic_vector(14 downto 0);
holdout: out std_logic_vector(3 downto 0)
);
end framestore;
architecture structure of framestore is
signal hold: std_logic_vector(3 downto 0);
signal address: std_logic_vector(14 downto 0);
signal tempvalid: std_logic;
signal tempread: std_logic;
signal readEn_RE: boolean;
signal valid_RE: boolean;
component ram4bits is
PORT
(
address : IN STD_LOGIC_VECTOR (14 DOWNTO 0);
clock : IN STD_LOGIC := '1';
data : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
wren : IN STD_LOGIC ;
q : OUT STD_LOGIC_VECTOR (3 DOWNTO 0)
);
end component;
begin
process(clk,reset,valid,readEn)
begin
if(reset = '1') then
address <= "000000000000000";
elsif(clk'event and clk = '1') then
tempread <= readEn;
tempvalid <= valid;
if(valid_RE or readEn_RE) then
address <= rwaddressstart;
elsif(valid = '1' or readEn = '1') then
address <= address + '1';
end if;
end if;
end process;
store: ram4bits port map(address,clk,input,valid,hold);
readEn_RE <= tempread <= '0' and readEn = '1';
valid_RE <= tempvalid <= '0' and valid = '1';
output <= hold when readEn = '1' else "0000";
addressout <= address;
holdout <= hold;
end structure;
The problem is that this code I think happens a cycle too late:
if(valid_RE or readEn_RE) then
address <= rwaddressstart;