lunes, 3 de octubre de 2011

CAMSHIFT OBJECT TRACKING ALGORITHM IMPLEMENTATION ON DM6437 EVM

CAMSHIFT OBJECT TRACKING ALGORITHM IMPLEMENTATION ON DM6437 EVM
Anton Varfolomieiev1, Oleksandr Antonyuk, Oleksandr Lysenko2
National Technical University of Ukraine “Kyiv Polytechnic Institute”
Faculty of Electronics, Department of Design of Electronic Digital Equipment
37, Peremogy Prospect, 03056, Kyiv, Ukraine
phone: (003 044) 4549538, 4549363; E-mail: 1 7is7@ukr.net, 2 o.lysenko@kpi.ua



ABSTRACT

An approach to creation of an automatic tracking system on the evaluation module, type DM6437 EVM, is considered.

As a core of the system the camshift algorithm was chosen. The model of the algorithm was implemented in Matlab Simulink and ported to the evaluation module. The work contains description of some peculiarities related to porting of the algorithm’s model to DM6437 EVM board. The pictures included show behavior of the system working with actual video sequences. Comparison of the optimized and non-optimized versions of the program from the viewpoint of operation speed is also performed.

1. INTRODUCTION

Automatic object tracking is a digital image processing method, which consists in finding and tracking various moving objects through successive frames of the video sequence [1]. This function of computer vision is widely used in computer-human interfaces, robotics, medical applications, surveillance, etc. [1, 2]. Of particular interest is realization of automatic tracking systems on embedded

platforms. The work described below represents one of such implementations.

Creation of automatic tracking systems on embedded platforms includes two problems: selection of appropriate platform and of the corresponding tracking algorithm able to provide acceptable reliability and speed. For our applied problem we used a digital signal processor (DSP) oriented to video image processing. Particularly, we took the DSP, type TMS320DM6437, used as a basis for

the debugging means called Spectrum Digital DM6437 EVM – in accordance with the task to be solved.

Most of recently developed tracking algorithms use the following principles: correlation methods, optical flow, background subtraction, particle filtering, methods based on probability density evaluation, etc. The correlation and optical flow methods are distinguished with their high computational complexity making them hardly suitable for real-time applications [3]. The background subtraction has low robustness in the presence of noise, and cannot work when the observation camera is moving. The particle filtering is a trade-off of reliability and operation speed (its implementation on DSP platform was described in [4]). In our design, we use an approach based on the probability density estimation algorithm known as camshift. This simple technique has low computational cost and can perform in real-time mode on DSP. Camshift has sufficient reliability, is able to track non-rigid objects when the camera is moving, shows low sensitivity to noise and occlusions.

The considered below DSP implementation may be particularly useful as the part of surveillance system, which allows holding the object of interest within the camera coverage. It also can be used as additional perceptual user interface in multimedia devices based on some OMAP platforms, permitting calculations to be performed on embedded DSP core.

The next sections of this paper describe the camshaft algorithm, its model implementation on Matlab Simulink and peculiarities related to the model porting to DM6437 EVM board. Experimental results contain the examples of the tracking performed by the algorithm on DM6437 EVM.

2. CAMSHIFT ALGORITHM

The camshift algorithm was developed for effective faceand-head tracking in perceptual user interfaces. Its main part represents a robust non-parametric technique for climbing density gradients permitting to find the peak of probability density. In the literature, this approach is called the mean-shift algorithm [5].

The original camshift algorithm uses one-dimensional histogram as a captured object model. The histogram consists of the hue (H) channel in HSV colour space. The object search is being conducted through finding the probability distribution maximum obtained from a so-called histogram back-projection procedure. In order to reduce the amount of calculations, the colour probability distribution is scanned not over the whole image. Instead, we restrict ourselves with calculating the distribution in a smaller image region surrounding the current search window.

The camshift algorithm reduces to the following sequence of steps [5]:

1) Set the calculation region of the probability distribution equal to the whole frame.

2) Choose the initial location of the two-dimensional mean shift search window.

