send data from MATLAB to FPGA

Discussion in 'Embedded Systems and Microcontrollers' started by omerysmi, Sep 8, 2015.

  1. omerysmi

    Thread Starter Member

    Oct 10, 2014
    44
    0
    What is the best way to send data from Matlab to fpga? (Altera DE1)
    I need it to control servo motors.
     
  2. Shagas

    Active Member

    May 13, 2013
    802
    74
    Why do you want to send data from Matlab to fpga?
    In any case your best best is probably UART. Get a 3dollar usb->UART converter like this one and implement a UART module on the FPGA (or download one, there are loads of free available implementations) so that the FPGA can talk to the converter.
    In Matlab: You open a serial object and you write to it in individual bytes.

    Code (C):
    1.  
    2. % Serial object
    3. s = serial('COM12','BaudRate',9600,'DataBits',8);
    4.  
    5. % Close any open objects so they don't interfere
    6. newobjs = instrfind;
    7. fclose(newobjs);
    8.  
    9. % Open our serial object
    10. fopen(s);
    11.  
    12.  
    You can write:

    get(s)

    To display all the parameters of the s object that you might want to configure and you do that by writing:

    set(s, '<parametername>', <parametervalue> );

    I have experience with reading from the port using 'fread()' but don't haven't tried writing to it. Shouldn't be too hard.
    I don't know if you will need a special toolbox for the serial stuff to work on Matlab. If you run into toolbox issues then try Octave, maybe they have a serial implementation aswell.
     
  3. omerysmi

    Thread Starter Member

    Oct 10, 2014
    44
    0
    i need to detect some object from camera with MATLAB and then to operate servo motors..so that's why i need to send data from matlab to fpga. Do you think that there is another way to do it?
     
  4. Shagas

    Active Member

    May 13, 2013
    802
    74
    I don't think so. Alternatively you can use some other program to communicate with the FPGA and read/write data to a file which you will
    use to write/read with matlab but you will still have to use RS232 because DE1 doesn't even have an ethernet PHY.
     
  5. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    Hello,
    I have used uart to usb module but no idea how matlab communicate...
     
Loading...