Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Loading Text File to sram on altera DE2-115 cyclone 5 using vhdl

Status
Not open for further replies.

aliceacapana

Newbie level 2
Joined
Nov 15, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
21
Hello All,

I'm trying to load a text file into sram of altera de2-115 using vhdl. I'm not very efficient in vhdl coding and am looking for help. It would be great if anyone could help me with it.....
Thanks in advance!!

Alice
 

VHDL contains functions for file IO. However, they cannot be synthesized. They are intended for testbench usage only!

Could you tell us a bit more about the nature of data in the text file? Is it a look up table or otherwise? The standard method is to create a .hex or .mif file for our data then specify to quartus that we want the memory to be "initiated with this data" in the options in the GUI when creating the memory block.

You will have to parse the text file to create a mif or hex file both of which are type of ASCII files, by using a script or otherwise.

I have done a project in which I had to put data of multiple .wav files into memory block. In this case I studied the structure of the .wav files i.e the file specification. I then wrote C++ program that read each .wav file, strip the headers and combine them into a binary file as contiguous blocks. It created a single header in this new binary file which created start and end address of each .wav file's sound data and offset could be calculated from this data to read .wav samples.

I then wrote another C++ program which was simpler, that read the binary file and converted it into a .hex file, something which required me to study the structure of the .hex files. But it seems to have worked out at the end.

So sorry for going off on a tangent, but you will need a program to convert the text file into hex or mif for use with altera tools. But before you do that, pleaes tell us what type of data is contained in the text file that needs to be put into memory blocks.
 

If it is a Xilinx Chip, you can use the textio functions to set the initial contents of the ram.
 

Loading Text File to sram on altera DE2-115 cyclone 5 using vhdl

If it is a Xilinx Chip, you can use the textio functions to set the initial contents of the ram.

[SOLVED] Loading Text File to sram on altera DE2-115 cyclone 5 using vhdl


Quixotic Victory.

--edit: after seeing the actual results of my editing, I think this might be misinterpreted as an insult. I find humor in many things, and this was one. It was not meant as an insult in any way and I enjoy TD's responses to threads. When I first typed it, it seemed less funny if I would have added an explaination.
 
Last edited:

Quixotic Victory.

--edit: after seeing the actual results of my editing, I think this might be misinterpreted as an insult. I find humor in many things, and this was one. It was not meant as an insult in any way and I enjoy TD's responses to threads. When I first typed it, it seemed less funny if I added an explaination.

Must read posts better next time.

To the OP: in that case only options are initialisation via a .mif file, or via an initialisation function in VHDL.

On the other hand, if you want to load it during runtime, you'll need to get the data into the ram somehow - how about an RS232 link from a PC?
 

Must read posts better next time.

Ok, thanks for not taking that personally. Part of me just loves the "if you know altera???" "i know xilinx..." "my problems are solved!!!" combo.
 

The text file can have any type of data be it plain text, binary data, ASCII or hex data. I wrote a VHDL program to load text file contents onto sram and display them on lcd display, but not sure if it's right or not. Can you have a look at it and let me know if it's right or not?

Code:
library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;

entity lcd is
port(clk : in std_logic;
RW: out std_logic;  
RS: out std_logic;  
E: out std_logic;   
lcd_data: inout std_logic_vector(7 downto 0);  
addr_sram : out std_logic_vector(19 downto 0); 
data_sram : inout std_logic_vector(15 downto 0);
CE_N: out std_logic;
OE_N: out std_logic;  
WE_N: out std_logic;  
LB_N: out std_logic;  
UB_N: out std_logic); 
end lcd;

architecture beh of lcd is
signal lcd_enable: std_logic; 
signal lcd_busy: std_logic;    
signal busy: std_logic := '1'; 
signal a,b,c:integer := 0;     
signal lcd_bus: std_logic_vector(9 downto 0); 
signal data1: std_logic_vector(9 downto 0);   
signal data2: std_logic_vector(9 downto 0);  
signal addr1: std_logic_vector(19 downto 0):=x"00000";  
signal r_reg: unsigned(19 downto 0):=x"00000"; 
signal r_inc: unsigned(19 downto 0);  

type state_type is (power_up,initialize,addr_increment,b0,b2,b3,b4,b1,delay,ready,send);
signal state : state_type;
begin
WE_N<='1'; 
OE_N<='0';
CE_N<='0';
UB_N<='0';
LB_N<='0';

