Using the Watches Window to Access Global Variables and Registers (SFRs)
Contents
- What is the Watches Window
- Opening the Watches Window
- Adding Items to the Watches Window
- Modifying the Display Properties
- Saving and Importing Watch Lists
- Watches In Local Variables View
- Viewing Array Segment
- Viewing an Element in a Structure
- Collecting Specific Watches in Groups Using Alternate Watch Views
- Learn More
What is the Watches Window
The Watches window is the MPLAB® X Integrated Development Environment (IDE) utility that allows you to observe and modify Global Variables and Special Function Registers (SFRs). The Watches window is part of the standard MPLAB X IDE debug tools and is available during a debug session.
The Watches window operates with all MPLAB development ecosystem supported debug tools, the MPLAB X Simulator and most third-party debug tools.
Opening the Watches Window
Make sure you are in a debug session.
Select Windows > Debugging > Watches (or ATL + SHIFT +2)
The Watches window will open up in the Output window section. (Usually the lower right-hand side.)
Any value left in the Watches window from a previous debug session will remain in the Watches window when it is reopened. This avoids the necessity of reloading. To erase the Watches from a previous session, right-click in the Watches window, then select Delete All.
Adding Items to the Watches Window
To add an element to the list of items being watched, first right-click in the open Watches window, then select New Watch from the drop-down menu.
A pop-up menu will display and allow you to select either a Global Variable or an SFR to add to the Watch. Select the either SFR or Global Symbol. Once selected, the box will fill with a list of all the Global Symbols or SFRs. Select the individual item you wish to add, then select OK.
Repeat these steps until you have added all the desired Watches.
Modifying the Display Properties
Right-click on the menu bar of the Watches window to bring up the Display Visible Options window. This will allow you to add and remove display columns. You can change the width of each column or sort the table by the elements in each.
Left-click on either the Type or Name heading to sort the entries.
Saving and Importing Watch Lists
You have the option to save the current list of items in the Watches window to a file. You can also reload the list of watches from a saved file. Two icons on the left-hand side of the Watches window control these functions.
Watches In Local Variables View
The Blue Jewel icon allows you to merge the Watches and Variables windows together in one. When you do this, the Watches Window is removed from the tabs in the Output Window to avoid redundancy. This feature is often useful when you want to see both together, but probably not the best to leave enabled for performance. This is because the watch has to read the data for all variables and not just the local ones. Select the icon again and the watches will return to their own tab.
Application
In addition to local variables, access to Global Variables and PIC® Special Function Registers (SFRs) is commonly needed during a debug session. The Variables Window has the capability of displaying watches ( i.e. Global Variables and SFRs) in addition to local variables. Accessing watches in the Variables Window is accomplished using the two lower control icons. The center icon controls whether or not to show watches in the Variables Window. When watches are enabled, the lowest control icon becomes active and you can click on it to enter a new watch into the Variables Window.
The image below shows a screenshot of an SFR being displayed in the Variables Window.
Local variables will be displayed next to a green rhombus while watches will be displayed using a diamond icon .
Viewing Array Segment
You can separate an array to be able to watch just a segment of data. If you have a large buffer, you can focus on just a few elements by providing the direct indexes of what you want to view, for example: [200:202].
Application
In order to use the Watches Window, MPLAB® X must be in operating in a debug session
Open the Watches Window (Alt + Shift + 2).
Right click anywhere on the Watches Window and select New Watch.
Select the name of the array you are interested in. Next to the name of the array enter the open bracket symbol "[", followed by the closing bracket "]". Inside the brackets, type in the starting and ending indexes of the array elements you want to view, separating them with a colon. Lastly, click OK.
You should now see the selected elements in the Watches window.
Viewing an Element in a Structure
You can select an element within a deep structure and create a fixed watch out of it. This will bring this element out to the top level. It prevents you from having to look in a long list of data to find the variable you want to focus on.
Application
Scroll up/down to find the watch you are interested in.
Right-click on it and then select Create As Fixed Watch.
Once you have added a fixed watch, a top-level watch for this specific element will be immediately created.
Collecting Specific Watches in Groups Using Alternate Watch Views
The Watches Window has alternate watch list views which work similarly to having tabbed watches. With alternate views, you can collect specific watches in groups and when you click on a watch view diamond, only the variables associated with that view will be displayed. Select that diamond again and it will default to the standard view. This feature works like a filter.
You enable this feature by going to Tools > Options > Embedded > Generic Settings. The default is to have one watch window.
Application
- Click on one of the numbered diamonds to select it.
- Double click on the <Enter new watch> message.
- Type in the name of the watch you are interested in and press Enter.
- Alternatively, you can right-click inside the Watches Window, select New Watch, scroll down to select the desired watch and click OK.
- If you want to add more than one watch, enter the second one in the second row and so on.