Laboratory 3 Learning C and Sinewave Generation



Similar documents
Developing applications under CODE COMPOSER STUDIO

Code Composer Studio Getting Started Guide

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Using Example Projects, Code and Scripts to Jump-Start Customers With Code Composer Studio 2.0

Code Composer Studio Development Tools v3.3. Getting Started Guide

TMS320C67x FastRTS Library Programmer s Reference

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

LABVIEW DSP TEST TOOLKIT FOR TI DSP

Freescale Semiconductor, I

An Introduction to MPLAB Integrated Development Environment

Project Manager Editor & Debugger

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Code::Blocks Student Manual

AN-8207 Fairchild s Motor Control Development System (MCDS) Integrated Development Environment (IDE)

Lab 3: Introduction to Data Acquisition Cards

Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

CooCox CoIDE UserGuide Version: page 1. Free ARM Cortex M3 and Cortex M0 IDE: CooCox CoIDE UserGuide

3. Programming the STM32F4-Discovery

Hardware and Software Requirements

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Getting Started with the LabVIEW Mobile Module

GIVE WINGS TO YOUR IDEAS TOOLS MANUAL

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

DS-5 ARM. Using the Debugger. Version 5.7. Copyright 2010, 2011 ARM. All rights reserved. ARM DUI 0446G (ID092311)

CP Lab 2: Writing programs for simple arithmetic problems

Animated Lighting Software Overview

Lesson 1 - Creating a Project

MPLAB C18 C Compiler

IAR Embedded Workbench

LabVIEW DSP Test Integration Toolkit for TI DSP

Microsoft Visual Studio 2010 Instructions For C Programs

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Using HiTOP with the HOT16x Hands-On Training Materials

Introduction to ROOT and data analysis

Application Note: AN00141 xcore-xa - Application Development

7-1. This chapter explains how to set and use Event Log Overview Event Log Management Creating a New Event Log...

Small Hardware Development and Prototyping Board for the SX28

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

VisualDSP Emulation Tools Installation Guide for Windows 95/98/NT/2000

Building an Embedded Processor System on a Xilinx Zync FPGA (Profiling): A Tutorial

C++ Programming Language

DS-5 ARM. Using the Debugger. Version Copyright ARM. All rights reserved. ARM DUI 0446M (ID120712)

Programming LEGO NXT Robots using NXC

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

Programming with the Dev C++ IDE

Introduction to Simulink

Set up a Nios II project that specifies a desired hardware system and software program

Floating Point C Compiler: Tips and Tricks Part I

Start Active-HDL by double clicking on the Active-HDL Icon (windows).

Set up a Nios II project that specifies a desired hardware system and software program

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

ML310 Creating a VxWorks BSP and System Image for the Base XPS Design

Software development and debugging for NXP ARM7 MCUs

Control III Programming in C (small PLC)

EE289 Lab Fall LAB 4. Ambient Noise Reduction. 1 Introduction. 2 Simulation in Matlab Simulink

SECTION 3 - INSTALLATION

Administration guide. Host software WinCCU Installation. Complete gas volume and energy data management

Debugging Java Applications

Lab Experiment 1: The LPC 2148 Education Board

Lab 1: Introduction to Xilinx ISE Tutorial

8051 MICROCONTROLLER COURSE

DSP Laboratory: Analog to Digital and Digital to Analog Conversion

DiskPulse DISK CHANGE MONITOR

Illustration 1: Diagram of program function and data flow

Creating a Webserver on the Nios development kit Stratix Edition board Enoch Hwang

Using C to Access Data Stored in Program Memory on the TMS320C54x DSP

Compustat data via Research Insight Quick Reference Guide

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

by NetMedia, Inc. All rights reserved. Basic Express, BasicX, BX-01, BX-24 and BX-35 are trademarks of NetMedia, Inc. 2.

V850E2/ML4 APPLICATION NOTE. Performance Evaluation Software. Abstract. Products. R01AN1228EJ0100 Rev Aug. 24, 2012

Using these objects to view the process of the whole event from triggering waiting for processing until alarm stops. Define event content first.

Intel Rapid Storage Technology

Embedded Software development Process and Tools:

TMS320C6000 Code Composer Studio Tutorial

Getting Started Using Mentor Graphic s ModelSim

Java Crash Course Part I

Building a Simulink model for real-time analysis V Copyright g.tec medical engineering GmbH

Fall 2006 CS/ECE 333 Lab 1 Programming in SRC Assembly

Implementation of Web-Server Using Altera DE2-70 FPGA Development Kit