3) Calculate the colour probability distribution in the 2D region centred on the search window location in an area slightly larger than the mean shift window size.

4) Perform the search of the maximum density probability using the mean shift parameter for convergence or for setting the number of iterations. Store the zero moment (area or size) and middle position.

5) For the next video frame, place the search window in the middle position fixed in step 4, and set the window size in conformity to the last moment. Go to step 3. As mentioned above, on step 2 the probability distribution is calculated by the back-projection procedure. This lowlevel operation puts the pixel values in the image into correspondence with the values of target’s histogram bins.

For discrete 2D image probability distributions, the mean location (the centroid) within the search window (steps 3 and 4) can be determined as follows:


where I(x, y) is the value of discrete probability distribution at a point (x, y) on the back-projected image; values x and y change within a search window; M00 – zero moment; M01 and M10 – first moments; (xc, yc) – mean location of a search window (centroid). Calculation of mean location is performed iteratively until a minimum shift of one pixel in either of xc and yc values will be achieved. The maximum number of iterations is usually taken to be 10-20 [6]. The scale and shape of the distribution (object’s scale and shape) are calculated using the equations [5, 6]



The first two eigenvalues (major length and width) of the probability distribution (corresponding to our object) captured by camshift can be calculated in closed form through central moments:




The minor and major semi-axes w and l of the distribution centroid can be determined from the following equations:



The object orientation (major axis inclination) can be found by the formula:


If the target histogram contains a significant number of features that belong to a background image or some adjacent objects, target position and scale can hardly be determined accurately. To cope with this problem, a simple technique was employed: we decreased the weights of target’s histogram bins belonging simultaneously to the background histogram. In other words, we used the ratio

between target’s histogram bins and the respective background histogram bins (the background corresponds to images outside the initial search window) – the so-called histogram weighing. Having simplified denotations adopted in [7], the histogram weighing can be written as:


where qr is the weighed histogram (ratio histogram); qo is the target histogram; and qb is the background histogram. More detailed description of the camshift and mean-shift algorithms for object tracking is contained in [5-7].

3. SOFTWARE IMPLEMENTATION

To simplify realization of the above algorithm on DM6437 EVM, we used Matlab Simulink environment. Such an approach allows for debugging the algorithm on a generalpurpose computer, and then porting it to the desired platform. The Simulink model, which realizes camshaft algorithm, is presented in Fig. 1-a. Its input parameters represent the frame in YCbCr colour space format and initial position of the object to be tracked. The object’s representation (its histogram) extracted from the designated location of the first frame in the video sequence.

The Features Extraction unit, shown in Fig. 1-b, is responsible for selection of proper features from the input frame. Since Simulink does not contain the procedure of direct colour conversion from YCbCr to HSV space, it is realized as an embedded Matlab function. The colour space conversion is performed through the intermediate RGB colour system. The function’s output is only the Hue component. After that, HistExtraction procedure calculates two histograms: the first one is the object histogram (OH) while the second – histogram of the image outside the object’s rectangle (FH). The signals Hue, OH and FH will be transferred to other units.




Figure 1 – Simulink model of camshift algorithm: algorithm subsystem (a); features extraction subsystem (b); object searching subsystem (c); DSP/BIOS function which realizes camshift object tracking on DM6437EVM (d).


Figure 2 – Example of object tracking by camshift on DM6437 EVM (all the images were captured from output of the evaluation module): face tracking (a-e); tracking of the object with non-uniform colour distribution (f-i).


The Features Selection unit is responsible for histogramweighting procedure according to Eq. (2). In fact, this procedure actually makes simple element-by-element division of the OH signal by FH in the event when the enable signal is nonzero (meaning that the histogram weighting is off).

The weighed histogram and Hue signal from the Features Extraction unit come to the input of the Object Searching unit (Fig. 1-c)). The latter includes two procedures: BackProjection and MeanShift. The first one, with the aid of weighed histogram and Hue image, forms the probability distribution function (PDF), while the second, based on this PDF and formulas (1), calculates coordinates of the object position. At the same time, in conformity with camshaft algorithm, we take account of the object position obtained at the previous frame, by introducing Unit Delay 2. At this stage we do not perform the target scaling.

