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.

Read, write data to Spartan-3E

Status
Not open for further replies.

amac5

Newbie level 3
Joined
Feb 23, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
Hi all,

I am somewhat new to FPGA design (most of my background is in analog electronics) and I am seeking guidance/advice on the best way to

1. Read a vector of data (text file generated in Matlab) into a Spartan-3E
2. Perform some computations on the data (like FFT)
3. Write the data back out to an output file on my PC to be read by MATLAB.

I am using VHDL in the ISE Webpack from Xilinx.

My main concern right now is getting the input/output part of this project working. What is the best way to do this? I have investigated using the STD.textio.all package to accomplish this. However, I have only been able to get a simple function working in simulation. It seems like something more advanced may be necessary to get this working on the FPGA (like writing to an actual block of RAM in the FPGA).

Here is my code that works in simulation:

Code:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_textio.all;
use STD.textio.all;

entity textfile_io is
	port(clk : in STD_LOGIC);
end textfile_io;

architecture i_o of textfile_io is
	file in_file 			:	text open read_mode is  "input.txt";
	file out_file			:	text open write_mode is "output.txt";
begin

	file_io:
		process (clk)
			variable in_line		:	line;
			variable out_line		:	line;
			variable a, b		:	std_logic;
		begin
			while not endfile(in_file) loop
				readline(in_file, in_line);
				read(in_line, a);
				b := NOT a;	
				write(out_line, b);
				writeline(out_file, out_line);
			end loop;
		end process file_io;
end architecture i_o;


Thanks in advance.
 

If i understand your post correctly, you recent problem is to send data to fpga , and get it (computed ) back? may be the most easy way to send data is to use COM port on your PC(virtual, may be hardware). On fpga you should implement UART.
 
  • Like
Reactions: amac5

    amac5

    Points: 2
    Helpful Answer Positive Rating
Thanks, kirill! Yes, that is my question. So as far as using a COM port, could this be done through a USB connection? Would I need to write another program in C or something that accomplishes this? I will check into UART on the FPGA, I've seen it else where in the forums.
 

Yes, you must write a small programm in C, or another language. Try to google it "Working with COM port Windows" (or Linux). In programm you will work with COM, but it is virtual. Driver in OS will translate automatically COM format packets to USB format packets. For example i working with Xilinx sp605 board. I have USB cable , usb connector on board and IC adapter USB to RS232 om board too. there are a lot of docs about uart in web. hope my posts will help)
 
  • Like
Reactions: amac5

    amac5

    Points: 2
    Helpful Answer Positive Rating
Thanks, kirill! Yes, that is my question. So as far as using a COM port, could this be done through a USB connection? Would I need to write another program in C or something that accomplishes this? I will check into UART on the FPGA, I've seen it else where in the forums.


Hi amac, I am also a noob and I had to do some task like yours.

Do you have any idea on how to read/write textfiles already?
 

Windows
You work with COM, like with file :
---------------------------------------------------------------
HANDLE COMport;
COMport=CreateFile("COM4", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
---------------------------------------------------------------
WriteFile(COMport, &buf_to_send, packetsize, &bc, NULL); // send data
unsigned char buf_to_send [8]; //data
int packetsize; //number of bytes to write
DWORD bc; it is empty, no assignments
---------------------------------------------------------------
ReadFile(COMport, &buffer_rd, blocksize, &bc, NULL); // receive data
---------------------------------------------------------------

Also you need to specify structures DCB, COMMTIMEOUTS , to determine parameters of COM behaviour.
functions for work with structures : GetCommState, SetCommState, GetCommTimeouts, SetCommTimeouts.
for additional tuning : SetupComm, PurgeComm

About all these functions you could fully acquainted at msdn.com
 
  • Like
Reactions: amac5

    amac5

    Points: 2
    Helpful Answer Positive Rating
Hi amac, I am also a noob and I had to do some task like yours.

Do you have any idea on how to read/write textfiles already?

Hey Sundae, I haven't gotten anything implemented yet, but I've learned a lot more since starting. It looks like kirill is right; implementing some sort of RS-232 connection looks to be much easier than doing something using the USB2 protocol. The Spartan-3E and my computer both have a serial port so I may look at doing a straight RS-232 connection without any adapter.

I think I'm going to try and program a UART on the FPGA. I may pick up this book:

Amazon.com: FPGA Prototyping by VHDL Examples: Xilinx Spartan-3 Version (9780470185315): Pong P. Chu: Books

It looks to be pretty helpful, especially chapter 7.

Then I'll have to write some sort of code like kirill posted for Windows to communicate through the COM port.

Hope this helps,

amac

---------- Post added at 16:42 ---------- Previous post was at 16:40 ----------

Windows
You work with COM, like with file :
---------------------------------------------------------------
HANDLE COMport;
COMport=CreateFile("COM4", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
---------------------------------------------------------------
WriteFile(COMport, &buf_to_send, packetsize, &bc, NULL); // send data
unsigned char buf_to_send [8]; //data
int packetsize; //number of bytes to write
DWORD bc; it is empty, no assignments
---------------------------------------------------------------
ReadFile(COMport, &buffer_rd, blocksize, &bc, NULL); // receive data
---------------------------------------------------------------

Also you need to specify structures DCB, COMMTIMEOUTS , to determine parameters of COM behaviour.
functions for work with structures : GetCommState, SetCommState, GetCommTimeouts, SetCommTimeouts.
for additional tuning : SetupComm, PurgeComm

About all these functions you could fully acquainted at msdn.com


Thanks for your help. I'll check out the msdn site.

amac
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top