Professional Documents
Culture Documents
Microcontroller DEBUGGING
and TESTING tools
Professor Dr Dogan Ibrahim, lecturer at the Near East University of Nicosia
in Cyprus, describes some of the currently available tools for microcontroller
debugging and testing
DESIGNING A microcontroller-based commercially available tools for debugging and Incorrect logic or errors in computations can
system is a complex activity that involves testing microcontroller-based systems. The be analyzed by stepping through the code in
hardware and software interfacing with the factors to consider when choosing a debugging simulation. Simulators run at speeds 100 to
external world and many engineers find it tool are cost, ease of use and the features 1000 times slower than the actual
difficult the first time. offered during the debugging process. microcontroller hardware and, thus, long time
Successful design of a microcontroller-based In this article I will describe the details of one delays should be avoided when simulating a
system requires skills to use the various of the popular low-cost debugging tools, with program.
debugging and testing tools available. A an example showing how an in-circuit debugger Microcontroller-based systems usually have
program may seem to be running but may not can be used in a real design. I’ve used the PIC interfaces to various external devices such as
be effective, or it might give the wrong results microcontroller family as the basis for this motors, I/O ports, timers, A/D converters,
when operated in real-time, so debugging may article. displays, push-buttons, sensors and signal
be the only tool to help eliminate the problems. generators, which are usually difficult to
Tools for debugging and testing Software Simulators simulate. Some advanced simulators, such as
microcontroller-based systems can be divided A software simulator is basically a computer the Proteus from Labcenter Electronics
into two groups: software-only tools and program running on an independent hardware (www.labcenter.co.uk) for example, allow the
software-hardware tools. Software-only tools and it simulates the CPU, the instruction set and simulation of various peripheral devices such as
come in the form of monitors and simulators, the I/O of the target microcontroller. Simulators motors, LCDs, 7-segment displays and
which are independent of the hardware under offer the lowest-cost development tools for keyboards, and users can, in general, create
development. Software-hardware tools are microcontroller-based systems and most new peripheral devices. Inputs to the simulator
usually hardware dependent, are more expensive companies offer their simulator programs free can come from files that may store complex
and range from in-circuit emulators and in-circuit of charge. digital I/O signals and waveforms. Outputs can
simulators to in-circuit debuggers. In general, the Basically, the user program can be operated in be in the form of digital data or waveforms,
higher the level of integration with the target a simulation environment where the user can usually stored in a file, or displayed on a screen.
hardware, the greater the benefit of a tool, insert breakpoints within the code to stop the Some simulators accept only the assembly
resulting in a shorter development time, but the code and then analyze the internal registers and language of the target microcontroller.
greater the cost as well. memory, display and change the values of Most microcontroller software is nowadays
This article describes very briefly some of the program variables and so on. written using a high-level language such as C,
Pascal or Basic, and it has become a necessity to
simulate a program written in a high-level
Figure 1: PICFlash 2 ICD
language. Some simulators – the microC,
developed by mikroElektronika
(www.mikroe.com) – can perform simulation
using high-level languages. Oshon Software
simulators (www.oshonsoft.com) are
powerful low-cost high-level language
simulators enabling the user to set breakpoints
and display and modify registers and program
variables.
Monitors
Monitors are software tools that usually run
on the target microcontroller system. A monitor
program usually resides in the bottom or top
www.electronicsworld.co.uk ❙ 21
DEBUGGERS
target hardware. In-Circuit Simulators are not microcontroller in-circuit debuggers are: ICD- pressed. As such the display shows the count as
very common and are only available for U40 (by CCS Inc., www.ccsinfo.com), 0, 1, 2, 3…9, 0, 1… as the button is pressed.
specific hardware platforms. Because an in- PICFlash 2 (by mikroElektronika) and others. Notice that ICD pins RB6 and RB7 and MCLR of
circuit simulator runs at the speed of the Table 1 gives a comparison of the various the microcontroller are connected to a PICFlash
simulator software, it runs much slower than features of the debugging and testing tools. 2 ICD.
the target microcontroller and, thus, can not In this article, an example is given to show The software in this example is based on the
be used to simulate time critical applications, how an ICD device can be used in a simple mikroC language, a popular C language
such as an USB port or the data transfer from microcontroller-based system development. compiler from mikroElektronika, supporting a
an USART port. Although the operation and use of most ICDs built-in software simulator and the PICFlash 2
are similar, the low-cost PICFlash 2 ICD is used ICD. The program listing is given in Figure 3.
In-Circuit Debuggers in the example below for illustrative purposes. Variable count is incremented every time the
In-circuit debuggers (ICD) are very clever button (PButton) is pressed. Array LED stores the
tools used instead of the more expensive in- PICFlash 2 In-Circuit Debugger bit pattern to be sent to the 7-segment display
circuit emulators. An ICD is a small hardware PICFlash 2 ICD is manufactured by to turn on a digit and this array is indexed by
device connected between a PC and the mikroElektronika as a general purpose ICD variable count.
microcontroller development system (some and, also, for use in their development
development systems have built-in ICD systems. A picture of the PICFlash 2 ICD is In-Circuit Debugging
circuits). shown in Figure 1. The ICD is connected to The debugging steps are given below:
An ICD uses the In-Circuit Serial the USB port of a PC and to the following pins ● Write the program given in Figure 3, making
Programming (ICSP) capability of the target of a PIC microcontroller: sure that the compiler is configured as
microcontroller where two or three pins of the ● RB6 follows:
microcontroller are allocated to the ICSP ● RB7 Device: P16F887
operation. The ICD downloads a small control ● MCLR Clock: 8MHz
program to the target microcontroller’s flash Pins RB6 and RB7 are used for data and Build Type: ICD debug
program memory and then the user can clock and pin MCLR provides the chip Debugger: mikroICD Debugger
develop and debug source code by setting programming voltage. ICD manufacturers ● Compile the program with no errors
breakpoints, watching variables, single- usually provide headers to connect their ● Connect the ICD to the target microcontroller
stepping the program, or running the program devices easily to the target microcontroller. system
in full speed, thus enabling the time critical Commands can be sent to PICFlash 2 from the ● Send the program to the target
routines to be tested in real-time. mikroElektronika language compilers to watch microcontroller by pressing F11 or by
An ICD requires specialized circuitry to be and modify program variables, to set selecting Tools -> PicFlash Programmer
present on a target microcontroller, such as breakpoints and to single-step the program. ● Select the mikroICD debugger. Debugger ->
logic to communicate to the ICD device, logic Select Debugger -> mikroICD Debugger.
to single step program code and logic to halt Example Use of PICFlash 2 ● Start the debugger. Click Run -> Start
and interrogate the target microcontroller. A simple 7-segment display example is given Debugger
Although an ICD can be an invaluable here to illustrate how useful an ICD can be ● Select variables and I/O ports count, PORTD
debugging tool, it has two main during the microcontroller-based system and PORTB from the Watch Window.
disadvantages: it uses some memory of the development cycle. ● The program is now ready for debugging.
target microcontroller and it requires the use a As shown in Figure 2, a 7-segment display is Press F7 to single step through the program.
few pins of the target microcontroller to connected to PORT D of a PIC16F877 type As shown in Figure 4, a blue bar moves
communicate and control the target. microcontroller and a push-button is connected down the program lines to indicate the
MPLAB ICD2 and, lately, the ICD3 are two of to bit 0 of PORT B (RB0). In this example, a statement being executed. You should see
the popular in-circuit debuggers developed by count is incremented and its value sent to the 7- the values of variables changing as the
Microchip. Some other popular PIC segment display whenever the push-button is program is executing in single step mode.
www.electronicsworld.co.uk ❙ 23