After debugging the algorithm, it can be ported to the DM6437 EVM evaluation module. To do this, Simulink includes Target Support Package. An example of model compilation, suitable for application in DM6437 EVM, is contained in Matlab help. To make it more clear, Fig. 1-d illustrates the DSP/BIOS Task function.

The main peculiar feature of the algorithm realization on this particular board is the signal format. The video decoder generates the signal in sparse 4:2:2 form. To avoid problems with further processing, transformation into 4:4:4 format is highly desirable. The procedure feasible by adding Chroma Resampling unit included in Simulink. This unit has to be placed in front of camshift Algorithm

Subsystem. Video and Image Processing Blockset. One can be plugged before camshift Algorithm Subsystem. By some considerations, we did not put Chroma Resampling unit in our project we performed transformation manually, directly in ycbcr2hsv_H255 function. In other words, we carried out subsumpling of lines and columns of the initial frame resulting in reducing it by half, particularly, from 720x576 to 360x288 pixels in PAL standard. It permits to reduce the amount further of computations performed by the at least by a factor of four.

Since TMS320DM6437 is an integer-type processor, execution of the algorithm can be accelerated by using the integer and fixed point arithmetic where possible. Moreover, the C code generated by Matlab is far from optimal. This stems from numerous checks for integer overflow, and usage of floating point operations not supported by the processor hardware. For this reason, the algorithm performance can be appreciably improved by C code optimization. In addition, calculation of histograms may be carried out on a special-purpose peripheral module [8]. This issue may become an item for further investigations.

In order to make the system well-controlled, i.e. to render the user an opportunity for turning the tracking on and off, or set the position and size of objects at any time instant, it is desirable to modify the C code and to introduce the control means into GEL files in Code Composer Studio environment.

4. EXPERIMENTAL RESULTS

In our experiments, a PAL video camera was used. To avoid performance slips in the process of algorithm execution, automatic white balance in the video camera was switched off. The camera was adjusted so that image brightness was neither too dim nor saturated.

Figure 2 gives examples of tracking performed by the designed system. Sequence (a-e) corresponds to tracking of a human head. As we can see, the designed system performs robust tracking in case of head rotation. Sequence (f-i) shows tracking of an object with non-uniform colour distribution. In the left-top corner of each frame in sequence (f-i) we can see images produced in the course of back-projection operation. The brightness of the minor frames permits to estimate probabilities for this frame.

The time needed for frame processing by the optimized and non-optimized code is shown in Fig. 3. Time measurements were performed with the aid of CLK_gethtime() procedure available in DSP/BIOS.


Figure 3 – Frame processing time attainable by the optimized and non-optimized programs.

As we can see, the average time of frame processing by the non-optimized algorithm is 750 ms while for the optimized one it is about 125 ms. Thus, manual optimization makes it possible to raise the speed of the code generated in Matlab at least by a factor of 6.

It turned out in the course of tests, that the most timeconsuming was the procedure of conversion of colour systems from YCbCr to HSV. Its optimization makes it possible to raise to maximum degree the promptness of the designed system. The procedure of mean-shift, on the contrary, almost has no effect on the operation speed.

It should be noted that the algorithm “looses” the object if its shift during the interval between frames exceeds the size of the search window. Because of peculiarities of the Hue colour component, the system may exhibit instability when tracking objects of certain shades, grey in particular.

5. CONCLUSION

Realization of the camshift tracking algorithm on the Spectrum Digital DM6437 EVM evaluation module is suggested and tested. The designed system is able to track easily various colour objects, even in the case of changing their size and shape. The method holds its stability when the camera is moving, and shows low sensitivity to noise and occlusions.

The use of Matlab Simulink makes it possible to simplify the design and debugging of the tracking system, but the program generated in the C language by the medium turns out to be far from optimal. Its optimization “by hand” permits to increase the performance of the system six times.

After thorough trials of the algorithm, new ways to its improvement became clear. Particularly, scale adaptation would give much benefit. Also, the further C code optimization may give a considerable gain in speed. All this forms a basis for future investigation.

