EmbDev.net

Forum: FPGA, VHDL & Verilog Width Mismatch in RAM Design


von Ed H. (howerj)


Rate this post
useful
not useful
So the issue I am having is that on the line: "data <= 
mem(conv_integer(address));" I get the following error: "width mismatch 
in assignment, target has 8-bits, source has 4-bits."
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
entity ram is   
5
port (
6
address :in    std_logic_vector ( 3 downto 0); 
7
data    :inout std_logic_vector ( 7 downto 0); 
8
cs      :in    std_logic;                                
9
we      :in    std_logic;                                
10
oe      :in    std_logic                                 
11
);
12
end ram;
13
architecture beh_ram of ram is
14
type memory is array (0 to 15)of std_logic_vector (3 downto 0);
15
signal mem : memory ;
16
begin
17
MEM_WRITE:
18
process (address, data, cs, we) 
19
begin
20
if (cs = '1' and we = '1') then
21
mem(conv_integer(address)) <= data;
22
end if;
23
end process;
24
MEM_READ:
25
process (address, cs, we, oe, mem) begin
26
if (cs = '1' and we = '0' and oe = '1')  then               
27
data <= mem(conv_integer(address));  
28
else
29
data <=  (others => 'Z' );
30
end if;
31
end process;
32
end beh_ram;

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Ed H. wrote:
> error: "width mismatch in assignment, target has 8-bits, source has
> 4-bits."
Thats correct.

data is a std_logic_vector ( 7 downto 0), the RAM is a array "of 
std_logic_vector (3 downto 0)".
So, what 4 bits of data do you want to store in the memory?

With this you won't get errors:
mem(conv_integer(address)) <= data(3 downto 0);
data <= "0000" & mem(conv_integer(address));
Wether thats OK to do it that way or not is up to you...

von Ed H. (howerj)


Rate this post
useful
not useful
Lothar M. wrote:
> Ed H. wrote:
>> error: "width mismatch in assignment, target has 8-bits, source has
>> 4-bits."
> Thats correct.
>
> data is a std_logic_vector ( 7 downto 0), the RAM is a array "of
> std_logic_vector (3 downto 0)".
> So, what 4 bits of data do you want to store in the memory?
>
> With this you won't get errors:
> mem(conv_integer(address)) <= data(3 downto 0);
> data <= "0000" & mem(conv_integer(address));
> Wether thats OK to do it that way or not is up to you...
So I just changed the array to hold 8-bits as shown below, but now I get 
an error that states "pin data[0]....[7] has multiple drivers."
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
entity ram is   
5
port (
6
address :in    std_logic_vector ( 3 downto 0); 
7
data    :inout std_logic_vector ( 7 downto 0); 
8
cs      :in    std_logic;                                
9
we      :in    std_logic;                                
10
oe      :in    std_logic                                 
11
);
12
end ram;
13
architecture beh_ram of ram is
14
type memory is array (0 to 15)of std_logic_vector (7 downto 0);
15
signal mem : memory ;
16
begin
17
MEM_WRITE:
18
process (address, data, cs, we) 
19
begin
20
if (cs = '1' and we = '1') then
21
mem(conv_integer(address)) <= data;
22
end if;
23
end process;
24
MEM_READ:
25
process (address, cs, we, oe, mem) begin
26
if (cs = '1' and we = '0' and oe = '1')  then               
27
data <= mem(conv_integer(address));  
28
else
29
data <=  (others => 'Z' );
30
end if;
31
end process;
32
end beh_ram;

von Markus F. (mfro)


Rate this post
useful
not useful
Ed H. wrote:
> "pin data[0]....[7] has multiple drivers."

that might be the case, but not in the code shown as far as I can see.

von 42 - Only the right quesions leads to an answer (Guest)


Rate this post
useful
not useful
Which Tools throws the error (Simulation, Synthesis)?
Do you really wanout direction inout at the mem?
Does your design holds a correct working Output enable (oe) control?

Do you got a block diagramm showing shared busses?

von Ed H. (howerj)


Attached files:

Rate this post
useful
not useful
42 - Only the right quesions leads to an answer wrote:
> Which Tools throws the error (Simulation, Synthesis)?
> Do you really wanout direction inout at the mem?
> Does your design holds a correct working Output enable (oe) control?
>
> Do you got a block diagramm showing shared busses?
Synthesis throws the error.
I will attach my files. I am trying to design a Random Access Memory to 
write 4’b1010 into 16 bit address location of RAM. After complete 
writing, read the data out of the RAM. Also adding clock division to 
this design so that the data can be read out of the RAM at 10 KHz rate 
and display the address and data bus on a logic analyzer.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.