The NiFpga toolbox provides a Matlab interface to National Instruments FPGA (NI FPGA). The Matlab interface is based on the recently released NI-FPGA C-API and can be used with any NI FPGA hardware running NI-RIO.
Using the toolbox, NI FPGA applications can directly be controlled from Matlab instead of LabView. The toolbox provides the full functionality of the LabView FPGA Interface Panel, including indicator and control read/write commands, interrupt handling and DMA FIFO operations.
You can install the NiFpga Toolbox as follows:
>> mex -setup >> NiFpga_installNiFpga.mexw32 in the installation directory (the extension may differ according to your operating system and hardware architecture, refer to the Matlab function mexext for details).
Assume you have implemented an FPGA VI (Virtual Instrument) called simpleFPGA.vi, shown above. This VI uses an analogue input (AI) module for signal acquisition and an analogue output (AO) for signal output. The input module is placed in Mod6 and the output module is placed in Mod8 of the used NI hardware. Both input and output modules are configured to work with raw I16 type data. The VI reads a sample from the 0-th channel of the input module, multiplies its value by an integer stored in the control Mul, and writes the result to the 0-th channel of the output module. The read and write operations are repeated in a while loop timed by the control Count(Ticks), until the boolean control stop is set to true.
Count(Ticks) = 1000, Mul = 2 and stop = false. Following this step, the FPGA execution is started, and after the user sets the stop control to true, the FPGA variable stop is set to true, and the FPGA program is closed.
simpleFPGA.vi needs to be generated by the C API. This is performed by right clicking the vi in the project explorer and calling the C API Generator, as shown below:
NiFpga_simpleFPGA.lvbitx (NI FPGA bitfile)NiFpga_simpleFPGA.h (C language header file)FPGA Bitfiles in your LabView project directory.
C:/FirstApp/), open Matlab and enter the destination directory.NiFpga toolbox using the toolbox function
>> NiFpga2Matlab('simpleFPGA', 'MyClass');
This command generates two Matlab classes based on the C language header file NiFpga_simpleFPGA.h. These classes are CMyClass and CsimpleFPGA, the source codes of which can be found in CMyClass.m and CsimpleFPGA.m in the destination directory.
simpleHOST.m can be implemented as below:
MyClass = CMyClass('rio://152.66.249.36/RIO0');
C = MyClass.simpleFPGA;
C.open('norun');
C.CountTicks = 1000;
C.stop = false;
C.Mul = 2;
C.run('nowait');
pause;
C.stop = true;
C.close;