Working with the Digilent I/O Explorer USB

This guide will be used as a reference for several lab experiences. Although the Explorer USB has many capabilities and can be used as a microprocessor, we will focus on three operations:

1. Analog input 2. Analog output 3. Encoder input

We will use a simple software-based timing technique that will limit the sample rate that can be used in a reliable way. Faster rates are possible with the Explorer USB, but they require programming techniques beyond the scope of MCE484.

The Explorer will be connected to the PC using a USB cable. We will write/modify programs to realize the 3 I/O operations. Programs will execute on the PC processor, not the Explorer. To do this, we will be using an open-source ++ compiler called CodeLite, which is equivalent to , a paid program. Only a knowledge of programming techniques is required. The instructor will provide information on new concepts and C++ syntax as needed.

0. Basic connection and program compilation:

Familiarize yourself with the Explorer board:

a. Make sure you are not charged with static electricity before touching the board. You may discharge by touching a bare pipe or wearing an anti-static strap. b. Locate the mini USB connector, the ON/OFF power switch, the JE connector (upper- right relative to the logo) and the J1 connector (to the right of the logo). Also find the JP7 jumper and shift it to the 5V0 position (default is 3V3). This sets certain voltage levels to 5.0V instead of 3.3V. c. The JE connector has 12 pins. Pin 1 is labeled on the board (top row). Pins 2-6 follow pin 1 on the top row. Pin 7 is directly below pin 1, and pins 8-12 follow pin 7 on the bottom row. This type of connector is called a Pmod connector.

Plug in the USB cable and wait until the PC recognizes the device. Then go to Start/All Programs/Digilent/Adept and run Adept. It should indicate that ioexp has been detected. If not, check the power switch and wait a few seconds. In Adept, click on Device Manager and click on USB and Enumerate. The ioexp device should show up on the right and the serial number in the middle. Give it an alias name, save and close Adept. This is a one-time operation. The next time you plug in the board, it will be recognized automatically, but you can use Adept to check.

Load and compile a Demo program to check that you have a working installation:

a. Open CodeLite. Start a new project. On the left, choose Console/Simple Executable (g++). Name it (let’s use demo1). For the project path, go to the C drive, and find the digilent_adept_sdk_v2.1.1 directory. Go in and find samples /dgio/ DgioDemo and copy-paste the entire path to the project path in CodeLite. b. Upon doing this, you will see a project tree on the left. Underneath src, there will be a default c++ source file called main.cpp. Right-click to remove it. Accept removing it from disk. Then right-click again and choose Add existing file. From the samples/DgioDemo directory, pick DgioDemo.cpp. When it appears under src, double-click on it. The program listing should appear on the editor on the right. c. Some settings are needed before compilation. Go to Settings/Build Settings/Advanced. For the Include path, enter: C:\digilent.adept.sdk_v2.1.1\include For the Libraries path, enter: C:\digilent.adept.sdk_v2.1.1\lib

These settings will be saved, you need to enter them only once. Now go to Workspace/Open Active Project Settings (or Alt F7) and go to Compiler. Enter the same Include path as before. The go to Linker and enter the same Library path as before. Finally, under Libraries (last box) enter :

dmgr;dgio

Note: dmgr will be needed always. The second library will vary according to the functions being used. In this demo, we are using the general i/o functions, so the dgio library is needed. You will be advised as to which libraries to use for each project.

This step must be done for each new project.

. Compile the code. Click anywhere on the editor window and press F7 . It should compile with no errors, maybe some warnings. Open a Windows file explorer and go to your project directory …/samples/..demo1.. and go in the Debug directory. There should be an executable file called demo1.exe. e. You can run the program in two ways. From CodeLite, you can press Ctrl F5. The demo program takes a few seconds and turns some LEDs on. At the end of the program it wants the user to set the switches on the Explorer to 0x0A to exit the program. The prefix 0x indicates that the number is in hexadecimal notation (the number A). Convert this number to an 8-bit binary. Knowing that SW0 is the MSB and SW7 is the LSB, set the switches to this binary code. The program should exit. f. The other way to run programs is to use the Windows command line in DOS mode. To do this, go to Start/Run…and enter cmd. When the command window appears, change the directory to the Debug directory where demo1.exe is located. You can use a file explorer and copy-paste, but quotes must be used (“) if the path contains spaces: cd “C:\digilent.adept.sdk_v2.1.1\samples\dgio\DaioDemo\demo1\Debug” Once you are in that directory, type demo1 at the prompt and it should run.

1. Analog Input:

An analog input program is provided as a sample. We will use it as a starting point and modify it/ simplify it to suit our needs. The resulting barebones code will be the basic template for our motor control projects.

a. Close any open workspace and create a new project following the basic steps. b. You will need to use the dmgr and daio libraries. c. In the Windows file explorer, go to the DaioDemo.cpp file and save it under a new name. Add this new cpp file as the source cpp code in your project. d. Follow instructor directions to modify the program e. Note that you will read the analog voltage using the J1 connector pins. You can test for proper operation by touching the positive pin with a small voltage from a protoboard via a jumper cable and grounding the other pin. You can also short the pins with the blue jumper (0V should be read).