REFERENCES

[1] C. Yang, R. Duraiswami, A. Elgammal and L. Davis, “Real-Time Kernel-Based Tracking in Joint Feature-Spatial Spaces,” Technical Report CS-TR-4567, UMIACS, College Park, 2003.

[2] F. Porikli, “Achieving Real-Time Object Detection and Tracking Under Extreme Conditions,” in Journal of Real-Time Image Processing, Springer, vol. 1, no. 1, pp. 33–40, June 2006.

[3] E. Roichman, Y. Solomon, Y. Moshe, “Real-Time Pedestrian Detection and Tracking” in Proc. of the 3rd European DSP Education and Research Symposium (EDERS 2008), Tel-Aviv, pp. 281-288, June 2008.

[4] H. Fu, Z. Cao and X. Cao, “Embedded omni-vision navigator based on multi-object tracking,” in Machine Vision and Applications, http://www.springerlink.com/content/f58l7674x024x722.

[5] G. Bradski “Computer Vision Face Tracking For Use in a Perceptual User Interface,” in Intel Technology Journal, pp. 1–15, Q2. 1998.

[6] J. Allen, R. Xu, J. Jin, “Object Tracking Using Camshift Algorithm and Multiple Quantized,” in VIP '05: Proceedings of the Pan-Sydney area workshop on Visual information processing, pp. 3–7, 2004.

[7] D. Comaniciu, V. Ramesh, P. Meer, “Kernel-Based Object Tracking” in IEEE Trans. Pattern Anal. Machine Intell., vol. 25, no. 5, pp. 564–575, 2003.

[8] Texas Instruments, "TMS320DM6437 Digital Media Processor (Rev. D),"http://focus.ti.com.cn/cn/lit/ds/symlink/tms320dm6437.pdf

sábado, 1 de octubre de 2011

Creating a Project MSP430

pag 2-37

Laboratory 1: “Hello World” Beginner’s project
The following laboratories provide an overview of the features of CCE.

Lab1.1 – Introduction to the application debug
Project files
 C source files: Chapter 2 > Lab1_CCE > Lab1a.c
Overview
This laboratory shows how to use the basic features of CCE to allow applications to be built and debugged. All the steps needed to create a project, including its configuration, as described above, are illustrated using an example. The application is downloaded to the device after the project has been successfully compiled and built. Several debugging techniques are used, such as: step-by-step execution, analysis of the contents of local and global variables, resetting the device, etc.
Step 1: Creation of the project
A project is to be developed that sends a set of numbers corresponding to the Fibonacci series to the CCE console. The Fibonacci series can be recursively defined by the expression:This sequence was originally used by Leonardo of Pisa (also known as Fibonacci, circa 1200 A.D.) to describe the growth of a rabbit population. With this formula, the sequence of Fibonacci numbers can be determined and answer to the question "how many rabbits were born in the sixth month?", in which the correct answer is, "in the sixth month 8 rabbits were born."

The algorithm that solves this problem is simple to develop. Beginning with the first two values of the sequence, the remaining values are successively calculated.

The sequence of actions to build the project is described below.

A. Creating the project
 Create a new project in Project > New Managed C/ASM Project;
 In project name write Project1;
 Accept the default settings in Select a type of project;
 There should not be any dependency on other existing projects;
 In Device Selection Page, choose in the option Device Variant, the device MSP430FG4618;
 Automatically, the CCE will select the appropriate debug file (lnk_msp430fg4618.cmd) and the support library (rts430x.lib);
 Complete the creation of the project by clicking the button finish.

B. Add a source code file
 The project created is visible in the C/C++ Projects window using the C/C++ perspective;
 Add a file to the project where the source code will be written, by selecting File > New > Source File;
 The file created should be named Lab1a.c;  Write the code below that solves the problem:

//*************************************************************************
// Basic debug introduction using CCE. Application conditional execution
//*************************************************************************
#include
#include
//*************************************************************************

// Global data
//*************************************************************************

