Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17255 Discussions

Help with a simple RAM code - VHDL

Altera_Forum
Honored Contributor II
1,763 Views

Hello everyone, 

So I have been trying to write a simple VHDL code for a RAM with the following conditions, no success yet. Can anyone please help me with a code?. 

 

1. Say I need a 2KB RAM with 1024 address locations and each location will be filled with 16 bit data. 

2. My first 4 memoy locations should have the value 1122, 3344, 5566, 7788, 9988, and the rest should have values from 0 to 1019 respectively. 

I am struggling with the part where I need the first 4 locations to be a specific value, and the rest to be the counter values from 0 to 1019. I don't know how to write that in VHDL. 

Please help me with a code, . Will be highly appreciated, thanks. 

 

Kind Regards, 

Manoj
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
1,014 Views

 

--- Quote Start ---  

Hello everyone, 

So I have been trying to write a simple VHDL code for a RAM with the following conditions, no success yet. Can anyone please help me with a code?. 

 

1. Say I need a 2KB RAM with 1024 address locations and each location will be filled with 16 bit data. 

2. My first 4 memoy locations should have the value 1122, 3344, 5566, 7788, 9988, and the rest should have values from 0 to 1019 respectively. 

I am struggling with the part where I need the first 4 locations to be a specific value, and the rest to be the counter values from 0 to 1019. I don't know how to write that in VHDL. 

Please help me with a code, . Will be highly appreciated, thanks. 

 

Kind Regards, 

Manoj 

--- Quote End ---  

 

 

I will just instantiate it with mif (with freedom from hdl inference) 

 

fid = fopen('filename.mif','w'); fprintf(fid,'--MIF data generated by MATLAB\n'); fprintf(fid,'--Date: %s \n\n', date); fprintf(fid,'WIDTH=16;\n'); fprintf(fid,'DEPTH=1024;\n'); fprintf(fid,'ADDRESS_RADIX=UNS;\n'); fprintf(fid,'DATA_RADIX=DEC;\n'); fprintf(fid,'CONTENT BEGIN\n'); fprintf(fid,'0 : 1122;\n'); fprintf(fid,'1 : 3344;\n'); fprintf(fid,'2 : 5566;\n'); fprintf(fid,'3 : 7788;\n'); fprintf(fid,'4 : 9988;\n'); for i = 5:1023 fprintf(fid,'%i : %i;\n',i,i-5); end fprintf(fid,'END;'); fclose(fid);
0 Kudos
Altera_Forum
Honored Contributor II
1,014 Views

Thank you. I see that you have used filename.mif, is that from MATLAB? 

Is there a way to write the same program, say using a basic simulator like ModelSIM? 

 

Regards, 

Manoj
0 Kudos
Altera_Forum
Honored Contributor II
1,014 Views

 

--- Quote Start ---  

Thank you. I see that you have used filename.mif, is that from MATLAB? 

Is there a way to write the same program, say using a basic simulator like ModelSIM? 

 

Regards, 

Manoj 

--- Quote End ---  

 

 

Yes that is matlab geneartion 

I believe you can write text file in Modelsim in same way. run a counter 0_1023 

set values for signal temp as your values depending on counter value then write text file out.
0 Kudos
Altera_Forum
Honored Contributor II
1,014 Views

I attach the file if it helps (change extension back to .mif)

0 Kudos
Reply