Microcomputer Systems 1 Introduction to Visual DSP++ Tools Goals Introduction to Visual DSP++ and Tools Specific to Blackfin Information on how to analyze applications and fine tune them. 14 March 2016 Veton Këpuska 2 Outline The VisualDSP++ Tools Creating a Project Plotting Performance improvement using chip features Cache L1 Memory Voltage Regulator 14 March 2016 Veton Këpuska 3 Blackfin CROSSCORE Product Line VisualDSP++ development suite Performance-tuned C/C++ compiler Source language debugger RTOS kernel (VDK) Device drivers and system services Ethernet and USB 2.0 libraries Tuned DSP libraries Visual linker Code wizards Flash programmer Multicore code generation and debugging Plotting and other advanced code generation and debugging tools Automation API 14 March 2016 EZ-KIT Lite and Daughter cards JTAG Emulators ADSP-BF533 ADSP-BF535 ADSP-BF537 ADSP-BF561 USB 2.0 USB 1.1 PCI Background Telemetry A-V EZ-Extender Audio EZ-Extender USB-LAN EZ-Extender FPGA EZ-Extender Veton Këpuska 4 Additional Information ADSP-BF533 EZ-KIT Lite Manual Tools manuals provided in the On-line help Analog Devices web site: www.analog.com Email Support: For tools questions: Processor.tools.support@analog.com For processor questions: Processor.support@analog.com Licensing and Registration questions: Processor.tools.registration@analog.com Or click the “Ask A Question” button 14 March 2016 Veton Këpuska 5 DSP Project Development Stages Simulation Evaluation Emulation 14 March 2016 Veton Këpuska 6 Simulation Development Cycle begins in simulation environment VisualDSP++ with simulation target enables: Building Debugging 14 March 2016 Veton Këpuska 7 Evaluation EZ-KIT Lite evaluation system in the lab can be used to: Determine Processor Capabilities that best fit target application EZ-KIT Lite Board connected to the PC Development System via USB Port or JTAG interface This connection can be used for Evaluation as well as Emulation purposes (see next slide). Code download via USB Port is significantly slower than JTAG interface used for emulation. 14 March 2016 Veton Këpuska 8 Emulation Actual hardware (can be EZ-KIT Lite board) is connected via JTAG (Joint Test Action Group) emulator We have only 1 JTAG obtained from our entry to UML-ADI competition Emulator enables application software to be downloaded and debugged from within VisualDSP++ Emulation Software performs the communications that enables measurement of DSP performance and how current implementation affects it. 14 March 2016 Veton Këpuska 9 Development Tools VisualDSP++ version 4.5 (from Analog Devices) – version 5.0 will be installed soon. Vendors other than Analog Dev.: MULTI from Green Hills Software Open Source GCC tool chain and Clinux 14 March 2016 Veton Këpuska 10 VisualDSP++ Project Development and Debugging is integrated (IDDE). C/C++ Native Compiler Graphical Plotting Tools Statistical Profiling Cache Visualization Pipeline Viewer VisualDSP++ Kernel (VDK) 14 March 2016 Veton Këpuska 11 ADSP-BF533 EZ-KIT Lite Evaluation System Board 14 March 2016 Veton Këpuska 12 Evaluation Board EZ-KIT LITE Analog Devices ADSP-BF533 processor Performance up to 600 MHz 160-pin mini-BGA package 27 MHz CLKIN oscillator The Ball Grid Array (BGA) is descended from the pin grid array (PGA), which is a package with one face covered (or partly covered) with pins in a grid pattern. 14 March 2016 Veton Këpuska 13 Evaluation Board EZ-KIT LITE Synchronous dynamic random access memory (SDRAM) MT48LC32M16 - 64 MB (32M x 16 bits) Flash memories 2 MB (512K x 16 x 2chips) Analog audio interface AD1836 – Analog Devices 96 kHz 24-bit audio codec 4 input RCA phono jacks (2 channels) 6 output RCA phono jacks (3 channels) 2 MB (512K x 16 bits x 2chips) FLASH memory 14 March 2016 Veton Këpuska 14 Evaluation Board EZ-KIT LITE Analog video interface Universal asynchronous receiver/transmitter (UART) ADV7183 video decoder w/ 3 input RCA phono jacks ADV7171 video encoder w/ 3 output RCA phono jacks ADM3202 RS-232 line driver/receiver DB9 male connector LEDs 10 LEDs: 1 power (green), 1 board reset (red), 1 USB (red), 6 general purpose (amber), and 1 USB monitor (amber) Push buttons 5 push buttons with debounce logic: 1 reset, 4 programmable flags 14 March 2016 Veton Këpuska 15 Interfaces Expansion interface PPI, SPI, EBIU, Timers2-0, UART, programmable flags, SPORT0, SPORT1 Other features JTAG ICE 14-pin header USB-based debugger interface SPORT0 connector Evaluation suite of VisualDSP++ 14 March 2016 Veton Këpuska 16 Evaluation Board (cont.) 10 LED’s: Power Board Reset USB Reset USB Monitor 6 general-purpose (programmable) 1 reset 4 programmable Parallel Peripheral Interface (PPI) Synchronous Serial Port Interface (SPI) External Bus Interface Unit (EBIU) Timers 0-2 Universal Asynchronous Receiver-Transmitter (UART) Programmable Flags, High Speed Serial Ports (SPORT0 & 1) 5 Push buttons 3 90-pin connectors providing: 14 March 2016 Veton Këpuska 17 Development Process on DSP VisualDSP++ Integrated Development & Debugging Environment Development Process Linker Description File (.ldf) Executable File (.dxe) Compiler & Assembler Linker Source Files Object Files (.c & .asm) (.doj) C Run-Time Header (basiccrt.s) 14 March 2016 Debugger (In-Circuit Emulator, Simulator, or EX-KIT Lite) Linker Description File (.ldf) Veton Këpuska 19 Bootable Image Executable File Boot Image Programmable Memory (.ldr) (.dxe) Loader/ Loader / Splitter Writer EPROM Boot Code (.dxe) 14 March 2016 Veton Këpuska 20 Integrated Development & Debugging Environment of VisualDSP++ 14 March 2016 Veton Këpuska 21 Code Development Tools C/C++ compiler Run-time library with over 100 math, DSP, and C run-time library routines Assembler Linker Splitter Loader Simulator Emulator (EZ-Kit Lite or custom hardware) 14 March 2016 Veton Këpuska 22 Connecting to Debugging Session Start -> All Programs -> … -> VisualDSP++ VisalDSP++ when launches for the first time it does not connect to any session (see next slide) Visual DSP++ can connect to a number of different debugging sessions: 14 March 2016 Veton Këpuska 23 Connecting to Debugging Session EZ-KIT Lite: Dedicated USB connection between the PC and EZ-KIT Lite. Simulator: Software model of the processor. No external hardware is required. Customized to the selected DSP processor: Pipelines Caches Several order of magnitude slower than actual hardware execution. Cycle-accurate simulation (detailed view of processor operations) Functional simulator (quick simulation at the expense of detail). 14 March 2016 Veton Këpuska 24 Connecting to Debugging Session Emulator: JTAG emulator ideal for connecting to hardware Maximal performance Maximal flexibility Emulator is required to connect to any non-EZ-KIT Lite hardware. 14 March 2016 Veton Këpuska 25 VisualDSP++ Startup Screen 14 March 2016 Veton Këpuska 26 Using VisualDSP++ VisualDSP++ includes basic Linker Description File (.ldf) for each processor type. For Blackfin Processors the default installation path is: Program Files\Analog Devices\VisualDSP 4.5\Blackfin\ldf The four Tutorial exercises will be covered in more detail in the LAB. 14 March 2016 Veton Këpuska 27 Exercise 1. Building and Running a C Program Goals of this Exercise: Learn to: Start up the VisualDSP++ environment Open and build an existing project Examine windows and dialog boxes Run the program 14 March 2016 Veton Këpuska 29 Additional Information The source files for this exercise are in the dot_product_c folder. Default installation path: Program Files\Analog Devices\VisualDSP 4.5\Blackfin\Examples\Tutorial\dot_prod uct_c 14 March 2016 Veton Këpuska 30 Step 1: Start VisualDSP++ and Open a Project 1. Click the Windows Start button and select: Programs, Analog Devices, VisualDSP++ 4.5, and VisualDSP++ Environment. 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. 14 March 2016 Veton Këpuska 31 Step 1: Start VisualDSP++ and Open a Project 2. From the File menu, choose Open and then Project. VisualDSP++ displays the Open Project dialog box. 3. Copy content of dotprodc folder: Program Files\Analog Devices\VisualDSP4.5\Blackfin\Examples\ Tutorial\dotprodc This path is based on the default installation. To: u:\ece3551\lab1\ 4. In the Look in box, open the folder u:\ece3551\lab1\ 14 March 2016 Veton Këpuska 32 Step 1: Start VisualDSP++ and Open a Project 5. Double-click the dotprodc project (.dpj) file. VisualDSP++ loads the project in the Project window, as shown 14 March 2016 Veton Këpuska 33 Step 1: Start VisualDSP++ and Open a Project 6. From the Settings menu, choose Preferences to open the Preferences dialog box, as shown 14 March 2016 Veton Këpuska 34 Step 1: Start VisualDSP++ and Open a Project 7. On the General page, under General Preferences, ensure that the following options are selected. Run to main after load Load executable after build 8. Click OK to close the Preferences dialog box. The VisualDSP++ main window appears. You are now ready to build the project. 14 March 2016 Veton Këpuska 35 dot_prod_c Project The dotprodc project comprises two C language source files: dotprod.c and dotprod_main.c, which define the arrays and calculates their dot products. 14 March 2016 Veton Këpuska 36 Step 2: Building the dotprodc Project 1. Running the Compiler Linker Description Executable File File (.ldf) (.dxe) Compiler & Assembler Linker Source Files Object Files (.c & .asm) (.doj) C Run-Time Header (basiccrt.s) 14 March 2016 Debugger (In-Circuit Emulator, Simulator, or EX-KIT Lite) Linker Description File (.ldf) Veton Këpuska 37 Step 2: Building the dotprodc Project 2. Linking Linker Description Executable File File (.ldf) (.dxe) Compiler & Assembler Linker Debugger (In-Circuit Emulator, Simulator, or EX-KIT Lite) Object Files Source Files (.c & .asm) 14 March 2016 (.doj) C Run-Time Header (basiccrt.s) Linker Description File (.ldf) Veton Këpuska 38 Step 2: Building the dotprodc Project 1. From the Project menu, choose Build Project. VisualDSP++ first checks and updates the project dependencies and then Builds the project by using the project source files. Output window displays status messages. 14 March 2016 Veton Këpuska 39 Step 2: Building the dotprodc Project 14 March 2016 Veton Këpuska 40 Step 2: Building the dotprodc Project Upon successful build (compile and link steps) example program can be run. 14 March 2016 Veton Këpuska 41 Step 3: Configuring the Session to Run the Program Before running the program: Set up the debug session. View debugger windows and dialog boxes. Note: In Preferences dialog box of the General page: Load executable after build is checked ⇒ automatic loading of dotprodc.dxe on to the target (EZLIT Lite). If not connected to a debug target, VisualDSP++ will prompt to connect to one using an existing debug session or creating a new debug session as shown in the next slide: 14 March 2016 Veton Këpuska 42 Step 3: Configuring the Session to Run the Program Clicking OK will launch the Session Wizard as shown in the next slide. 14 March 2016 Veton Këpuska 43 Step 3: Configuring the Session to Run the Program 14 March 2016 Veton Këpuska 44 Step 3: Configuring the Session to Run the Program Setting up debug session: 1. On the Select Processor page, select the ADSPBF533 processor from the Blackfin family. Click Next to continue. 2. On the Select Connection Type page, select Simulator, and click Next to continue. 3. On the Select Platform page, select ADSP-BF5xx Single Processor Simulator. You can either use the default Session name, or give it a more meaningful name of your choosing. Click Next to review your choices, then click Finish. VisualDSP++ closes the Session Wizard dialog box, automatically loads your project’s executable file (dotprodc.dxe), and advances to the main function of your code. 14 March 2016 Veton Këpuska 45 Step 3: Configuring the Session to Run the Program 14 March 2016 Veton Këpuska 46 Step 3: Configuring the Session to Run the Program 4. 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. 14 March 2016 Veton Këpuska 47 Step 3: Configuring the Session to Run the Program From the Settings menu, choose Breakpoints to view the breakpoints set in your program. VisualDSP++ displays the Breakpoints dialog box, as shown. The two breakpoints of interest are set at these C program locations: at main + 0x04 at __lib_prog_term 14 March 2016 Veton Këpuska 48 Step 4: Run dotprodc To run dotprodc.dxe: Click Run button: Select Run from Debug Menu. VisualDSP++ computes the dot products and displays the following results on the Console view of the Output window. 14 March 2016 Veton Këpuska 49 Exercise 2: Modifying a C Program Code to Call an Assembly Routine Goals of this Exercise Learn to: Modify the C program to call an assembly language routine Create a Linker Description File (.ldf) to link with the assembly routine Rebuild the project. 14 March 2016 Veton Këpuska 51 Additional Information Ensure that the previous project and its files are closed: From File menu, choose Close and then Project dotprodc. Click Yes when prompted to close all open source windows. Important Note: If you have modified your project during the first exercise you will be prompted to save the project. Click 14 March 2016 No. Veton Këpuska 52 Step 1: Creating a New Project 1. From the File menu, choose New and then Project to open the Project Wizard: 14 March 2016 Veton Këpuska 53 Step 1: Creating a New Project 2. In the Name field, type dot_product.asm 3. Click the browse button to the right of the Directory field to open the Browse For Folder dialog box. Locate the dot_product_asm tutorial folder and click OK. By default this directory is in the following location. Program Files\Analog Devices\VisualDSP 4.5\Blackfin\ Examples\Tutorial\dot_product_asm 4. Click Next to bring up the Output Type page. 5. Verify that the Processor type is ADSP-BF533, the Silicon Revision is Automatic, and the Project output file is Executable file. Click Next to display the Add Startup Code/LDF page. 14 March 2016 Veton Këpuska 54 Step 1: Creating a New Project 6. Read the displayed text, and scroll down to the bottom of the page. Select the Add an LDF and startup code option. When this project is created: Startup code that initializes and configures the processor will be added to the project, as well as a Linker Description File that defines the target memory map and the placement of program sections within processor memory. The options available to configure the startup code and LDF are beyond the scope of this tutorial. Make sure the Add an LDF and startup code option is selected, and click Finish. The new project is created and is shown in the Project window of the IDDE. 14 March 2016 Veton Këpuska 55 Step 1: Creating a New Project 7. From the Project menu click the Project Options command to display the Project Options dialog box 14 March 2016 Veton Këpuska 56 Step 1: Creating a New Project 8. On the Project page (see previous slide) verify that the values shown in the following table (or image of the previous slide) are entered. Field Value Processor ADSP-BF533 Revision Automatic Type Executable file Name dot_product_asm Settings for Configuration Debug 14 March 2016 Veton Këpuska 57 Step 1: Creating a New Project 9. Take a moment to view the various pages in the Project Options dialog box by selecting them from the tree on the left: Project, General, Compile, Assemble, Link, Load, Pre-Build, and Post-Build. On each page, you specify the tool options used to build the project. 14 March 2016 Veton Këpuska 58 Step 1: Creating a New Project 10. Click the Compile tab to display the General page, shown: 14 March 2016 Veton Këpuska 59 Step 1: Creating a New Project 11. Specify these settings in the Code Generation group box: a. Select the Enable optimization check box to enable optimization. b. Select the Generate debug information check box, if it is not already selected, to enable debug information for the C source. 12. Click OK to apply changes to the project options and to close the Project Options dialog box. Note: These settings direct the C compiler to optimize code for the ADSP-BF533 processor. Because the optimization takes advantage of DSP architecture and assembly language features, some of the C debug information is not saved. Therefore, debugging is performed through debug information at the assembly language level. 14 March 2016 Veton Këpuska 60 Step 2: Adding Source Files to dot_product_asm 1. To add the source file to the new project: Click the Add File button , or from the Project menu, choose Add to Project, and then choose File(s). The Add Files dialog box appears. 14 March 2016 Veton Këpuska 61 Step 2: Adding Source Files to dot_product_asm 14 March 2016 Veton Këpuska 62 Step 2: Adding Source Files to dot_product_asm 2. In the Look in box, locate the project folder, dot_product_asm. 3. In the Files of type box, select All Source Files from the drop-down list. 4. Hold down the Ctrl key and click dotprod.c and dotprod_main.c. Then click Add. To display the files that you added in step 4, open the Source Files folder in the Project window. 5. Click the Rebuild All button ( ) to build the project. The C source file opens in an editor window, and execution halts. 14 March 2016 Veton Këpuska 63 Step 2: Modifying the Project Source Files In this procedure we will: 1. Modify dotprod_main.c to call a_dot_asm instead of a_dot_c 2. Save the modified file 14 March 2016 Veton Këpuska 64 Step 2: Modifying the Project Source Files To modify dotprod_main.c to call assembly function a_dot_asm do the following: 1. 2. Resize or maximize the editor window for better viewing From the Edit menu, choose Find to open the Find dialog box as shown in the figure. 14 March 2016 Veton Këpuska 65 Step 2: Modifying the Project Source Files 3. In the Find What box, 1. 2. type “/*”, and then click Mark All. The editor bookmarks all lines containing “/*” and positions the cursor at the first instance of “/*” in the extern int a_dot_c_asm declaration. 4. Select the comment characters “/*” and 1. 2. Use the Ctrl+X key combination to cut the comment characters from the beginning of the a_dot_c_asm declaration. Then move the cursor up one line and use the Ctrl+V key combination to paste the comment characters at the beginning of the a_dot_c declaration. Because syntax coloring is turned on, the code changes color as you cut and paste the comment characters. Repeat this step for the end-of-comment characters “*/” at the end of the a_dot_c_asm declaration. The a_dot_c declaration is now fully commented out, and the a_dot_c_asm declaration is no longer commented. 14 March 2016 Veton Këpuska 66 Step 2: Modifying the Project Source Files 5. Press F2 to move to the next bookmark. The editor positions the cursor on the “/*” in the function call to a_dot_c_asm, which is currently commented out. Note that the previous line is the function call to the a_dot_c routine. 6. Press Ctrl+X to cut the comment characters from the beginning of the function call to a_dot_c_asm. Then move the cursor up one line and press Ctrl+V to paste the comment characters at the beginning of the call to a_dot_c. Repeat this step for the end-of-comment characters “*/”. The main() function is now calling the a_dot_c_asm routine instead of the a_dot_c function (previously called in Exercise One). Note: The next image displays the changes made in the step 6. 14 March 2016 Veton Këpuska 67 Step 2: Modifying the Project Source Files 14 March 2016 Veton Këpuska 68 Step 2: Modifying the Project Source Files 7. From the File menu, choose Save and then File dotprod_main.c to save the changes to the file. 8. Place the cursor in the editor window. Then, from the File menu, choose Close and then File dotprod_main.c to close the dotprod_main.c file. 14 March 2016 Veton Këpuska 69 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf In this procedure we will: View the Expert Linker representation of the .ldf file that is created. Modify .ldf file to map in the section for the a_dor_c_asm assembly routine. 14 March 2016 Veton Këpuska 70 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf To examine and then modify dot_prod_asm.ldf to link eith the assembly function do the following: 1. Click the Ad File button . 2. Select dotprod_func.asm and click Add. 3. Build the project by performing one of these actions: Click the Build Project button . From the Project menu, choose Build Project. 4. Notice the error in the Output window. 14 March 2016 Veton Këpuska 71 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf Output Window: Linker Error To correct this error the do the following: 14 March 2016 Veton Këpuska 72 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf In the Project window, double-click in the dot_prod_asm.ldf file. The Expert Linker window (see Figure in the next slide) opens with a graphical representation of your file. Resize the window to expand the view and change the view mode. To display the tree view shown in next slide, right-click in the right pane, choose View Mode, and then choose Memory Map Tree. The left pane (Input Sections) contains a list of the input sections that are in your project or are mapped in the .LDF file. A red X is over the icon in front of the section named “my_asm_section” because Expert Linker has determined that the section is not mapped by the .LDF file. The right pane (Memory Map) contains a representation of the memory segments that Expert Linker defined when it created the .LDF file. Expert Linker Window depicts the procedure followed in this step. 14 March 2016 Veton Këpuska 73 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf 14 March 2016 Veton Këpuska 74 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf 6. Map my_asm_section into the memory segment named MEM_PROGRAM as follows. In the Input Sections pane, open my_asm_section by clicking on the plus sign in front of it. The input section expands to show that the linker macros: $COMMAND_LINE_OBJECTS and $OBJECTS and the object file dotprod_func.doj have a section that has not been mapped. In the Memory Map pane, expand MEM_L1_CODE and drag the icon in front of $OBJECTS onto the program_ram output section under MEM_L1_CODE. As shown in Figure in the next slide, the red X should no longer appear because the section my_asm_section has been mapped. 14 March 2016 Veton Këpuska 75 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf 14 March 2016 Veton Këpuska 76 Step 3: Use the Expert Linker to Modify dot_prod_asm.ldf 7. From the Tools menu, choose Expert Linker and Save to save the modified file. Then close the Expert Linker window. If you forget to save the file and then rebuild the project, VisualDSP++ will see that you modified the file and will automatically save it. 14 March 2016 Veton Këpuska 77 Step 4: Rebuild and Run dot_prod_asm Build the project by: 1. Click the Build Project button , or 2. From the Project menu, choose Build Project. At the end of the build, the Output window should display this message in the Build view: “Build completed successfully” VisualDSP++ loads the program Runs to main, and Displays the Output, Disassembly, and editor windows (as seen in the next slide) 14 March 2016 Veton Këpuska 78 Step 4: Rebuild and Run dot_prod_asm 14 March 2016 Veton Këpuska 79 Step 4: Rebuild and Run dot_prod_asm Click the Run button to run dot_product_asm. The program calculates the three dot products and displays the results in the Console view of the Output window. When the program stops running, the message “Halted” appears in the status bar at the bottom of the VisualDSP++ main window. The results, shown below, are identical to the results obtained in Exercise One. Dot product [0] = 13273595 Dot product [1] = –49956078 Dot product [2] = 35872518 14 March 2016 Veton Këpuska 80 Exercise 3 Plotting Data Goals of this Exercise Learn to: Load and debug a prebuilt program that applies a simple Finite Impulse Response (FIR) filter to a buffer of data Use VisualDSP++’s plotting engine to view the different data arrays graphically, both before and after running the program. 14 March 2016 Veton Këpuska 82 Digression: What is an FIR Filter Digital Filtering, in general, is one of the most powerful tools of Digital Signal Processing. In general any Digital Signal Processing of a Linear Time Invariant (LTI) system can be expressed with a difference equation (more on this latter) 14 March 2016 Veton Këpuska 83 Linear Constant-Coefficient Difference Equations Nth-order linear constant-coefficient difference equation is of the form: N M a yn k b xn k k 0 k m 0 k Accumulator Example y[n] n x[k ] k y[n 1] n 1 x[k ] k 14 March 2016 Veton Këpuska 84 Linear Constant-Coefficient Difference Equations (cont.) y[n] x[n] n 1 x[k ] k y[n] x[n] y[n 1] y[n] y[n 1] x[n] x[n] y[n] One-sample delay 14 March 2016 Veton Këpuska 85 General Formulation of Difference Equation Equation: N M yn k yn k k xn k k 1 k 0 Along with initial conditions: y[-1], y[-2], …, y[-N] Uniquely specifies the LTI system. General equation must be computed using recursive procedure. 14 March 2016 Veton Këpuska 86 Example Recursive Computation of Difference Equations: y[n] = ay[n-1]+x[n] Initial condition is given by y[-1] = c; Input x[n] = K[n] Solution n≥0: y[0] = ac+K y[1] = y[0]+0 = a(ac+K) = a2c+aK … y[n] = an+1c+anK, n≥0 14 March 2016 Veton Këpuska 87 Example (cont.) Solution n<0: y[n] = ay[n-1]+x[n] ➲ y[n-1] = a-1(y[n]-x[n]) y[-1] = c y[-2] = a-1(y[-1]-x[-1]) = a-1 (c+0) = a-1c … y[n] = an+1c, n<0 Overall solution y[n] = an+1c+Kanu[n], n 14 March 2016 Veton Këpuska 88 Z-Transform Interesting specific class of rational functions of the form: P( z ) X ( z) Q( z ) Roots of the polynomial P(z) define the zeros, and Roots of the polynomial Q(z) define the poles of the z-transform. Partial fraction expansion method can be used for rational functions. 14 March 2016 Veton Këpuska 89 Difference Equation & Z-Transform By definition variable Z is equal to unit delay. There is direct relationship between difference equation and Z-Transform: N M k 1 k 0 yn k yn k k xn k Y ( z) H ( z) X ( z) 14 March 2016 Veton Këpuska 90 Property of Z-Transform xn X ( z ) xn k z X ( z ) k N M k 1 k 0 N M yn k yn k k xn k Y z k Y z z k k 1 14 March 2016 Veton Këpuska k X z z k k 0 91 Difference Equation & Z-Transform Y z N M k 1 k 0 k k Y z z X z z k k or M Y z H z X z k z k k 0 N 1 k z k k 1 Last expression is a rational function with numerator and denominator that are polynomials of z-1. 14 March 2016 Veton Këpuska 92 Filters Any Linear Time Invariant digital filter is expressed by its difference equation. There are two classes of digital filters: Finite Impulse Response (FIR), and Infinite Impulse Response (IIR). 14 March 2016 Veton Këpuska 93 FIR Filters The impulse response of an FIR filter has finite duration and corresponds to having no denominator in the rational function H(z): ➨ There is no feedback in the difference Equation. This results in the reduced form difference equation: M yn r xn r r 0 Impulse sample response (input x[0]=1; x[n]=0 elsewhere for n≠0) of FIR filter is: hn n ,0 n M hn 0, otherwise 14 March 2016 Veton Këpuska 94 Step 1: Loading the FIR Program 1. Keep the Disassembly window and Console page (of the Output window) open, but close all other windows. 2. From the File menu, choose Load Program or click The Open a Processor Program dialog box appears. 3. Select the FIR program to load as follows. a. Open the Analog Devices folder and double-click: VisualDSP 4.5\Blackfin\Examples\Tutorial\fir b. c. Double-click the Debug subfolder. Double-click FIR.DXE to load the program. If VisualDSP++ does not open an editor window (shown in Figure in the next slide), right-click in the Disassembly window and select View Source. 14 March 2016 Veton Këpuska 95 Step 1: Loading the FIR Program 14 March 2016 Veton Këpuska 96 Step 1: Loading the FIR Program 4. 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. 14 March 2016 Veton Këpuska 97 Step 2: Opening a Plot Window 1. From the View menu, choose Debug Windows and Plot. Then choose New to open the Plot Configuration dialog box, shown in the next slide Figure. Here you add the data sets that you want to view in a plot window. 2. 3. In the Plot group box, specify the following values. In the Type box, select Line Plot from the dropdown list. In the Title box, type fir. Enter two data sets to plot by using the values in Table in the slide after next. 14 March 2016 Veton Këpuska 98 Step 2: Opening a Plot Window 14 March 2016 Veton Këpuska 99 Step 2: Table Specifying 2 Data sets: Input & Output Box Input Data Set Output Data Set Description Name Input Output Data set Memory BLACKFIN Memory BLACKFIN Memory Data memory Address IN OUT The address of this data set is that of the Input or Output array. Click Browse to select the value from the list of loaded symbols Count 128 128 The array is 260 elements long, but you are plotting the first 128 elements Stride 1 1 The data is contiguous in memory Data short short Input & Output are arrays of int values 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 the one in the Figure presented in the next slide. 14 March 2016 Veton Këpuska 100 Step 2: Opening a Plot Window Plot Configuration Dialog Box with Input/Output Data Sets 14 March 2016 Veton Këpuska 101 Step 2: Opening a Plot Window 4. Click OK to apply the changes and to open a plot window with these data sets. The plot window now displays the two arrays. By default, the simulator initializes memory to zero, so the Output data set appears as one horizontal line, shown in Figure below. 14 March 2016 Veton Këpuska 102 Step 2: Opening a Plot Window 5. Right-click in the plot window and choose Modify Settings. On the General page, in the Options group box, select Legend and click OK to display the legend box. 14 March 2016 Veton Këpuska 103 Step 3: Run the FIR Program and View the Data Press F5 or click the Run button program. to run to the end of the When the program halts, you see the results of the FIR filter in the Output array. The two data sets are visible in the plot window, as shown in Figure below: 14 March 2016 Veton Këpuska 104 Step 3: Run the FIR Program and View the Data 2. Additional Features of the Plotting interface allows you to select the region and to zoom in. 14 March 2016 Veton Këpuska 105 Step 3: Run the FIR Program and View the Data 14 March 2016 Veton Këpuska 106 Step 3: Run the FIR Program and View the Data To return to the view before magnification, right-click in the plot window and choose Reset Zoom from the pop-up menu. Individual data points can be viewed as described in the following procedure: 3. Right-click inside the plot window and choose Data Cursor from the pop-up menu. Move to each data point in the current data set by pressing and holding the Left (←) or Right (→) arrow key on the keyboard. To switch data sets, press the Up (↑) or Down (↓) arrow key. The value of the current data point appears in the lower-left corner of the plot window, as shown in Figure in the next slide. 14 March 2016 Veton Këpuska 107 Step 3: Run the FIR Program and View the Data 14 March 2016 Veton Këpuska 108 Step 3: Run the FIR Program and View the Data 4. Right-click in the plot window and choose Data Cursor from the popup menu. Next you will look at data sets in the frequency domain. 5. 6. Right-click in the plot window and choose Modify Settings to open the Plot Settings dialog box. Complete these steps: a. Click the Data Processing tab to display the Data Processing page, shown in next Figure. b. In the Data Sets box, ensure that Input (the default) is selected. In the Data Process box, choose FFT Magnitude. c. In the Sample rate (Hz) box, type 10000. d. In the Data Sets box, select Output. In the Data Process box, choose FFT Magnitude e. Click OK to exit the Plot Settings dialog box. VisualDSP++ performs a Fast Fourier Transform (FFT) on the selected data set before it is plotted. The FFT enables you to view the signal in the frequency domain, as shown in Figure after next. 14 March 2016 Veton Këpuska 109 Step 3: Run the FIR Program and View the Data Data Processing Page 14 March 2016 Veton Këpuska 110 Step 3: Run the FIR Program and View the Data FFT Performed on a Selected Data Set 14 March 2016 Veton Këpuska 111 Step 4: Analysis of the Data 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 in the next slide. 14 March 2016 Veton Këpuska 112 Step 4: Analysis of the Data 14 March 2016 Veton Këpuska 113 Step 4: Analysis of the Data 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. VisualDSP++ performs a Fast Fourier Transform (FFT) on the selected data set, and enables you to view the filters frequency response plot in the frequency domain, as shown in Figure in the next slide. 14 March 2016 Veton Këpuska 114 Step 4: Analysis of the Data Filter’s Frequency Response Plot 14 March 2016 Veton Këpuska 115 Step 4: Analysis of the Data This plot shows that the low-pass FIR filter cuts off all frequency components above 4,000 Hz. When you apply this low-pass filter to the input signal, the resulting signal has no output above 4,000 Hz. On the importance of filtering more later: Telephony toll-quality signal requires that signal has no frequency components above 4000 Hz to avoid aliasing. The effect of aliasing is depicted as a low frequency noise “reflected” from the components above 4000 Hz. 14 March 2016 Veton Këpuska 116 Exercise 4 Linear Profiling Goals of this Exercise Learn to: Load and debug the FIR program from the previous exercise 3 Use linear profiling to evaluate the program’s efficiency and to determine where the application is spending the majority of its execution time in the code 14 March 2016 Veton Këpuska 118 VisualDSP++ Profiling VisualDSP++ supports two types of profiling: linear and statistical. Linear Profiling: You use linear profiling with a simulator. The count in the Linear Profiling Results window is incremented every time an assembly instruction is executed. Statistical Profiling: You use statistical profiling with a JTAG emulator connected to a processor target. The count in the Statistical Profiling Results window is based on random sampling of the program counter. 14 March 2016 Veton Këpuska 119 Step 1: Loading the FIR Program 1. Close all open windows except the Disassembly window and the Output window. 2. Keep the Disassembly window and Console page (of the Output window) open, but close all other windows. 3. From the File menu, choose Load Program or click The Open a Processor Program dialog box appears. 4. Select the FIR program to load as follows. a. Open the Analog Devices folder and double-click: VisualDSP 4.5\Blackfin\Examples\Tutorial\fir b. Double-click the Debug subfolder. c. Double-click FIR.DXE to load and run the FIR program. If VisualDSP++ does not open an editor window, right-click in the Disassembly window and select View Source. 14 March 2016 Veton Këpuska 120 Step 2: Opening the Profiling Window 1. From the Tools menu, choose Linear Profiling and then choose New Profile. The Linear Profiling Results window opens without any data. 2. Click in the profiling window’s title bar and then drag and drop the window to the top of the VisualDSP++ main window, as shown in Figure in the next slide. You will have a better view of the profile data. 14 March 2016 Veton Këpuska 121 Step 2: Opening the Profiling Window 14 March 2016 Veton Këpuska 122 Step 2: Opening the Profiling Window The Linear Profiling Results window is initially empty. Linear profiling is performed when you run the FIR program. After you run the program and collect data, this window displays the results of the profiling session. 14 March 2016 Veton Këpuska 123 Step 3: Collecting & Examining the Linear Profiling Data 1. Press F5 or click to run to the end of the program. When the program halts, the results of the linear profile appear in the Linear Profiling Results window. 2. Examine the results of your linear profiling session. The Linear Profiling Results window is divided into two three-column panes. The left pane shows the results of the profile data. You can see the percentages of total execution time consumed, by function and by address. Double-clicking a line with a function enables you to display the source file that contains that function. For example, double-click the fir function to display the assembly source file (fir.asm) in the right pane, as shown in Figure in the next slide. 14 March 2016 Veton Këpuska 124 Step 3: Collecting & Examining the Linear Profiling Data Linear Profiling Results, FIR Program Performance Analysis. Note: your results may be slightly different. 14 March 2016 Veton Këpuska 125 Interpreting Collected Data Histogram A graphical representation of the percentage of time spent in a particular execution unit. This percentage is based on the total time that the program spent running, so longer bars denote more time spent in a particular execution unit. The Linear Profiling Results window always sorts the data with the most time-consuming (expensive) execution units at the top. % The numerical percent of the same data found in the Histogram column. You can view this value as an absolute number of samples by right-clicking in the Linear Profiling Results window and by selecting View Sample Count from the pop-up menu. Execution Unit The program location to which the samples belong. If the instructions are inside a C function or a C++ method, the execution unit is the name of the function or method. For instructions that have no corresponding symbolic names, such as hand-coded assembly or source files compiled without debugging information, this value is an address in the form of PC[xxx], where xxx is the address of the instruction. If the instructions are part of an assembly file, the execution unit is either an assembly function or the assembly file followed by the line number in parentheses. 14 March 2016 Veton Këpuska 126 Interpreting Collected Data In previous Figure, the left pane shows that the fir function consumes over 96% of total execution time. The right (source) pane, shown in next Figure, displays the percentage that each line in the fir function consumes. 14 March 2016 Veton Këpuska 127 Linear Profile Data for fir.asm 14 March 2016 Veton Këpuska 128 End of Tutorial