unsigned int a, b, i;
//*************************************************************************

// Main routine
//*************************************************************************
void main (void)
{
// Stop watch dog
WDTCTL = WDTPW + WDTHOLD; // Stop WDT


// Global data initialization
a = 0;

b = 1;
// First message to CIO
printf("Lab 1 - Introduction to Debug with CCE V3\n");

printf("Fibonacci sequence computation\n");
printf("Number n = 0 - %d\n", a);
printf("Number n = 1 - %d\n", b);
for(i = 0; i < 7; i++){

int c;
c = a + b;

a = b;
b = c;
printf("Number n = %d - %d\n", i, c);

}
}



//*************************************************************************
// Basic debug introduction using CCE. Application conditional execution
//*************************************************************************
#include
#include
//*************************************************************************
// Global data
//*************************************************************************
unsigned int a, b, i;
//*************************************************************************
// Main routine
//*************************************************************************
void main (void)
{
// Stop watch dog
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// Global data initialization
a = 0;
b = 1;
// First message to CIO
printf("Lab 1 - Introduction to Debug with CCE V3\n");
printf("Fibonacci sequence computation\n");
printf("Number n = 0 - %d\n", a);
printf("Number n = 1 - %d\n", b);
for(i = 0; i < 7; i++){
int c;
c = a + b;
a = b;
b = c;
printf("Number n = %d - %d\n", i, c);
}
}

 The code starts with a descriptive header of the contents of the file and other essential aspects, such as: author, date and version. Other contents may be added;


 Next, the file msp430xG46xx.h is included. It contains the definitions necessary for programming the device;

 The global variables a, b are defined as unsigned integer, and are used to store the Fibonacci numbers of order N and N-1, respectively. These variables are initialized with the values {0, 1},
respectively;

 The control variable i is used to control the number of iterations used in the sequence
calculation;

 The first message is sent to the console using the instruction printf;

 The message consists of a sequence of text lines, so it uses the escape character \n, causing a
change of line in the console;

 Within the code structure, the numbers of the Fibonacci sequence are calculated successively
using the above mathematical expression;

 Finally, the code ends with the directive _NOP(), corresponding t
o the execution of an operation, which has no effect other than to take execution time.


Step 2. Configuration

The project must be configured after writing the code.

 Go to Project > Properties and select the field MSP430 Linker 3.0 Runtime Environment in the option C/C++ Build;


 At this location, define the size of the stack using the directive Specify heap Size for C/C++ dynamic memory allocation (--heap_size) with the value 400 and in set C system stack size (--stack_size) with the value 200;

 Since the printf library function is used, the type of implementation in use
must be specified;

 In MSP430 Compiler V3.0 on the option Library Function Assumption choose to full;

 Finally, confirm in the Run Time Model Options if the silicon version (--silicon_version) is defined as mspx, because the application runs on an extended memory device.


In the TI Debug Settings field, specify the connection type between the PC and hardware:

 Choose the link TI MSP430 USB1;

 At Debugger tab confirm the selection of options Connect to exact CPU and load
Program in loading options;

 At Target tab ensure through Program load options that the use of the IO console CIO is active in Enable CIO Function Use and that the program written to the device is verified using Perform Verification During Program Load;

 Ensure that in Auto run options, the program begins to run in the main routine. Select the two options On the Load or Restart Program and On reset.


Step 3. Compilation

Once the configuration has been set up, the project must be compiled through the option
Project > Build Active Project.


Step 4. Project debug

To debug the code it is necessary to download it to the device through the function Run > Debug Active Project.

The CCE will automatically switch to the Debug perspective;


The following sequence of tasks will allow verification of the operation of the application, while utilizing the CCE features for code debugging.

A. Observe the contents of variables and expressions

 In the Variables window press the
icon and mark the global variables a, b, and i to highlight them;

The contents of these variables can be monitored immediately;


 As the program has not yet begun to run, the values not yet valid;

 In the Expressions window, add an expression that the debug will automatically calculate through the debugging process. For example, using the context menu option