process(clk)
variable char: integer range 0 to 6 := 1;
variable clk_count: integer := 0; 
begin
if(clk' event and clk='1') then 

case state is

when power_up=>
clk_count := 0;
RS<= '0';  
RW<= '0';  
lcd_data<= "00110000"; 
state<=initialize;

when initialize=>
clk_count := clk_count+1;
if(clk_count <(2000)) then 
lcd_data <= "00111100"; 
E<='1';
E<='0';
lcd_data <= "00001100";
E<='1';
E<='0';
lcd_data <= "00000001"; 
E<='1';
state <= initialize;
elsif(clk_count < (100000)) then 
lcd_data <= "00000000"; 
E<='1';
E<='0';
lcd_data<="00001100"; 
E<='1';
E<='0';
lcd_data<="00000001"; 
E<='1';
state <= initialize;
elsif(clk_count<(100000)) then
lcd_data <= "00000000";
E<='0';
state<=initialize;
else
clk_count := 0;
state<=b0;
end if;

when b0=>
r_reg<= unsigned(addr1);
r_inc<=r_reg+1;
r_reg<=r_inc;

addr_sram<=std_logic_vector(r_reg); 
data1(9 downto 8)<="10";
data2(9 downto 8)<="10";
data1(7 downto 0)<=data_sram(7 downto 0);
data2(7 downto 0)<=data_sram(15 downto 8);
b<=b+1;
state<=b2;

when b2=>
if(b<3) then
b<=b+1;
state<=b0;
else
b<=0;
state<=b1;
c<=c+1;

end if;

when b3=>

lcd_enable<='1';
lcd_bus(9 downto 8)<="00";
lcd_bus(7 downto 0)<="11000000";
c<=c+1;
state<=ready;

when b4=>
RS<='0';
RW<='0';
clk_count := clk_count+1;
if(clk_count<(2000)) then
lcd_data <= "00000001";
E<='1';
state<=b4;
elsif(clk_count<(100000)) then
lcd_data<="00000000";
E<='0';
state<=b4;
else
clk_count := 0;
c<=0;
r_reg<=unsigned(addr1);
r_inc<= r_reg+1;
r_reg<= r_inc;

addr_sram<=std_logic_vector(r_reg);
state<=b0;
end if;

when b1=>
lcd_enable<='1';
if(char<4) then
char := char+1;
end if;
case char is
when 2=>
lcd_bus<=data1;
state<=ready;
when 3=>
lcd_bus<=data2;
char := 1;
state<=ready;

when others=> lcd_enable<='0';
state<=addr_increment;
end case;
			----------- wait for the enable signal 
when ready=>
if(lcd_enable='1') then
busy<='1';
RS<=lcd_bus(9);
RW<=lcd_bus(8);
lcd_data<=lcd_bus(7 downto 0);
clk_count := 0;
state<=send;
else
busy<='0';
RS<='0';
RW<='0';
lcd_data<="00000000";
clk_count := 0;
state<=ready;
end if;

when send=>
busy<='1';
if(clk_count<(600)) then 
busy<='1';
if(clk_count<(50)) then  
E<='0';
elsif(clk_count<(200)) then 
E<='1';
elsif(clk_count<(500)) then  
E<='0';
end if;
clk_count := clk_count+1;
state<=send;
else
clk_count := 0;
state<=delay;
end if;

when delay=>
if(a<20000000) then
a<=a+1;
state<=delay;
else
a<=0;
state<=addr_increment;
end if;
 when addr_increment=>
 if(char=1 and c=8) then
 state<=b3;
 elsif(char=1 and c=17) then
 state<=b4;
 c<=0;
 elsif(char=1) then
 state<=b0;
 else
 state<=b1;
 end if;
 
 end case;
 end if;
 end process;
 end beh;
 

Write a testbench and run it on a simulator instead of asking someone here to write a testbench and debug the design for you.

I think you are going to have problems with the char variable (probably also with your clk_count variable) as you use it as a counter and "read" the value elsewhere in the code.
I recommend you don't use variables unless you know what synthesis will do with them.

Also format your code, the formatting stinks (as there is NO formatting in the first place).

What are you expecting this code to do:
Code:
r_reg<=unsigned(addr1);
r_inc<= r_reg+1;
r_reg<= r_inc;
I think you are attempting to writing code like an imperative program. You mistakenly think you are incrementing addr1 and loading it into r_reg.

I think you'll be very surprised with what your code does if you simulate it. Probably does something completely different than what you expect.

- - - Updated - - -

I wrote a VHDL program to load text file contents onto sram and display them on lcd display
BTW where is this code that somehow manages to read in a text file and initializes a RAM?

Must be written in invisible characters as it doesn't seem to show up anywhere in your code. :-?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top