Well..
Below is the RAM code that I've done in VHDL.
library ieee;
use ieee.std_logic_1164.all;
use IEEE.numeric_std.all;
entity RAM is
port ( A0,A1,A2,A3 : in std_logic;
CS : in std_logic;
clk : in std_logic;
R_Wbar : in std_logic;
Data : inout std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (7 downto 0)); -- for testing
end RAM;
Architecture version1 of RAM is
signal Addr : unsigned (3 downto 0);
type MEM is array (15 downto 0) of std_logic_vector (7 downto 0);
signal MEM_s : MEM;
Begin
Addr <= (A0 & A1 & A2 & A3);
Process (clk)
variable Addr_int : integer;
Begin
if Rising_Edge(clk) then
Addr_int := TO_INTEGER(Addr);
if (CS = '0') then
if (R_Wbar = '0') then
MEM_s(Addr_int) <= Data;
DataOut <= MEM_s(Addr_int);
elsif (R_Wbar = '1') then
Data <= MEM_s(Addr_int) ;
DataOut <= Data;
end if;
end if;
end if;
End process;
End version1;
What I set in waveform simulator before the simulation is shown in BeforeSim.jpg attached below.
The result of the simulation is shown in AfterSim.jpg also attached below.
In the first clock pulse, the address of the RAM (A0 to A3) is all 0.
I manually set the Data pin (of the RAM) to 1. Since this is the writing process (because R_Wbad is 0, I was hoping to get "11111111" in the DataOut pin (output pin to display the array values). However, I got "00000000" instead.
In the following clock pulse (supposed to be the reading cycle to read the information in the array), the Data pin (of the RAM) is at high impedance state. What I hope to get is the value for Data and DataOut to both be "11111111" because "11111111" is written in the first clock pulse.
If this is C#, my next action would be to use the built in debugger to try to figure out what went wrong. However, since I am new to VHDL, I am totally lost.. I am not even sure if the data is actually written into the RAM's array.
Please advice..
Thanks..