, the global variables addresses can be monitored through the expressions &a, &b and &i;

 Request the number of Fibonacci numbers remaining to calculate using the expression 7-i.



 B. Run the code step-by-step


 Execute the application step-by-step;

 By pressing the key F6, the first instruction is executed;

The program’s status indicator will indicate the next instruction to be executed and will stop the watchdog timer;

 Note that after the execution of the lines that changes the values of variables a and b, the Variables window displays the new values.

 Observe messages being sent to the CIO console;

 Display the CIO console pressing the icon
, choosing Console 3;

 To ensure that it remains visible, press the icon ;

Later, as the application runs step-by-step (F6), the messages will appear in the CIO console:


Lab 1 - Introduction to Debug with CCE V3 Fibonacci sequence computation Number n = 0 - 0 Number n = 1 - 1
 At the end of this sequence of instructions, the variables should have the following values of a = 0, b = 1.

 C. Run the application until a specific code line

Put the cursor on line of code 48, corresponding to:
printf("Number n = %d - %d\n", i, c)

 Select the command Run to line execution, to lead the program execution status indicator to that line;

 The sequence of instructions that led up to this point has been executed, modifying the program variables.


The local variable c was automatically added to the Variables window.


 D. Restart the debugging task

 Once the application has finished running, or whenever it is desired to repeat the code debug, it is possible to restart the device;

 Choose the reset CPU option in Run > Reset;


 Note that the memory of the processor remains unchanged;

 Re-run the application. Place the cursor at the code line 36 and order it to run the program until the cursor position;

Using the Variables window, change the contents of variables a and b to 3 and 4, respectively;


 Execute the application until line of code 52; Observe the new sequence of values for the Fibonacci numbers.


E. Include the project in the workspace

 The project built during this laboratory can be found in code folder Lab1. To include it in the workspace, choose the project through Project > Open Existing Project;

 Perform this laboratory starting at point B.


Lab1.2 – Using breakpoint to save and load data to and from file

Project files

 C source files: Chapter 2 > Lab1_CCE > Lab1a.c
Overview
The debugging of an application can benefit from the ability to exchange information with files on disk. This laboratory will exploit this capability using the project developed in Lab1. Now, the two initial values required to determine the sequence of Fibonacci numbers are collected from a data file. The numbers are successively calculated and are also stored in a data file.

Step 1. Include the project in the workspace

This task is identical to that carried out Step E of Lab 1.1. Compile the laboratory with the file Lab1a.c.

Step 2. Creating input and output data files

The code debugger can access binary files in COFF (Common Object File Format) format or files in text format. The latter format is used in this laboratory. This file has a header line followed by several lines with one value per line. The data can be stored in the following formats: Hexadecimal, integer, long, float. The information contained in the header line has the following syntax:

MagicNumber Format InitialAddress PageNumber Length

where:

MagicNumber: constant value equal to 1651;

Format: Value between 1 and 4, indicating the format used in file samples;

InitialAddress: Address of the start of the data block;

PageNumber: Page number from which the data block was cobtained;

Length: Number of samples in the block.


All the numbers represented in the header are in hexadecimal format.


 A. Create the data files
 The CCE can create this file through File > New > File;

 Include the name DataIn_a.txt on file dialog box to create the file containing the data to be allocated to the variable a:

1651 1 135c 0 2 2

 Repeat the process for the data file of variable b:

1651 1 135c 0 2 3

 Note that CCE expects that the values read are represented using 5 values, each with 4 digits. If the data values are represented in hexadecimal, then CCE expects the first digit to be zero.

B. Associate the input data files to the project

 The project built during this laboratory can be found in the code folder Lab1 and can be added to the project using two different procedures:

o Copy the file to the project directory: This solution has the disadvantage of copying the file to the directory of the project. It loses any freedom to control the file contents if it is used in several projects because there can be multiple sources of that file;

o Link the file to the project: This option allows the file to be stored in an appropriate location and connect it with the project without copying it to the project directory. The same file can be used on different projects, and a change to its content will be observed by all projects that use it.

In this example, the files are copied into the project directory.



Step 3. Add breakpoints to the application and associate them with files


