Many of the low- to mid-range PICs have little or no internal debugging capability. Some (with no internal support) have low cost debug headers
available from Microchip that replace the target device
during development. Others have internal support along
with re-writable program memory to support the ICD3
debug executive. In either case, these PIC devices
generally have one hardware and one software breakpoint
(BP). The hardware BP is always used by the ICD3
executive, leaving one measly BP for your debugging.
Once one BP is set in your code, you have
single-stepping control only, and you lose the ability to step into
or over functions/procedures/calls, etc. This means that
navigating your code in a controlled manner while
observing internal registers, values, and/or I/O behavior
can be quite a challenge! It’s infuriating to single-step
through some problem code only to step into a function
call that throws all your monitored values out-of-scope.
You can’t easily get back, and there is likely many cycles
ahead before the function returns.
Certainly you can run a simulator like MPSIM and get
quite detailed debugging control, but if your system
interfaces with the real world, you are going to have to
simulate real world peripherals and timing events that can
be hard to develop and operate. You can also use
oscilloscopes and logic analyzers, but to do so you must
have access to the event you are studying.
Enhancing Your Debugger
Oftentimes, the purpose of a debug BP is to stop the
processor to examine the internal and external machine
state in hopes of understanding where a bug is hiding. You
then step around your code observing system behavior.
When you can’t do this due to resource limitations or
event timing, you can often get what you want by leaking
it out on an unused pin or on a used pin between I/O
operations.
Think of this technique as a probe that can poke
around inside the processor at a time and place of your
choosing. Of course, this technique will not magically add
breakpoint control to your debugger, but it will allow you
access to internal state and register values on-the-fly to
augment the limited BP features.
The Logic Analyzer
There was a time when a logic analyzer cost
thousands of dollars and was as big as a suitcase. With the
advent of low cost field-programmable gate arrays (FPGAs)
that has all changed.
There are many USB connected eight- and 16-bit
I
work with a broad spectrum
of low- and mid-range PIC
microcontrollers using
MPLAB/X and a Microchip
ICD2/3 debugger/
programmer as shown in
Manchester debugging
technique can be implemented
in any language, but I will start
with C for its structural clarity.
Enhance Your
Debugging Tool Suite
with Embedded Manchester Serial Output
By Kevin J. O’Connor
32 March 2018