ECE 3551-Microcomputer System 1 Fall 2008 LAB Exercise # 1: Building and Running a C Program & Plotting DATA Using: Visual DSP++ 5.0 Purpose: The purpose of this lab is to introduce the student to hands on experience with the tools by building and running pre-written sample programs. The student will then use some simple debugging techniques to compare execution time using different build options. Experimentation is encouraged and the user should feel free to explore through the menu items. This lab is based upon a tutorial in the “Programming ADSP-BF533 EZ-Kit Lite with VisualDSP++” manual. It is suggested to go through all the getting started labs when time permits for a more complete demonstration and understanding. Outline: This lab is broken into 3 main parts Part A involves: Connecting power and USB to the board Opening projects and setting up sessions and other desired settings Building and running pre-written programs, and examining windows and dialog boxes Exploring Debug vs. Release compiler versions How to create your own project Part B, included for demonstration purposes, involves: Opening, building, and running a project The use of programmable flags to generate interrupts and control LEDs Part C involves: Loading and debugging a prebuilt program that applies a simple Finite Impulse Response (FIR) filter to a buffer of data Using VisualDSP++’s plotting engine to view the different data arrays graphically, both before and after running the program. Getting Started: For this lab you will need to make a LAB_1 folder in your U-Drive: U:\username\ece3551\LAB_1 Copy the following folders into your LAB_1 folder. You will be required to use these at different stages of the lab: C:\ Program Files\Analog Devices\VisualDSP5.0\Blackfin\Examples\ Tutorial\dot_product_c C:\ Program Files\Analog Devices\VisualDSP 5.0\Blackfin\ Examples\ADSP-BF533 EZ-Kit Lite\LED Blink (C) C:\ Program Files\Analog Devices\VisualDSP 5.0\Blackfin\Examples\ Tutorial\fir PART A (Dot Product) The sources for this exercise are in the dot_product_c folder Step 1: Start VisualDSP++ (version 5.0) & open an existing project. Connect the USB cable from the PC to the ADSP-BF533 EZ-KIT Lite. Plug in the AC/DC power adapter and power the board. Click the Windows Start button and select: Programs Analog Devices VisualDSP++ 4.5 VisualDSP++ Environment. If you are running VisualDSP++ for the first time, you will not be connected to a debug target. In VisualDSP++ 5.0, it is possible to edit and build your code without being connection to a debug target through a debug session. When you are ready to run and debug your program, you can quickly connect to a target and disconnect when you are finished. Doing so eliminates the overhead associated with the target connection, resulting in a smoother and more responsive experience. When you need to connect to a debug session, click the Connect to Target toolbar button or choose from the available sessions listed under Select Session in the Session menu. To create a debug session, select New Session from the Session menu. This will launch the Session Wizard, which is covered in more detail later. If you have already run VisualDSP++ and the Reload last project at startup option is selected on the Project page under Settings and Preferences, VisualDSP++ opens the last project that you worked on. To close this project, choose Close and then Project from the File menu, and then click No when prompted to save the project. From the File menu, choose Open and then Project. VisualDSP++ displays the Open Project dialog box In the Look in box, open the U: folder and double-click the following subfolders in succession. U:\ece3551\labs\LAB_1\dot_product_c Double-click the dotprodc project (.dpj) file. VisualDSP++ loads the project in the Project window, as shown in the figure below. The environment displays messages in the Output window as it processes the project settings and file dependencies. The dotprodc project comprises two C language source files, dotprod.c and dotprod_main.c, which define the arrays and calculate their dot products. From the Settings menu, choose Preferences to open the Preferences dialog box, shown in figure below. Ensure the “Load executable after build” option from the General Preferences Box is checked. From the Session menu, choose New Session. The Session Wizard will appear. a) Create the first session by selecting the following: Processor Family: Blackfin Target Processor: ADSP- BF533 Connection Type: Simulator Session Name: (keep the default name) Platform: ADSP_BF5xx Single Processor Simulator b) Return to the Session menu and create a New Session with the following: Processor Family: Blackfin Target Processor: ADSP- BF533 Connection Type: EZ-KIT Lite Session Name: (keep the default name) Platform: ADSP_BF533 EZ-KIT Lite via Debug Agent Step 2: Build the Project 1) From the Project menu, select Build Project The output window should display “Build Completed Successfully” message if the build has no errors: If the tool detects invalid syntax or a missing reference, the tool reports the error in the Output window. If you double-click the file name in the error message, VisualDSP++ opens the source file in an editor window. You can then edit the source to correct the error, rebuild, and launch the debug session. If the project build is up-to-date (the files, dependencies, and options have not changed since the last project build), no build is performed unless you run the Rebuild All command. Instead, you see the message “Project is up to date”. 2) Look at the information in the open windows. The Output window’s Console page contains messages about the status of the debug session. In this case, VisualDSP++ reports that the dotprodc.dxe load is complete. The Disassembly window displays the assembly code for the executable. Use the scroll bars to move around the Disassembly window. Note that a solid red circle and a yellow arrow appear at the start of the program labeled “main”. The solid red circle (●) indicates that a breakpoint is set on that instruction, and the yellow arrow (➨) indicates that the processor is currently halted at that instruction. When VisualDSP++ loads your C program, it automatically sets several breakpoints. Most of the breakpoints set are used as part of advanced features of VisualDSP++. There are two breakpoints of interest for this tutorial, one at the beginning and one at the end of code execution. Step 3: Run the Program To run dotprodc, click the Run button or choose Run from the Debug menu. VisualDSP++ computes the dot products and displays the following results on the Console view of the Output window. Dot product [0] = 13273595 Dot product [1] = –49956078 Dot product [2] = 35872518 To stop a program from running, select Halt from the Debug menu, or hit Shift + F5 Step 4: Build and Run the Program using the Release Compiling Version Each Project usually has two compiling versions: Debug Version: The compiler does not optimize the code, runs slowly, and can run step by step. This version is usually used for developing debugging. Release Version: The compiler optimizes the code, runs fast, and cannot run step-by-step. This version is usually released to the customer. Select the Release compiler configuration from the drop box. See figure below: Hit the F7 key, or select Build Project from the Project menu. This will build the project using the release version. The output window should look like the figure below: Select Run from the Debug menu, and the dot product results will appear in the Output Window Step 5: Build and Run the Program using another Session When using the Simulator Session, Visual DSP++ does not communicate with the hardware. The results are simulated on the PC. From the Session menu, choose Select Session and check the session that is not already checked (i.e. you should check Single Process Simulator) Select the Debug compiling version from the drop down box. Hit the F7 key, or select Build Project from the Project menu Hit the F5 key, or select Run from the Debug menu Step 6: Create your own project Ensure the program for the open project is not running. (Select Debug Halt, if necessary) To close the project select : File Close Project dotprodc.dpj Select Yes when asked to close all open windows. Select the Single Processor Simulator from the Session Select Session menu Create a new project by selecting File New Project. The Project Wizard should appear. Enter “mylab1” in the Name field In the Directory field, ensure that it is mapped to the LAB_1 folder in your U-Drive. Click Next, and complete the Wizard selections, as shown in the figures below: Create a new file by selecting: File New File. A new edit window will appear. Input the following code into the edit window: #include <stdio.h> int main(void) { printf("Welcome to analog DSP simulator!"); return 0; } Save your new file: File Save , and save the file as “main.c” Add your new file to the project: Project Add to Project File(s), add the “main.c” file to the project. Build and run your new project: Hit F7 or select Project Build Hit F5 or select Debug Run. The result should be displayed in the output window: Close the Project: Select File Close Project mylab1.dpj PART B (Interrupts and LEDs) At this stage of the lab assignment, you will use a prewritten program to explore some interactions with the board. Open the LED Project from your U-Drive: Select: File Open Project, and select the folder U:\username\ece3551\LAB_1\ LED Blink (C) Double click on BF533 Flags C. The project should open in the Project window Select a Session: Select: Session Select Session ADSP-BF533 EZ-KIT Lite via Debug Agent . ( If this option is not listed, then Create a new session) Build and Run the Project: Hit F7 to build the project Hit F5 to run the project. You should notice the LEDs moving from left to right. Push the button marked PF8 (on the board) to change the direction of the LEDs This program uses the programmable flag PF8 to generate an interrupt. The interrupt is processed by an interrupt service routine, which directs a changes the direction of the blinking LEDs. Some of the other components working in the background are the flash to access the LEDs and one of the timers to regulate the speed of the blinking LEDs. More details about this will be provided in the lecture. Stop the program: Debug Halt PART C Step 1: Load the FIR Program From the File menu of Visual DSP++, choose Load Program. The Open a Processor Program dialog box appears. Open the U:\username\ece3551\LAB_1\fir folder Double-click the Debug subfolder Double-click FIR.DXE to load the program A message may appear, inquiring whether you want to find fir_test_c. Select Yes, look for fir_test_c in the fir folder, and then double click. Look at the source code of the FIR program. You can see two global data arrays: • IN • OUT You can also see one function, fir; that operates on these arrays. You are now ready to open a plot window. Step 2: Open a Plot Window 1. From the View menu, choose Debug Windows and Plot. Then choose New to open the Plot Configuration dialog box 2. In the Plot group box, specify the following values. • In the Type box, select Line Plot from the drop-down list. • In the Title box, type fir. 3. Enter two data sets to plot by using the values below: After entering each data set, click Add to add the data set to the Data sets list on the left of the dialog box. The Plot Configuration dialog box should now look like: 4. Click OK to apply the changes and to open a plot window with these data sets. Plot Window: Before Running the FIR Program 5. Right-click in the plot window and choose Modify Settings. On the General page, in the Options box, select Legend and click OK to display the legend box. Step 3: Run the FIR Program and View the Data To run the FIR program and view the data: 1. Press F5 or click the Run button to run to the end of the program. Plot Window: After Running the FIR Program to Completion 2. Click the left mouse button inside the plot window and drag the mouse to create a rectangle around the area of interest. Then release the mouse button to magnify the selected region. Plot Window: Magnifying Area of Interest 3. Right-click in the plot window and choose Data Cursor from the pop-up menu. Next you will look at data sets in the frequency domain. 4 Right-click in the plot window and choose Modify Settings to open the Plot Settings dialog box. Click the Data Processing tab to display the Data Processing page In the Data Sets box, ensure that Input (the default) is selected. In the Data Process box, choose FFT Magnitude.In the Sample rate (Hz) box, type 10000. In the Data Sets box, select Output. In the Data Process box, choose FFT Magnitude Click OK to exit the Plot Settings dialog box. Now, complete the following steps to look at the FIR filter’s response in the frequency domain. 1. From the View menu, choose Debug Windows and Plot. Then choose New to open the Plot Configuration dialog box. 2. Set up the Filter Frequency Response plot by completing the Plot and Data Setting group boxes as shown in Figure below. 3. Click Add to add the data set to the Data sets box. 4. Click OK to apply the changes and to open the plot window with this data set. 5. Right-click in the plot window and choose Modify Settings to open the Plot Settings dialog box. 6. Click the Data Processing tab to display the Data Processing page, Complete this page as follows. a. In the Data Sets box, select h. b. In the Data Process box, choose FFT Magnitude. c. In the Sample rate (Hz) box, type 10000. d. Click OK to exit the Data Processing page. This plot shows that the low-pass FIR filter cuts off all frequency components above 4,000 Hz. When you apply a low-pass filter to the input signal, the resulting signal has no output above 4,000 Hz. You have finished this lab tutorial.