The easiest way to set a breakpoint is through the Breakpoint window. This window allows the choice of action, including the reading or writing data on file. Choosing one of these actions allows the linking of a file to the breakpoint.


 A. Activate the Breakpoint window

 If the breakpoint window is not already open, do so in Window > Show View > Breakpoints.


 B. Create Breakpoints

 Create two breakpoints, one at line of code 36 and another at line of code 37;

 Click on the line of code and add the breakpoint using the left mouse button, in order to provide access to the C editor content menu;

 In this menu choose the option Toggle Breakpoint.

C. Setting the Breakpoint

 In Breakpoint window, after selecting the line of code 28 breakpoint, edit its properties;

 Choose the option Action and open the list of options to choose Read Data from File.



 D. Filling the Breakpoint options

 It is required to fill out the following fields:

o File: location and file name from where the data will be read;
o
Wrap around: mark this selection to start reading at the beginning of the file once it reaches the end;

o
Start Address: Location to send the data read from the file. This address can be changed, since it is always re-evaluated at the beginning of each read;

o
Length: The length of memory. This parameter can also be modified by the debug process.


 To set the Breakpoint associated with the line of code 36, configure:

o File: DataIn_a.txt o Wrap around: Yes o Start Address: &a
o Length: 1
o Name: Breakpoint Load a

 To set the Breakpoint associated with the line of code 37, configure:
o File: DataIn_b.txt
o Wrap around: Yes
o Start Address: &b
o Length: 1
o
Name: Breakpoint Load b


 For the file used to write the values of variable c (Fibonacci series of numbers), create a breakpoint to associate the file to line of code 48;

 Follow the same steps for setting the previous breakpoint, edit its properties and choose Write Date to File in the option Action;

 The data values to configure are:
o File: DataOut_c.txt
o Format: Hex
o Start Address: &b
o Length: 1
o Name: Breakpoint Write c

 Finally, add a breakpoint at line 52 named Final Point, to suspend the execution of the application at the end of the calculation of the Fibonacci numbers.

Step 4. Save file and load files with the breakpoint information

The breakpoints created in this laboratory can be written and read. This feature is useful in order to reuse the breakpoint configuration.


 A. Export the breakpoints to file

 After creating and setting up the breakpoints, as described in the previous steps, the breakpoint information can be saved by exporting it to a file;

 Go to File > Export;

 In the General item choose the option Breakpoints;

 All breakpoints defined in debugger will be present. Select them all;

 Specify the file name to make, name it Lab1_breakpoint.bkpt.


B. Import breakpoints from the file

 To import the breakpoint use the Import feature;

Indicate the file name and select the two options to automatically create and update the breakpoint imported.

Step 5. Code debugging:
The data file exchange operation can be verified during the debug process. To debug the code, perform the following tasks:

 Verify that the execution state indicator points to line of code 27. If this does not happen, order a restart of the device;

 Verify that the CIO console is clean and visible. If these conditions are not fulfilled, using the context menu, order its cleaning and activate the icon to turn the console to always visible;

 Execute the application step-by-step until the variables a and b are initialized. Verify that in the Variables window that they take the values 0 and 1, respectively;

 When the code line 36 is pointed to (before being executed), the variable a takes the value 2, read from the respective data file. The same thing will happen when it reaches code line 29, since when it is pointed to, it leads to the execution of breakpoint Load B, resulting in reading the value 3 for the variable b;

 The Fibonacci number calculation process, using these initial conditions, is initiated within the computing cycle. Whenever the code line is reached, the breakpoint Save c runs. Successive data values are stored in the data file associated with the breakpoint. Order the execution of the application using the command run .The execution takes place until the breakpoint Final Point is reached. In this execution state, the application already determined and stored all the Fibonacci numbers in the file;

 Switching to the C/C++ perspective, in the C/C++ Projects window, it is now possible to see that the data file DataOut_c has been created. Edit this file to see the results. Note that the calculation process returned the sequence: 2, 3, 5, 8, 13, 21, 34, 55, 89.

pag 2-47