OCS Training Workshop LAB14. Setup

Debugging of Application Programs on Altera s DE-Series Boards. 1 Introduction

Lab 1 Course Guideline and Review

Xcode Project Management Guide. (Legacy)

Capture Pro Software FTP Server System Output

Lab Experience 17. Programming Language Translation

Hypercosm. Studio.

Code Composer Studio s Command Window

DRV8312-C2-KIT How to Run Guide

Athena Knowledge Base

Status Monitoring. Using Drivers by Seagull to Display Printer Status Information WHITE PAPER

Assignment 09. Problem statement : Write a Embedded C program to switch-on/switch-off LED.

Fast Arithmetic Coding (FastAC) Implementations

Creating a Guest Book Using WebObjects Builder

Chapter 3 Software Installation

Transcription:

Department of Electrical and Electronic Engineering Imperial College of Science, Technology and Medicine EE3T Study Project: Real-Time Digital Signal Processing with TMS320C6000 Objectives Laboratory 3 Learning C and Sinewave Generation Learn how to create and build a project. Learn how to use functions in C. Learn how to generate a sinewave using table lookup. Map the Network Drive 1. Map \\reserver\sp_data to m: 2. Copy the files from m: C6x labs lab3 to an appropraite subdirectory in your workspace on h: for use. This should be the same directory in which you create the project below. Create the project file The first step in creating a new DSP program is to create a project file and to add appropriate configuration files. These configuration files automatically handle memory mapping and allow you to set various global parameters (in particular, we will use the configuration file in later labs to assign interrupts). 1. Create a new project called lab3.mak Project:New and save it in an appropriate subdirectory in your workspace on h: 2. Create a new DSP/BIOS configuration file called lab3.cdb File:New:DSP/BIOS Configuration using the dsk6711.cdb template. Save this file in the same subdirectory. Take care to use the correct extension, for some reason the default extension is a PowerPoint file! 3. Add the configuration file to the project. Project:Add Files to Project This also automatically adds the file lab3cfg.s62. 4. Also add the linker command file lab3cfg.cmd. DBW 2001 1

The sinewave generation program You are provided with a simple program sine.c whose listing is given in Appendix A. This program does the following: Initializes I/O ports with calls to CSL Init, BSL init, and codec init. This is done using predefined functions, we will look at these functions in more detail in a later lab. A while loop runs forever, writing out data calculated in the subroutine sinegen(). Currently this subroutine simply outputs a sine wave of fixed frequency. In the reminder of the lab you will write a routine that outputs a sine wave of a user-defined frequency. 1. Add the C program sine.c to the project. Building the project Building the project consists of three steps: compiler, assembler, linker. Each of these steps has various options which determine, for example, how efficient is the DSP code that is generated. Two.txt files are provided that contain appropriate compiler and linker options. 1. Set the compiler options Project:Options by copying the contents of compiler.txt to the Compiler window. 2. Set the assembler options to -gls 3. Set the linker options by copying the contents of linker.txt to the Linker window. 4. Now build the project Project:Rebuild All This can also be done using the appropriate icon on the left hand side. Once it has successfully compiled and linked, it will create a file sine.out that is the DSP executable file. Load and run the program Having built the program it can be downloaded to the DSP and run. 1. Load the program to the DSP File:Load Program 2. Connect an oscilloscope to the DSK output, and run the program Debug:Run or click the appropriate icon on the left. Ensure that the output is a sinewave. 3. Halt the program Debug:Halt or click the appropriate icon on the left. DBW 2001 EE3T Study Project 2

