Main Content

Program Standalone Altera FPGA Development Board from MATLAB

This example shows how to program a standalone FPGA with your MATLAB® design, using the FPGA Turnkey workflow.

The target device in this example is an Altera® DE2-115 development and education board.

Before You Begin

To use the FPGA Turnkey workflow, you must:

  • Have your synthesis tool path set up. To learn how to setup your synthesis tool path, see Synthesis Tool Path Setup.

  • Connect the target device if you want to program it immediately. If the target device is not connected, you can still generate the programming file.

Create a Project

  1. Create a new folder to hold your project files.

  2. At the MATLAB command line, open the design and test bench files:

    edit mlhdlc_turnkey_led_blinking.m
    edit mlhdlc_turnkey_led_blinking_tb.m

  3. Save copies of the design and test bench files to your new project folder.

  4. Change directory to your new project folder.

  5. At the MATLAB command line, enter:

    The project creation pane opens.

  6. For Name, enter myproject.prj and click OK.

  7. Under MATLAB Function, click Add MATLAB Function and select mlhdlc_turnkey_led_blinking.m.

  8. Under MATLAB Test Bench, click Add files and select mlhdlc_turnkey_led_blinking_tb.m.

  9. Click the Workflow Advisor button to open the HDL Workflow Advisor.

Convert Design To Fixed-Point

  1. Right-click the Define Input Types task and select Run This Task.

  2. In the Variables tab, for the freqCounter variable, in the Proposed Type column, enter numerictype(0, 27, 0) to set the type to unsigned 27-bit integer.

  3. On the left, right-click the Fixed-Point Conversion task and select Run This Task.

Map Design Ports to Target Interface

In the Select Code Generation Target task, select the FPGA Turnkey workflow and Altera DE2-115 development and education board as follows:

  1. For Workflow, select FPGA Turnkey.

  2. For Platform, select Altera DE2-115 development and education board. If your target device is not in the list, select Get more to download the support package.

    The coder automatically sets Chip family, Device, Package, and Speed according to your platform selection.

  3. For FPGA clock frequency, for both Input and System, enter 100.

  4. In the Set Target Interface task, map the design input and output ports to interfaces on the target device by setting the fields in the Target Platform Interfaces column as follows:

    • Blink_frequency_1 to User-defined Push-button Switch [0:3]

    • Blink_direction to Slide Switch [0:17]

    • LED to LED Green [0:8]

    You can leave the Read_back port unmapped.

The HDL Workflow Advisor applies your settings immediately.

Generate Programming File and Download To Hardware

You can generate code, perform synthesis and analysis, and download the design to the target hardware using the default settings:

  1. For the Synthesis and Analysis task group, uncheck the Skip this Step option.

  2. For the Download to Target task group, uncheck the Skip this Step option.

  3. Right-click Download to Target > Generate Programming File and select Run to Selected Task.

  4. If your target hardware is connected and ready to program, select the Program Target Device subtask and click Run.