Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

Data corrupted, any problem with VHDL codes

HI everyone.

I just have a quick question to ask.

When we use the LOOP in VHDL, is there any chances that the number of times the LOOP is repeated affects the data, say, in the following piece of code, the code "content(i) <= content(i+1)" is repeated 65 times (content is an array of 8bit number), and the data I get at the output of the Modules (dataout[7:0]) is corrupted at some points:

-- ram.vhd

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

entity RAM is

generic ( bits: integer := 8;

words: integer:= 66);

port (clk_in: in std_logic;

clk_out: in std_logic;

we: in std_logic;

re: in std_logic;

reset: in std_logic;

datain: in std_logic_vector(bits - 1 downto 0);

dataout: out std_logic_vector(bits - 1 downto 0)

);

end RAM;

architecture beh of RAM is

signal readp: integer range 0 to words;

type table is array (0 to words - 1) of std_logic_vector(bits-1 downto 0);

signal content: table :=(others => "10000000");

begin

process(reset,clk_in, we)

begin

if (reset = '1') then

content <= (others => "10000000");

elsif (clk_in'event and clk_in = '1') then

if (we = '1') then

for i in 0 to words - 2 loop

content(i) <= content(i+1); --***could it be this line? ***

end loop;

content(words - 1) <= datain;

end if;

end if;

end process;

process(clk_out, re)

begin

if (clk_out'event and clk_out = '1') then

if(re = '1') then

dataout <= content(readp);

end if;

end if;

end process;

process(clk_out, re, reset)

begin

if (reset = '1') then

readp <= 0;

elsif (clk_out'event and clk_out = '0') then

if(re = '1') then

readp <= readp + 1;

if(readp = words - 1) then

readp <= 0;

end if;

end if;

end if;

end process;

end beh;

Any suggestion would be greatlly appreciated.

Cheers.

J.

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can't do this if those are two independent clocks; you will most likely need to either look up how to infer dual port memory from your manufacturer or simply use their dual port ram blocks. If the two clocks are real you really should just put this in one clocked process. Again it's always good to refer to your manufacturers manuals on how to infer RAM. You'll find it's very similar to the way you set up "table" but very unlike your read and write processes. You can read and write with two separate clocks but it will require handshake signals using clock domain synchronization flip flops. It will not be single clock cycle access either.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't see clearly, why you organized the code this way. However, when you write data to the shift register, the content of the complete array is shifted, and can't be accessed consistently for a time interval of several ns. If clock_out is unrelated to clock_in, you have no gurantee to read consistent data. To my opinion, the issue can't be avoided with the present structure.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You seem to infer a dual clock shift register. You better instantiate an altera dual clock ram.

    Your loop is not the problem but it could be your use of two clocks going wrong.