MRCL - MPDSP Lab Manual
MRCL - MPDSP Lab Manual
OF INSTITUTIONS
(Approved by AICTE & Affiliated to JNTU-KAKINADA)
Vizianagaram-535216
MICROCONTROLLERS AND
PROGRAMMABLE DIGITAL SIGNAL PROCESSORS
LAB MANUAL
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Regulation : R19
Class : I M.Tech _ I Sem
Branch : VLSI & Embedded Systems
Department : ECE
Subject Code : 19MECE1007
COURSE OBJECTIVES
S.NO DESCRIPTION
1 Demonstrate Keil IDE tool for development of Embedded system.
2 Program the interfacing of various devices with ARM using Embedded C.
3 Develop program for implementation of interrupts and serial communications.
4 Implementation of digital signal processing algorithms in MATLAB and C
5 Understand the real-time operation of digital filters
COURSE OUTCOMES
S.NO DESCRIPTION
1 Understand the architecture of Cortex M3
2 Develop Embedded C Programs for any problem statement
3 Understand the architecture and programming using DSP Processors
3. Students have to bring the observation book, record along with them whenever they come for lab work.
4. Should take only the lab observation, calculator (if needed) and a pen or pencil to the work area.
5. Should learn the prelab questions. Read through the lab experiment to familiarize themselves with the
components and assembly sequence.
6. Should utilize 4 hours‟ time properly to perform the experiment and to record the readings. Do the
calculations, draw the graphs and take signature from the instructor.
7. If the experiment is not completed in the stipulated time, the pending work has to be carried out in the
leisure hours or extended hours.
8. Should submit the completed record book according to the deadlines set up by the instructor.
9. For practical subjects there shall be a continuous evaluation during the semester for 25 internal marks and
75 end examination marks.
10. Out of 25 internal marks, 5 marks shall be awarded for day-to-day work, 5 marks for record work and 15
marks to be awarded by conducting an internal laboratory test.
1. Objective
The objective of this lab is to give you a “first foot in the door” exposure to the programming in C and
assembly of a program, which when executed by the microcontroller (NXP LPC1768, an ARM Cortex-
M3) simply blinks LEDs located on the development board. You also learn how to use the ARM Keil
uVision IDE to create projects, build and download them to the board (either Keil MCB1700 or Embest
EMLPC1700).
2. Pre-lab Preparation
Optional (but encouraged) You should plan to work on your own computer at home a lot during this
semester. You should install the main software (evaluation version) we will use in this course: the
Microcontroller Development Kit (MDKARM), which supports software development for and
debugging of ARM7, ARM9, Cortex-M, and Cortex-R4 processor-based devices. Download it from
ARM‟s website [1] and install it on your own computer. This is already installed on the computers in
the lab. MDK combines the ARM RealView compilation tools with the Keil µVision Integrated
Development Environment (IDE). The Keil µVision IDE includes: Project Management and Device &
Tool Configuration, Source Code Editor Optimized for Embedded Systems, Target Debugging and
Flash Programming, Accurate Device Simulation (CPU and Peripheral).
3. Lab Description
a. BLINKY 1
Creating a new project
1. First create a new folder called say EE378_S2013 where you plan to work on the labs of this course.
Then, inside it, create a new folder called lab1.
2. Launch uVision4, Start->All Programs->Keil uVision4
3. Select Project->New uVision Project… and then select lab1 as the folder to save in; also type
blinky1 as the File Name.
4. Then, select NXP (founded by Philips) LPC1768 as CPU inside the window that pops-up. Also,
click Yes to Copy “startup_LPCxx.s” to Project Folder.
5. Under File Menu select New.
6. Write your code in the and save it as blinky1.c in the same project folder. This file (as well as all
others discussed in this lab) is included in the downloadable archive from the website of this course.
The panel on the left side of the uVision IDE is the Project window. The Project window gives you the
hierarchy of Target folder and Source Group folder.
7. Right click on the “Source Group 1” and select “Add files to Source Code”.
8. Locate blinky1.c and include it to the group folder.
9. Copy C:\Keil\ARM\Startup\NXP\LPC17xx\system_LPC17xx.c to lab1 directory and add it as a
source file to the project too. Open this file and browse it quickly to see what functions are defined
inside it.
10. Click Project menu and then select Build Target.
Debugging
If your program has errors (discovered by compiler or linker) or you simply want to debug it to verify
its operation, then we can use the debugging capabilities of the uVision tools.
1. Click Debug menu option and select Start/Stop Debug Session. A warning about the fact that this is
an evaluation version shows up; click OK.
2. Then, a new window appears where we can see the simulation of the program.
3. This window has several different supportive panels/sub-windows where we can monitor changes
during the simulation. The left hand side panel, Registers, provides information regarding the
Registers of LPC17xx with which we are working.
4. Again, click on the Debug menu option and select Run. The code starts simulating.
5. It is good practice that before going ahead with the actual hardware implementation to perform a
debug/simulation session to make sure that our program behaves according to the design
requirements. 6. In our example, we use PORT1.
7. Go to Peripherals menu option then select GPIO Fast Interface followed by Port 1.
8. You should get the window shown in Fig.2 below, where you can see LED P1.29 blinking. To
actually observe this you should wait until the simulated time (shown on the bottom-right side of the
uVision ISE window) is longer than 1 second. Note that in order to actually simulate 1 second of
execution time of the program, the simulator must run much longer. This is expected, as typically
simulators require much longer computational runtimes (wallclock time) in order to simulate
relatively short execution times of the program under investigation!
10. The debugger is a very powerful tool. This is only a brief exposure to it; we‟ll revisit it many times
later in this course. Once you are done with the simulation/debug of your program, you can stop it by
selecting Start/Stop the Debug Session from the Debug menu option. This stops the show and takes
us back to the main uVision window.
A signal can be defined as a function that conveys information, generally about the state or behavior
of a physical system. There are two basic types of signals viz Analog (continuous time signals which
are defined along a continuum of times) and Digital (discrete-time).
Remarkably, under reasonable constraints, a continuous time signal can be adequately represented by
samples, obtaining discrete time signals. Thus digital signal processing is an ideal choice for anyone
who needs the performance advantage of digital manipulation along with today‟s analog reality.
Hence a processor which is designed to perform the special operations (digital manipulations) on the
digital signal within very less time can be called as a Digital signal processor. The difference between
a DSP processor, conventional microprocessor and a microcontroller are listed below.
Feature Use
Fast-Multiply accumulate Most DSP algorithms, including filtering,
transforms, etc. are multiplication-
intensive
Multiple – access memory architecture Many data-intensive DSP operations
require reading a program instruction
and multiple data items during each
instruction cycle for best performance
Specialized addressing modes Efficient handling of data arrays and first-
in, first-out buffers in memory
Specialized program control Efficient control of loops for many
iterative DSP algorithms. Fast interrupt
handling for frequent I/O operations.
On-chip peripherals and I/O interfaces On-chip peripherals like A/D converters
allow for small low cost system
designs. Similarly I/O interfaces
tailored for common peripherals allow
clean interfaces to off-chip I/O devices.
Digital Signal Processing can be divided into two categories, fixed point and floating point which refer
to the format used to store and manipulate numbers within the devices. Fixed point DSPs usually
represent each number with a minimum of 16 bits, although a different length can be used. There are
four common ways that these 216 i,e., 65,536 possible bit patterns can represent a number. In unsigned
integer, the stored number can take on any integer value from 0 to 65,535, signed integer uses two's
complement to include negative numbers from -32,768 to 32,767. With unsigned fraction notation, the
65,536 levels are spread uniformly between 0 and 1 and the signed fraction format allows negative
numbers, equally spaced between -1 and 1. The floating point DSPs typically use a minimum of 32 bits
to store each value. This results in many more bit patterns than for fixed point, 232 i,e., 4,294,967,296
to be exact. All floating point DSPs can also handle fixed point numbers, a necessity to implement
counters, loops, and signals coming from the ADC and going to the DAC. However, this doesn't mean
that fixed point math will be carried out as quickly as the floating point operations; it depends on the
internal architecture.
C VERSUS ASSEMBLY:
DSPs are programmed in the same languages as other scientific and engineering applications, usually
assembly or C. Programs written in assembly can execute faster, while programs written in C are
easier to develop and maintain. In traditional applications, such as programs run on PCs and
mainframes, C is almost always the first choice. If assembly is used at all, it is restricted to short
subroutines that must run with the utmost speed.
The primary reason for using a DSP instead of a traditional microprocessor is speed: the ability to
move samples into the device and carry out the needed mathematical operations, and output the
processed data. The usual way of specifying the fastness of a DSP is: fixed point systems are often
quoted in MIPS (million integer operations per second). Likewise, floating point devices can be
specified in MFLOPS (million floating point operations per second).
TMS320 FAMILY:
The Texas Instruments TMS320 family of DSP devices covers a wide range, from a 16-bit fixed-point
device to a single-chip parallel-processor device. In the past, DSPs were used only in specialized
applications. Now they are in many mass-market consumer products that are continuously entering
new market segments. The Texas Instruments TMS320 family of DSP devices and their typical
applications are mentioned below.
C1x, C2x, C2xx, C5x, and C54x:
The width of the data bus on these devices is 16 bits. All have modified Harvard architectures. They
have been used in toys, hard disk drives, modems, cellular phones, and active car suspensions.
C3x:
The width of the data bus in the C3x series is 32 bits. Because of the reasonable cost and floating-point
performance, these are suitable for many applications. These include almost any filters, analyzers, hi-fi
systems, voice-mail, imaging, bar-code readers, motor control, 3D graphics, or scientific processing.
C4x:
This range is designed for parallel processing. The C4x devices have a 32-bit data bus and are
floating-point. They have an optimized on-chip communication channel, which enables a number of
them to be put together to form a parallel-processing cluster. The C4x range devices have been used in
virtual reality, image recognition, telecom routing, and parallel-processing systems.
C6x:
The C6x devices feature Velocity, an advanced very long instruction word (VLIW) architecture
developed by Texas Instruments. Eight functional units, including two multipliers and six arithmetic
logic units (ALUs), provide 1600 MIPS of cost-effective performance. The C6x DSPs are optimized for
multi-channel, multifunction applications, including wireless base stations, pooled modems, remote-
access servers, digital subscriber loop systems, cable modems, and multi-channel telephone systems.
The high–performance board features the TMS320C6713 floating-point DSP. Capable of performing
1350 million floating point operations per second, the C6713 DSK the most powerful DSK
development board
The DSK is USB port interfaced platform that allows efficiently developing and testing applications for
the C6713. With extensive host PC and target DSP software support, the DSK provides ease-of-use and
capabilities that are attractive to DSP engineers. The 6713 DSP Starter Kit (DSK) is a low-cost
platform which lets customers evaluate and develop applications for the Texas Instruments C67X DSP
family. The primary features of the DSK are:
TI‟s Code Composer Studio development tools are bundled with the 6713DSK providing the user with
an industrial-strength integrated development environment for C and assembly programming. Code
Composer Studio communicates with the DSP using an on-board JTAG emulator through a USB
interface. The TMS320C6713 DSP is the heart of the system. It is a core member of Texas
Instruments‟ C64X line of fixed point DSPs who‟s distinguishing features are an extremely high
The 6713 has a significant amount of internal memory so many applications will have all code and data
on-chip. External accesses are done through the EMIF which can connect to both synchronous and
asynchronous memories. The EMIF signals are also brought out to standard TI expansion bus
connectors so additional functionality can be added on daughter card modules. DSPs are frequently
used in audio processing applications so the DSK includes an on-board codec called the AIC23. Codec
stands for coder/decoder, the job of the AIC23 is to code analog input samples into a digital format for
the DSP to process, then decode data coming out of the DSP to generate the processed analog output.
Digital data is sent to and from the codec on McBSP1.
The DSK implements the logic necessary to tie board components together in a programmable logic
device called a CPLD. In addition to random glue logic, the CPLD implements a set of 4 software
programmable registers that can be used to access the on-board LEDs and DIP switches as well as
control the daughter card interface.
AIC23 Codec
The DSK uses a Texas Instruments AIC23 (part #TLV320AIC23) stereo codec for input and output of
audio signals. The codec samples analog signals on the microphone or line inputs and converts them
into digital data so it can be processed by the DSP. When the DSP is finished with the data it uses the
codec to convert the samples back into analog signals on the line and headphone outputs so the user can
hear the output.
The codec communicates using two serial channels, one to control the codec‟s internal configuration
registers and one to send and receive digital audio samples. McBSP0 is used as the unidirectional
Loaded PC the new hardware found wizard will come up. So, Install the drivers (The CCS
CD contains the require drivers for C6713 DSK).
If Code Composer Studio IDE fails to configure your port correctly, perform the following steps: Test
the USB port by running DSK Port test from the start menu
Use Start->Programs->Texas Instruments->Code Composer Studio-> Code Composer Studio C6713
DSK Tools -> C6713 DSK Diagnostic Utilities
The below Screen will appear
Select 6713 DSK Diagnostic Utility Icon from Desktop, The Screen Look like as below
Code Composer is the DSP industry's first fully integrated development environment (IDE) with DSP-
specific functionality. With a familiar environment liked MS-based C+, Code Composer lets you edit,
build, debug, profile and manage projects from a single unified environment. Other unique features
include graphical signal analysis, injection/extraction of data signals via file I/O, and multi-processor
IDE
Debug IDE
Advanced watch windows
Integrated editor
File I/O, Probe Points, and graphical algorithm scope probes
Advanced graphical signal analysis
Interactive profiling
Automated testing and customization via scripting
Visual project management system
Compile in the background while editing and debugging
Multi-processor debugging
Help on the target DSP
STEP 1: Start CCS Setup by double clicking on the Setup CCS desktop icon.
STEP 2: Select Family ->c67xx
Platform->simulator
Endean‟s->little
STEP 3: Click the Import button (File-> import) to import our selection (c67xx_sim.ccs)
to the System configuration currently being created in the CCS Setup window.
STEP 4: Click the Save and Quit button to save the configuration in the System Registry.
STEP 5: Click the Yes button to start the CCS IDE when we exit CCS Setup. The CCS
Setup Closes and the CCS IDE automatically opens using the configuration we
just created.
From the Project menu, choose New. In the Project Name field, type the name we want for our
project. Each project we create must have a unique name, and Click Finish. The CCS IDE
creates a project file called projectname.pjt. This file stores our project settings and references
the various files used by our project.
The Project Creation wizard window displays.
Create a new source file using „File ->new ->source file „ pull down menu and save the source
file with .c extension in the current project name directory. Save as type: c/c++ source file
(*.c*)
Path: C:\CCStudio_v3.1\ MyProjects\Project Name\
STEP 3: Add files to our project (source file\ library file\ linker file)
SOURCE FILE: Add the source file in the project using „Project->add files to project‟ pull
down menu. Files of type: c/c++ source file (*.c*)
Path: C:\CCStudio_v3.1\ My Projects\Project Name\filename‟s
LIBRARY FILE: Add the library file in the project using „Project-> add files to project‟
pull down menu. Files of type: Object and Library Files (*.o*,*.l*)
Path: C:\CCStudio_v3.1\ C6000\ cgtools\ lib \ rts6700.lib
STEP 4: Building and Running the Program (compile\ Build\ Load Program\ Run)
Choose View-> Graph-> Time/Frequency. In The Graph Property Dialog, Change The Graph
Title, Start Address, And Acquisition Buffer Size, Display Data Size, Dsp Data Type, Auto
Scale, And Maximum Y- Value Properties To The Values.
Program:
/*----------------------------------------------------------------------------
* Name: LED.c
* Purpose: low level LED functions*/
#include "LPC17xx.H" /* LPC17xx definitions */
#include "LED.h"
/*----------------------------------------------------------------------------
initialize LED Pins
*----------------------------------------------------------------------------*/
Void main()
{
void LED_Init (void) {
/*----------------------------------------------------------------------------
/*----------------------------------------------------------------------------
Function that turns off requested LED
*----------------------------------------------------------------------------
*/ void LED_Off (unsigned int num) {
/*----------------------------------------------------------------------------
Function that outputs value to LEDs
*----------------------------------------------------------------------------*/
void LED_Out(unsigned int value) {
int i;
Source Code:
/*----------------------------------------------------------------------------
* Name: ADC.c
* Purpose: low level ADC functions
* Note(s): possible defines select the used ADC interface:
* __ADC_IRQ - ADC works in Interrupt mode
* - ADC works in polling mode (default) */ #include
"LPC17xx.H" /* LPC17xx definitions #include "ADC.h" */
LPC_SC->PCONP |= ((1 << 12) | (1 << 15)); /* enable power to ADC & IOCON */
/*----------------------------------------------------------------------------
start AD Conversion
*----------------------------------------------------------------------------*/
void ADC_StartCnv (void) {
LPC_ADC->ADCR &= ~( 7 << 24); /* stop conversion */
LPC_ADC->ADCR |= ( 1 << 24); /* start conversion */
}
/*----------------------------------------------------------------------------
stop AD Conversion
*----------------------------------------------------------------------------*/
void ADC_StopCnv (void) {
/*----------------------------------------------------------------------------
get converted AD value
*----------------------------------------------------------------------------*/
uint16_t ADC_GetCnv (void) {
#ifndef __ADC_IRQ
while (!(LPC_ADC->ADGDR & ( 1UL << 31))); /* Wait for Conversion end */
AD_last = (LPC_ADC->ADGDR >> 4) & ADC_VALUE_MAX; /* Store converted value */
AD_done = 1;
#endif
return(AD_last);
}
/*----------------------------------------------------------------------------
A/D IRQ: Executed when A/D Conversion is done
*----------------------------------------------------------------------------*/
#ifdef __ADC_IRQ
void ADC_IRQHandler(void) {
volatile uint32_t adstat;
AD_done = 1;
}
#endif
}
Output: You can see the message on LCD.analog readings if required reset the board.
Aim : Write an embedded C program to control intensity of a led using pwm implemented in
software.
Apparatus:
Source Code:
#include <lpc17xx.h>
#include "pwm.h"
#include "delay.h"
while(1)
{
Output: In this program control intensity of an led using pwm implemented in software. You can see
output on display
Source code:
#include "adc.h"
#include "lcd.h"
#include "LPC17xx.h"
#include "delay.h"
int main()
{
int adcValue;
float temp;
SystemInit();
ADC_Init(); /* Initialize the ADC module */
while(1)
{
adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero where the
temperature sensor(LM35) is connected
/* Convert the raw ADC value to equivalent temperature with 5v as ADC reference
Step size of AdC= (5v/1023)=4.887mv = 5mv.
for every degree celcius the Lm35 provides 10mv voltage change.
1 step of ADC=5mv=0.5'c, hence the Raw ADC value can be divided by 2 to get
equivalent temp*/
RESULT:
Thus the Embedded C program for temperature indication on an RGB LED is written and
executed. The output is verified in the CORTEX kit.
THEORY:
Formula:
C Code:
#include <stdio.h>
#include <math.h>
int main() {
scanf("%f", &x1);
scanf("%f", &y1);
scanf("%f", &x2);
scanf("%f", &y2);
gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
printf("\n");
return 0;
Sample Output:
Input x1: 25
Input y1: 15
Input x2: 35
Input y2: 10
Distance between the said points: 11.1803
AIM: Verify the linear convolution operation Using DSK Code composer studio
EQUIPMENTS:
THEORY:
In this equation, x(k), h(n-k) and y(n) represent the input to and output from the system at time n.
Here we could see that one of the input is shifted in time by a value every time it is multiplied with
the other input signal. Linear Convolution is quite often used as a method of implementing filters
of various types.
PROGRAM:
PROCEDURE:
Open Code Composer Studio; make sure the DSP kit is turned on.
Start a new project using „Project-new „pull down menu, save it in a separate directory
Load the program (linearconv.out) in program memory of DSP chip using the „File-
load program‟ pull down menu.
Debug-> Run
To View output graphically Select view ->graph ->time and frequency.
AIM: Verify the circular convolution operation using DSK code composer studio
EQUIPMENTS:
THEORY:
Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is folded
and right shifted before the convolution sum is found. Also note that circular convolution could
also be found by taking the DFT of the two input signals and finding the product of the two
frequency domain signals. The Inverse DFT of the product would give the output of the signal in
the time domain which is the circular convolution output. The two input signals could have been of
varying sample lengths. But we take the DFT of higher point, which ever signals levels to. For e.g.
If one of the signals is of length 256 and the other spans 51 samples, then we could only take 256
point DFT. So the output of IDFT would be containing 256 samples instead of 306 samples, which
follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two inputs.
Thus the output which should have been 306 samples long is fitted into 256 samples. The 256
points end up being a distorted version of the correct signal. This process is called circular
convolution.
Open Code Composer Studio, make sure the DSP kit is turned on.
Start a new project using „Project-new „ pull down menu, save it in a separate
directory(D:11951A0xxx) with name circular convolution.
Write the program and save it as circularconv.c
Add the source files circularconv.c to the project using „Project->add files to project‟ pull down
menu.
Add the linker command file hello.cmd.
Load the program (circularconv.out) in program memory of DSP chip using the„File-load program‟
pull down menu.
Debug-> Run
To View output graphically Select view ->graph ->time and frequency.
AIM: Verify the convolution operation Using DSK Code composer studio
EQUIPMENTS:
THEORY:
In this program the Discrete Fourier Transform (DFT) of a sequence x[n] is generated by
using the formula,
N-1
N represents the sequence length and it is calculated by using the command „length‟. The
DFT of any sequence is the powerful computational tool for performing frequency analysis
of discrete-time signals.
PROGRAM:
#include
<stdio.h>
#include
<math.h> int
N,k,n,i;
pi=3.1416,sumre=0,sumim=0,out_real[8]={0.0},out_imag[8]={0.0}
main(void)
scanf("%d",&N);
scanf("%d",&x[i]);
for(k=0;k<N;k++)
sumre=0;
sumim=0;
for(n=0;n<N
;n++)
sumre=sumre+x[n]*cos(2*pi*k*
n/N); sumim=sumim-
x[n]*sin(2*pi*k*n/N);
out_real[k]=sum
re;
out_imag[k]=su
printf("x[%d]=\t%f\t+\t%fi\n",k,out_real[k],out_ima
g[k]);
PROCEDURE:
Open code composer studio, make sure the dsp kit is turned on.
(path: c:ccstudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)
Load the program (dft.out) in program memory of dsp chip using the„file-load
program‟ pull down menu.
Debug-> run
To view output graphically select view ->graph ->time and frequency.
enter the
sequence 1234
Sheet (Normal)
AIM: To design and implement filters in C to enhance the features of given input sequence/signal
EQUIPMENTS:
PROCEDURE:
#include "iirfiltercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
const signed int filter_coeff [ ] = {15241,15241,15241,32761,10161,7877};
//IIR_BUTERWORTH_LP FILTER pass band range 0-8kHz
DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001}
;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 3); while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(const signed int * h, signed int x1)
{
static signed int x[6] = {0,0,0,0,0,0};
static signed int y[6] = {0,0,0,0,0,0};
RESULT:
f) C6713 DSK