libm2k Library Setup in MATLAB 2024b
Objectives:
This document will walk through how to set up the libm2k Library in MATLAB and use the library to interface with the ADALM-2000 (M2K) with Windows.
Preparation:
Before you start, please make sure that:
- The MATLAB version is 2024b or higher.
- The M2K driver is installed on your computer (If so needed, install the driver for Windows here).
Install libm2k Toolbox:
Step 1: Go to https://drive.google.com/file/d/1VVwdFxmQhbZ2zXMJxsF26NKqgWsEUKyc/view?usp=sharing and download the toolbox.
Step 2: Drag the “AnalogDeviceslibm2kBindings_vxx.x.x.mltbx” file to your MATLAB working directory (Figure 2).
| Figure 2: Drag the toolbox file to the MATLAB working directory |
Step 3: Double-click on the .mltbx file in MATLAB to install the toolbox. You will see an “installation complete” message after the installation (Figure 3). If you are using a MATLAB version newer than 2024b, and the window indicates that the toolbox is not for your MATLAB version, you can still proceed with installing the toolbox.
| Figure 3: “Installation Complete” window displayed after toolbox installation |
Set libm2k Path:
Step 1: Find the local path of the libm2k library by opening the “Add-Ons Manager” and selecting the options boxed in Figure 4 and Figure 5.
| Figure 4: Steps to open the Add-On Manager |
| Figure 5: Steps to open the libm2k folder |
Step 2: Double-click on the libm2k folder in the working directory (Figure 6), then copy the file path (Figure 7).
| Figure 6: libm2k folder |
| Figure 7: Path to the libm2k DLL files |
Step 3: Open the “Set Path” window in the MATLAB Home page (Figure 8). Select “Add with Subfolders”, navigate to the path you copied from Step 2 (Figure 7), then click “Select folder”.
Step 4: The libm2k DLL file paths should now be added to the search path list. Click “Save” and then close the Set Path window (Figure 8).
| Figure 8: Set Path window |
Test the Toolbox:
Step 1: Connect ADMAL-2000 to your computer. MAKE SURE SCOPY IS CLOSED.
Step 2: Disconnect any circuit or the M2K adapter board from your ADMAL-2000.
Step 3: Navigate to your Windows desktop and create a blank folder.
Step 4: Download ReadPowerSupply.m and store it in the blank folder you created in Step 3.
Step 5: In MATLAB, navigate to the folder where you stored your ReadPowerSupply.m file.
Step 6: Run the ReadPowerSupply.m file in MATLAB.
You do not need to understand the code in ReadPowerSupply.m, it is simply a program for troubleshooting the programming environment.
You only need to run “ReadPowerSupply.m” once during Lab 6 to verify the setup, after which your computer should be ready for all MATLAB M2K programming assignments in future labs and in the final project.
Step 7: If you get a voltage reading (doesn’t have to be 1.6914 V) and a graph (doesn’t have to look exactly like Figure 9) after running ReadPowerSupply.m with no error, you may proceed to the Lab 6 instruction, Section 4.2 Procedure.
| Figure 9: “ReadPowerSupply.m” program output |
Step 8: If you get an error:
- Make sure you are using a Windows machine.
- Make sure Scopy is closed on your computer, then run ReadPowerSupply.m again.
- Make sure the M2K driver is installed on your computer (If so needed, install the driver for Windows here), then run ReadPowerSupply.m again.
- Disconnect and reconnect M2K to your computer, then run ReadPowerSupply.m again.
- If you see an error message similar to Figure 10, make sure you have installed the libm2k toolbox, then run ReadPowerSupply.m again.
- If you see an error message similar to Figure 11, make sure the MATLAB version is 2024b or higher, then run ReadPowerSupply.m again.
| Figure 10: Error message related to the toolbox |
| Figure 11: Error message related to MATLAB version |
Resouces:
- “Using ADALM-2000 With MATLAB” from Analog Devices: Using ADALM-2000 With MATLAB [Analog Devices Wiki]
- libm2k API documentation: libm2k: Main Page
- m2k toolbox download link: libm2k-matlab - File Exchange - MATLAB Central