0

I am trying to send/retreieve data from/to FPGA using Matlab. I connected FPGA using Virtual com port. Now how to send data from Matlab to FPGA or read data of FPGA ?

FTDI 2232H is on the FPGA as well. I connected external LED's and switches on the I/O ports of the FPGA.

I am new in this field, so want some guideline to start communication b/w MAtlab and FPGA:

I tried following code:

  s1= serial('COM9')
  fopen(s1)

. Is it the right way to communicate ? Kindly guide. thanks

Dennis Kriechel
  • 3,719
  • 14
  • 40
  • 62
Nabeel
  • 3
  • 2

1 Answers1

1

FPGA's are configured using a Hardware Description Language (HDL) such as Verilog or VHDL. These languages let you specify how the switch configuration within the FPGA, which in turn lets you construct your custom digital logic and processing system.

The HDL Coder Toolbox in Matlab lets you design and prototype your custom logic using higher-level functions, which are then translated into HDL and can be be used to directly program your chip. This tutorial describes the process in detail.

If you already have a design implemented on your FPGA and want to communicate with that implementation, you would use Matlab's serial port communication functions. The exact protocol will depend on the interface you have implemented.

Some intermediate debugging steps I find helpful:

  1. Verify that you can send serial port data from your computer. In Windows XP, you can do this easily with HyperTerminal, and hooking up a scope to the output pins of your serial cable. Set up a trigger to capture the event. For Windows 7 and newer, you'll need to download a HyperTerminal client.
  2. Repeat this same process with Matlab. Using a scope, verify that you see the serial port signal when sent from Matlab, and that the output matches the results from step 1. Again, set up a scope trigger to capture the event.
  3. Now connect the serial cable directly to the FPGA board. Modify your HDL to include a latch on the serial input that displays the output on the LED's. Verify that your board initializes to the correct LED state, and that the LED state changes when you send the serial message.
  4. Lastly, verify that you are interpreting the message correctly on the FPGA side. This includes making sure that the bit-ordering is correct, etc. Again, the LED outputs can be very helpful for this part.

The key here is to take small, incremental steps, physically verifying that things are working each step of the way.

supyo
  • 3,017
  • 2
  • 20
  • 35
  • I have the verilog code for FTDI chip having Inout 8 bits (FTD7...FTD0) and other inputs and outputs. I added the blink Led code in it too . I can see the output on FPGA by loading bit file . So. I dont need HDL file .. Should i start with serial port communication function(described by you) in Matlab ?? Or anyother thing ?? – Nabeel Jul 05 '13 at 18:23
  • I dont have the serial cable. I connected FPGA by USB port (hence using Virtual com port). . By "SCOPE ", do you mean that i should use the system generator for it in Matalb? – Nabeel Jul 05 '13 at 19:01
  • By scope - I mean a physical oscilloscope, as made by HP or Agilent. They can be very helpful. You might also by an adapter (Google: USB to Serial Adapter) or build your own by clipping a cheap USB cable and stripping the individual wires- so that you can directly hook up the oscilloscope. Again, it is very helpful when you can physically see what's going on- there are a lot of moving pieces here. – supyo Jul 05 '13 at 19:10
  • well, this stuff i will do later on. but your 3rd point : i connected USB cable to FPGA. i have the BLINK LED code with FTDI Chip program. So when i load bit file to FPGA, LEd starts blinking. Now what can the role of Matlab in it ? ( for reading fpga output lines or setting bit high or low ) ? – Nabeel Jul 05 '13 at 19:20
  • That will really depend on your HDL program. At the simplest level, you might program the FPGA to receive a message and display the output on the LED's. One example of a next step would be for the FPGA to receive a number via serial port, increment it by one, and then send the result back to Matlab. Once you have the two-way communication working, there are lots of directions you can go- such as using the FPGA for special-purpose highly optimized/parallel computing, and returning the results to Matlab. – supyo Jul 05 '13 at 19:33
  • i already programmed the code to turn ON one of the external LED . (FPGA cannot display the number as I am usíng XC3s1400A (DLPHSFPGA3) . ) So the best possibility is to turn on/OFF the external LED'S – Nabeel Jul 05 '13 at 19:53
  • According to your comment " One example of a next step would be for the FPGA to receive a number via serial port, increment it by one, and then send the result back to Matlab. " . How to send data to Matlab from FPGA ? – Nabeel Jul 08 '13 at 13:33
  • On the FPGA side, you'll need to send the data. This is hardware dependent- you'll need to read the datasheet and follow any example code provided by the vendor. http://www.ftdichip.com/Products/ICs/FT2232H.htm The typical method is that you'll write to some predefined registers in the FPGA (which have been physically wired to the USB chip), and then toggle another wire to trigger the 'send'. On the Matlab side, you'll need to continuously poll the receive buffer to see if anything has arrived. Check out this blog under the Matlab section for help. http://cnx.org/content/m12062/latest/ – supyo Jul 08 '13 at 14:44
  • I programmed the FTDI chip, and is able to see the output on external connected LED's (that is Turned ON) . Should the next step to be check the status of that particular output from Matlab ?? I used this command " y = GetSerialData('port', baud, size); " in matlab but NULL has received.. – Nabeel Jul 11 '13 at 07:11