Later when the program is modified and rebuilt it can be reloaded to the DSP by using File:Reload Program. Note that you should always halt the DSP before loading or reloading a program. Generating a sine wave Currently, the function sinegen generates a sinewave with fixed frequency of around 1 khz. In the remainder of the lab you will rewrite this function so that the frequency that is output is determined by the global constant SINE FREQ. The simplest way of generating a sinewave signal is by using a sine lookup table. We will define a lookup table in memory, and then modify sinegen so that it uses this table to output a sinewave of the desired frequency. 1. Define a global constant SIZE TABLE that determines how many values are in the table, and assign it a value of 256. (See the definition of SAMPLE FREQ for how to declare global constants.) 2. Define a global variable x that is an array of floats containing SIZE TABLE elements. This is done by inserting the following line in the section of the program designated as being for Global Variables: float x[size_table]; Notice that the definition for y defines an array of 3 floats, and assigns some initial values. The above definition for x does not assign initial values. In C, arrays are indexed starting from 0, so an array of 10 values would be indexed 0 through 9. Individual elements of an array are accessed by using the variable name followed by the index in square brackets. For example, to assign the zeroth element of x to 0.2, you would use x[0] = 0.2; 3. Having defined how big the table is and where it will be stored in memory, we now need to create a function that will fill it with the appropriate sine values. Create a function sine init that will do this. It will have no parameters and return no value, its purpose is simply to initialize the global variable x. This will involve defining the function prototype (look at the definition of codec init at the top of sine.c for how to do this). Now you will need to write the implementation of this function. It should consist of a for loop (see C programming guide for syntax) that fills x with the appropriate number of points within one period of a sine wave. In the math.h library file (which is included in the shell program), there is a function sin() that returns the sine of its argument (in radians). A global constant PI is assigned a value of 3.1415926 (in the included file c6211dsk.h) for you to use. 4. Add a call to sine init in the main program, just before the while loop. Rebuild the project and download it to the DSP. Set a breakpoint just after the call to sine init, and run the program. To check that your function is successful, look at the memory starting at x (View:Memory) and confirm that 256 points within a single period of a sine wave are stored there. You could also do this by using the graph function (View:Graph:Time/Frequency). Ensure that sine init is working correctly before proceeding. DBW 2001 EE3T Study Project 3

5. Now rewrite the function sinegen so that it reads the appropriate value from the sine table and returns this value to the main routine. You will need to use the global constants SIZE TABLE and SAMPLE FREQ which have been pre-defined for you. You shouldn t need to modify the main program further at this stage, it is only necessary to rewrite the implementation of sinegen. 6. Since the frequency of the sine wave is determined by the global variable SINE FREQ, you can easily change the output frequency by changing the value of this variable. Open a watch window (View:Watch Window) and insert SINE FREQ. By double-clicking on SINE FREQ within the watch window you will be able to update the frequency of the sine wave without requiring you to recompile the code. Comments Within the existing function sinegen, the variable wave is a local variable. Any variable that is defined within a function is local, and it is undefined outside that particular function. Moreover, when the function is exited the local variable loses its value. If it is necessary for a variable to keep its value even after a local function is exited, or from one function call to the next, it should be defined as a global variable, by inserting its definition before main (as you just did when defining x). You will probably need to define one more variable as a global variable, and use it to keep track of where you are within the sine table from one call of sinegen to the next. DBW 2001 EE3T Study Project 4

Appendix A /* SINE.C Sinewave generation lab DBW 24/4/01 */ * Function prototypes void codec_init(void); float sinegen(void); * Include files #include <c6x.h>/* C6000 compiler definitions header */ #include <c6211dsk.h> /* C6000 DSK definitions header */ #include <csl.h>/* CSL headers */ #include <bsl.h>/* BSL headers */ #include <bsl_ad535.h> #include <bsl_extra.h> #include <mcbsp.h> /* Multichannel serial port header */ #include <math.h> * Definitions #define SAMPLE_FREQ 8000.0 * Global variables AD535_Handle had535; AD535_Config my_ad535_config = { AD535_LOOPBACK_DISABLE, AD535_MICGAIN_OFF, AD535_GAIN_0DB, AD535_GAIN_0DB ; float SINE_FREQ = 3000.0; /* THE FOLLOWING DEFINITION IS ONLY NEEDED FOR THE SHELL PROGRAM, IT CAN BE REMOVED LATER */ float y[3] = {0,0.7071,0; * Main routine void main(){ DBW 2001 EE3T Study Project 5

/* Local variables */ float sample; /* Initialize the chip support library, required */ CSL_Init(); /* Initialize the board support library, required */ BSL_init(); /* Open and configure the local codec */ codec_init(); /* loop forever writing sinewave */ while(1) { /* scale the output to use the full range and output it using the pre-defined function */ sample = sinegen(); AD535_write(hAD535,(int)(32000*sample)); /************************************ * Codec functions *************************************/ void codec_init() { /* Use BSL routines to open, reset, and configure the codec */ had535 = AD535_open(AD535_localId); AD535_reset(hAD535); AD535_config(hAD535, &my_ad535_config); MCBSP_setfree(0); * Function implementations float sinegen(void) { /* YOU NEED TO REWRITE THIS FUNCTION */ float wave; float A = 1.4142; y[0] = y[1] * A - y[2]; y[2] = y[1]; y[1] = y[0]; wave = y[0]; return(wave); DBW 2001 EE3T Study Project 6