Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Command FPGA using Matlab

Hi,

I would like to know how to command my FPGA board with Matlab.

I explain :

I would like for exemple switch on a LED with Matlab and RS232 connexion.

I don't know how to make it...

If I have to use UART with TX and RX or if they are some function in Matlab.

My FPGA is ep2c35f672c6n and I use matlab r2007b.

Thanks for your help :)

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Do you have a QII subscription edition respective a license with allows you to use the SOPC/QSYS feature?

    Do you have any HDL background?

    In any case you've to implement logic into the FPGA that understands serial data received from the UART and

    translates that into a high respective low on the aproppriate FPGA pin that is connected to you LED.

    My MATLAB knowledge is very poor.

    Is MATLAB able to transmit data (i.e. characters) over a console/UART?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes I can use SOPC an QSYS features with QII

    Yes I have knowledges in VHDL, but not in verylog

    But I don't know how to use SOPC. I have to place all component (UART and serail device)?

    And yes with Matlab we can transmit data but i don't know how to do it but I'll find :)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Yes I can use SOPC an QSYS features with QII

    --- Quote End ---

    That's good.

    --- Quote Start ---

    Yes I have knowledges in VHDL, but not in verylog

    --- Quote End ---

    That's good either.

    --- Quote Start ---

    But I don't know how to use SOPC. I have to place all component (UART and serail device)?

    --- Quote End ---

    If you wish to extend your commanding by MATLAB in the future, is suggest that you implement

    a NIOSIIe (the simplest) and a UART-Peripheral.

    I recommend QSYS, because it (has already) superseded SOPC.

    I'm not sure if ALTERA is provide a GPIO-Peripheral. This could be used to drive the LED-Pin.

    You'll have to to create a QSYS-system with

    NIOSIIe: Instruction Avalon Master -> On-Chip RAM that holds you code

    NIOSIIe: Data Avalon Master -> GPIO-Peripheral Avalon Slave

    NIOSIIe: Data Avalon Master -> UART-Peripheral Avalon Slave

    After you've successfull described you system and build it, you'll have to instantiate it in a top-level (V)HDL Wrapper (or BSF) in QII.

    After that worked you'll have to write your NIOSII-SW based on the Board-Support-Package QSYS created for you.

    I guess that will be no simple task.

    Do you need to control the board directly via MATLAB or is a command window sufficient? That would generate significant less

    work in the FPGA, because you could exclude the NIOS and the SW part.

    In that case you'll have to to create a QSYS-system with

    JTAG-UART-Peripheral Avalon Master -> GPIO-Peripheral Avalon Slave

    After you've successfull described you system and build it, you'll have to instantiate it in a top-level (V)HDL Wrapper (or BSF) in QII.

    You could split your task in two phases:

    1. Implemented the JTAG-UART based solution (gaining QSYS basic knowledge and establish a commanding interface to the PC)

    2. Implement the NIOSIIe based solution (developing the sophisticated solution based on the knowledge gained in 1.)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks,

    I have implemented niosII on my fpga with the uart and serial device.

    I have made a C program in order to send Hello World on serial port and it's successful.

    #define RS232_UART_DATA ((volatile int*) 0x10001010)
    # define RS232_UART_CONTROL ((volatile int*) (0x10001010+4))
    int main()
    {
        unsigned char hwld = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
        unsigned char *pOutput;
        pOutput = hwld;
        while(*pOutput) //strings in C are zero terminated
        {
             //if room in output buffer
             if((*RS232_UART_CONTROL)&0xffff0000  ) 
             {
                //then write the next character
                *RS232_UART_DATA = (*pOutput++); 
             }
         }
    }

    With this code my FPGA send "hello world" to my computer.

    But now I would like to send information on my FPGA with serial port in order to control my FPGA.

    I explain:

    If I send '1' from my computer to the FPGA I would like that the LEDG(1) turn on.

    If I send '2' the LEDG(2) turn on...

    I don't know how to make it... I know that I have to take the information on RX but I don't know how to do it