Page 228 - Mechatronics with Experiments
P. 228

214   MECHATRONICS
                                   MPLAB > Debugger > Program to download the application program to the
                              PIC microcontroller.
                              The debugging commands for non-real-time software debugger (MPLAB SIM) and hard-
                              ware debugger MPLC ICD3 are largely the same. Typical debugging commands to find
                              errors in the program are similar to debugging commands for other high level programming
                              languages. Typically we need to be able to

                                1. Run, Halt, Continue the program execution.
                                2. Single step, Step into the function, Step over functions.
                                3. Setup “Breakpoints” at various lines in the program. When the program reaches
                                   that line, the program execution will halt. To setup a “Breakpoint”, open the source
                                   file, place the cursor on the desired line, right-click on the line, and then select “Set
                                   Breakpoint” from the menu. A red icon should appear on that line to indicate that
                                   this is a breakpoint line. When the program execution reaches this line, the program
                                   will halt before executing this line.
                                4. Setup a “Watch window” to view the values of selected variables and registers, that is
                                   when the program stops at a breakpoint, values of various variables can be examined
                                   to check for errors.
                                   MPLAB IDE > Wiew > Watch
                                5. Give the run command to the PIC chip from the PC. Debug the code on the PIC chip
                                   with software and hardware debugging tools (i.e., MPLAB ICD3). When debug-
                                   ging a program, disable the watchdog timer (WDT). The watchdog timer can be
                                   enabled/disabled from the IDE menus. Otherwise, while the program is paused for
                                   debugging, the WDT will reset the processor.


                       4.2 BASIC COMPUTER MODEL


                              Let us consider the operation of a basic computer using a human analogy (Figure 4.3).
                              As shown in the Figure 4.3, the human has a brain to process information, eyes to read,
                              hands to reach various components, and fingers to write. There is also a clock. On the desk,
                              there is a deck of cards which has the instructions to follow, a chalk, an eraser, a black
                              board, input–output trays, and two pockets with one card each for quick access to read/write
                              things on.
                                   The analogy between this human model and a computer is as follows:


                              brain                      --- CPU
                              wall clock                 --- clock
                              deck of instruction cards --- read only memory (ROM)
                              chalk-eraser-black-board   --- random access memory (RAM)
                              pocket cards               --- accumulators (also called registers)
                              input-output tray          --- I/O devices
                              eyes, hands and arms       --- bus to access resources (read/write)


                              There are seven basic components of a computer:
                                1. The CPU which is the brain of the computer. The CPU is made of a collection of
                                   arithmetic/logic units and registers. For instance, every CPU has
                                   (a) a program counter (PC) register which holds the address of the next instruction
                                      to be fetched from the memory,
   223   224   225   226   227   228   229   230   231   232   233