
Theory of Operation
©
2009 Microchip Technology Inc.
DS51795A-page 21
2.6.1
Sequence of Operations Leading to Debugging
Given that the requirements for debugging (see previous section) are met, these
actions can be performed when the PICkit 3 programmer/debugger is set as the current
debugger from the MPLAB IDE menu (
Debugger>Select Tool>PICkit 3
):
• The application code is compiled/assembled by selecting
Project>Build
Configuration>Debug
.
• When
Debugger>Program
is selected, the application code is programmed into
the device’s memory via the ICSP protocol as described above.
• A small “debug executive” program is loaded into the high area of program
memory of the target device automatically by MPLAB IDE. Since the debug
executive must reside in program memory, the application program must not use
this reserved space. Some devices have special memory areas dedicated to the
debug executive. Check your device data sheet for details.
• Special “in-circuit debug” registers in the target device are enabled. These allow
the debug executive to be activated by the debugger.
• The target device is held in reset by keeping the V
PP
/MCLR line low.
2.6.2
Debugging Details
Figure 2-7 illustrates the PICkit 3 programmer/debugger system when it is ready for
debugging.
FIGURE 2-7:
PICkit™ 3 DEBUGGER READY FOR DEBUGGING
Typically, in order to find out if an application program will run correctly, a breakpoint is
set early in the program code. When a breakpoint is set from the user interface of
MPLAB IDE, the address of the breakpoint is stored in the special internal debug
registers of the target device. Commands on PGC and PGD communicate directly to
these registers to set the breakpoint address.
Next, the
Debugger>Run
function or the Run icon (forward arrow) is usually pressed
from MPLAB IDE. The debugger will then tell the debug executive to run. The target
will start from the reset vector and execute until the Program Counter reaches the
breakpoint address previously stored in the internal debug registers.
After the instruction at the breakpoint address is executed, the in-circuit debug
mechanism of the target device “fires” and transfers the device’s Program Counter to
the debug executive (much like an interrupt) and the user’s application is effectively
+5V
+12V
4.7 k
Ω
4.7 k
Ω
Internal Circuits
Program
Memory
File
Registers
Internal
Debug
Registers
V
PP
/MCLR
PGC
PGD
1
5
4
Executive
Debug
Area Used by
Target
be
Running
must
for Debug
Executive
to Function
Area
V
DD
Hardware
Stack Shared
by Debug Exec
Debug Exec
Reserved
for Debug
Executive