This is only a preview of the November 2023 issue of Silicon Chip.
You can view 47 of the 112 pages in the full issue, including the advertisments.
Articles in this series:
Items relevant to "Pico Audio Analyser":
Articles in this series:
Items relevant to "K-Type Thermostat":
Items relevant to "Modem/Router Watchdog":
Items relevant to "1kW+ Class-D Amplifier, Pt2":
Items relevant to "Recreating Sputnik-1, Part 1":
Purchase a printed copy of this issue for $12.50.
Microchip PICkit 5 and MPLAB X v6.10/.15 We frequently work with Microchip microcontrollers, so we were keen to try the new PICkit 5. Microchip Technology kindly sent us a sample. This was also our introduction to the latest version of their free MPLAB X software, which has several new features. Review by Tim Blythman S ince we primarily use Microchip’s PIC microcontrollers for our projects, we’re keen to stay up-to-date with the latest hardware and tools for programming and debugging them. The PICkit range is intended as a low-cost tool for evaluation and development. It stretches back to the original PICkit 1 from 2003. They offer other devices, such as the ICD 5, which are more capable and provide more features, such as device emulation. In 2016, Microchip Technology purchased Atmel Corporation, best known for their 8-bit AVR microcontrollers and 32-bit ARM chips. In 2018, they released the PICkit 4, which introduced support for the chips previously made by Atmel. Earlier PICkits had a six-pin programming header; the PICkit 4 introduced an 8-pin header to handle a broader range of chips and programming protocols. The PICkit 5 is a direct update to the PICkit 4 and keeps the same 8-pin socket. MPLAB X IDE is the software we use most to develop firmware for PIC microcontrollers. With an appropriate compiler installed, it allows you to write programs in C or assembly language. Version 6.10 is the first version to support the PICkit 5 (until recently, we were using v6.00). Version 6.15 was released while we were writing this article. Later, we’ll discuss the MPLAB X IDE, focusing on new features introduced over the last few years. “IDE” stands for integrated development environment and describes software with the necessary tools for writing, testing and deploying software. The MPLAB X IDE includes (among many other features) a text editor, compiler integration, a debugger and a programmer interface. When we reviewed the PICkit 4 in the September 2018 issue (siliconchip.au/ Article/11237), we found it substantially faster than its To program recent Microchip microcontrollers, you’ll need a PICkit 4, Snap or PICkit 5. They all contain a SAM E70 processor, but only the PICkit 5 has Bluetooth and the ability to connect to the MPLAB PTG app. The yellow wire on the Snap is a modification we described on page 69 of the June 2021 issue. 62 Silicon Chip Australia's electronics magazine predecessor, especially for in-circuit debugging. That article also explains what in-circuit debugging involves. For more background on MPLAB X, see our introductory guide in the January 2021 issue (siliconchip.au/ Article/14707). That article also covered setting up and using MPLAB X, specifically version 5.40. In case you aren’t familiar, we’ve provided a Glossary at the end of the article, explaining some of the terms that are in this article. The PICkit 5 The PICkit 5 comes in a black plastic enclosure of about 85 × 43 × 13mm. Most of the front is covered by a brushed aluminium panel with the Microchip and MPLAB PICkit 5 logos. Protruding about 5mm is an eightpin header socket at one end and a USB-C socket at the other. The back has a microSD card slot. Included in the box with the PICkit 5 is a USB-A to USB-C cable, about a metre long, plus a sheet of PICkit 5 stickers. A small hole near the USB socket provides access to an emergency recovery button. On an adjacent corner is a hole for a lanyard to be attached. The PICkit 5 is almost identical in appearance to the PICkit 4. Apart from the front panel label, the only external difference is the change in the USB socket to USB-C. This is a welcome but not unexpected upgrade. So much equipment seems to wear out or break at the USB connector; the more robust USB-C socket will hopefully avoid that and also provides commonality with most modern smartphones and tablets. The other big difference is that the PICkit 5 incorporates a Bluetooth 5.0 module. The intent is for the PICkit 5 to siliconchip.com.au Fig.1: although it might look like a simple device, you can see that there are quite a few parts needed for the PICkit 5 to do all that it does. communicate with a smartphone running the MPLAB PTG (Programmer- to-go) app. The Programmer-to-go feature has been available since the PICkit 3 and allows a firmware image to be programmed into a device without needing a full computer. The user guide indicates that the PICkit 5 supports PIC and AVR microcontrollers, dsPIC digital signal controllers and SAM and CEC (Arm Cortex) microcontrollers and microprocessors. A full device support list (including other Microchip programmers) can be found at siliconchip.au/ link/abpl Checking that list, we see that the PICkit 5 supports much the same range of parts as the PICkit 4. The PICkit 5 supports interfaces such as Microchip’s own ICSP, JTAG (Joint Test Action Group), SWD (Serial Wire Debug) and various AVR protocols like UPDI, PDI, ISP and TPI. It can also provide a virtual USB serial port (known as the “data stream interface” in the user guide). Hardware Ever curious, we opened up the case for the PICkit 5 to see what is ‘under the bonnet’. It sports a 300MHz SAM siliconchip.com.au E70 processor along with numerous peripheral components to generate the variety of programming voltages that are needed and interface with various targets. You can see the internals in the photos overleaf. Our review of the PICkit 4 also included photos of the PCB, and it’s clear that the resemblance doesn’t end with the enclosure. Indeed, the PICkit 5’s internals look very similar. Most components are in the same place in both programmers, except where they needed to be moved to accommodate the USB-C socket and Bluetooth module. Fig.1 shows the block diagram of the PICkit 5. The Snap programmer (reviewed in the March 2019 issue; siliconchip. au/Article/11628) also bears a SAM E70 processor but lacks the capability of high-voltage programming (high- voltage here means above 5V and up to 14V) and it can’t supply power to the target processor. Even with the upgrade to a USB-C socket, the PICkit 5 is only capable of USB 2.0 speeds. Still, 480Mbit/s is quick enough for most of its tasks. Since many modern PIC microcontrollers require at least a PICkit 4 or Snap for programming, we expect many readers will already know about Australia's electronics magazine these devices, so we’ll focus on the updated features. As expected, programming and debugging with a PICkit 5 is the same fast and simple experience that PICkit 4 users will be familiar with. App and Bluetooth Being able to program a microcontroller without it being connected to a computer is a handy thing, especially since it gives complete galvanic isolation. The Programmer-to-go (PTG) feature was available with the PICkit 3 and PICkit 4, but the new app makes it easier to use. The app is available for Android and iOS and is called “MPLAB PTG”; a search for this on your respective app store should find it. We used the Android version in our testing. Screens 1-3 show what the app looks like. A PTG image must be loaded onto the PICkit 5 before the app can be used. You will also need a microSD card to hold the image. We’ll discuss this process later when we get into the MPLAB X IDE. Screen 1 shows the results after scanning for devices; the app has detected the PICkit 5. Tapping on the device serial number takes you November 2023 63 to Screen 2. The BROWSE SD button shows a picker (the individual PTG images are actually folders on the microSD card filled with numerous files). Toggling the app’s PTG mode switch causes the PICkit 5’s light to flash green. This indicates that PTG mode is active; the same pattern is seen if PTG mode is activated from a computer. With a PTG image selected, the PROGRAM button takes you to Screen 3, which, in this case, has logged a successful programming effort. The diagnostic message shown when programming fails could be more descriptive; it simply says it failed. Programming from the IDE or IPE will give a much more detailed message, such as whether an incorrect voltage was present, a different chip was detected or even the specific location at which program memory could not be programmed or verified. The PICkit 5 can take power from the target circuit (through the eightway header), and we had no trouble programming a chip in this scenario. The ability to easily select and program different images in the field will be convenient, as will not needing to worry about connecting a separate power supply. We also tried hooking the PICkit 5 up to an Android mobile phone via a USB-C to USB-C cable. In this case, the phone supplied power to the PICkit 5 (and thus the target chip). We even tested serial communications using the ‘Serial USB Terminal’ app on Android and were able to send (typed into the Android phone) and receive data using the PICkit 5’s serial data pins. So, with a suitable mobile device and perhaps other apps, the PICkit 5 becomes a much more useful tool for working in the field. We see great potential for the MPLAB PTG app and Bluetooth connectivity and for many different features to be added in the future. If you don’t have the app, it’s still possible to initiate PTG programming. Like the PICkit 4, it’s done by pressing the logo on the front of the programmer, activating the internal switch, as long as the PICkit has previously been set to PTG mode. MPLAB is Microchip’s development ecosystem that includes an IDE, IPE (integrated programming environment), compilers and a wide range of programming and debugging devices. Several other code tools exist, including MPLAB Harmony and MPLAB Code Configurator. The MPLAB X IDE replaces the older Windows-only MPLAB IDE, which dates back over 20 years. The significant change was that the MPLAB X IDE became available for Mac and Linux operating systems. It’s proprietary software that’s free to download and use, although some compiler optimisation options are only available with a paid license (“PRO”) upgrade. We try to design our projects to require only the free compiler options so that anyone can modify the code, although sometimes that isn’t possible. Note that free evaluation trials are available for the PRO license versions. Also, if you want to try the IDE software without installing it on your computer, there is a cloud-based version at siliconchip.au/link/abpm Apart from the IDE, there have been updates to the compilers (which have their own version numbers) and the device family packs (DFPs). These elements mean that the overall development environment is quite modular. Different versions of the IDE, compilers and DFPs can be installed alongside each other. Screen 1: the PTG app is intuitive to use. After scanning for devices, the specific PICkit 5 can be identified by its serial number and selected. Screen 2: the microSD card can be browsed to select a PTG image. Pressing the PROGRAM button changes to Screen 3. Screen 3: the programming screen provides some simple pass/fail statistics, much like the MPLAB IPE, as well as a status log. 64 Silicon Chip MPLAB ecosystem Australia's electronics magazine siliconchip.com.au MPLAB X IDE will prompt you if there is a version mismatch (eg, the selected DFP is not installed); resolving the problem is as simple as clicking on the link in the prompt to download the correct version. You can check and update DFPs from the Tools → Packs menu item. For example, support for the newer 8-bit PIC parts is available by installing the PIC16F1xxxx pack (see our article in the October 2022 issue; siliconchip. au/Article/15505). If you need older versions of the software (for example, to maintain an old project), there is an archive, see: siliconchip.au/link/abpn Compilers Three different compiler families work with the MPLAB X IDE. XC8 targets 8-bit devices, including PIC10, PIC12, PIC16 and PIC18 parts. With the takeover of Atmel, this also includes many 8-bit AVR devices. XC16 works with 16-bit microcontrollers with PIC24 and dsPIC prefixes. XC32 is a 32-bit compiler for the wide variety of 32-bit processors from the Microchip and Atmel stables. This includes PIC32 (MIPS and ARM) and SAM parts. All compilers include other tools, such as assemblers. Late 2021 saw the release of version 6.00 of the MPLAB X IDE, followed not long after by version 4.00 of the XC32 compiler. This marked the time at which all three compilers were truly C99 compliant and began to share a standard C Library. MPLAB X IDE v6.xx The 6.xx version projects are not backwards compatible with older versions, although there is a tool to convert back to the older version. Our full Windows install of version 6.10 of the MPLAB X IDE, including support for all processor families, comes to around 11GB. The latest versions of the compilers add around 2-3GB each. Version 6.15 is much the same. The XC8 Compiler Options now allow optimisation level 2 to be selected without requiring a PRO license. Previously, only up to optimisation level 1 could be used with the free license. That is excellent news! The PICkit 5 circuit board looks quite similar to the PICkit 4. The main differences are the USB-C socket and the Bluetooth module, just visible under the notch in the main PCB. Note the tactile switch under the light guide, which is activated by pushing on the front of the PICkit 5. Compiler Advisor One new tool since version 6.00 is the Compiler Advisor. According to siliconchip.com.au Fig.2: the PRO Comparison option starts a Compiler Advisor analysis. Note how the Debugging build option is now the default. Australia's electronics magazine November 2023 65 Fig.3: even if you don’t have a PRO license, the Compiler Advisor will allow you to see how it would perform against the free compilation options. This can even be a handy tool for free licence users, as occasionally, the obvious optimisation setting is not necessarily better. Fig.4: the PTG options available on the Setting page of the MPLAB IPE are similar to the PTG app, although there is the option to change the image name from the IPE. The IPE is the best way to manage multiple PTG images. 66 Silicon Chip Australia's electronics magazine the documentation, this can be used with XC8 from version 2.30, XC16 from version 1.26 and XC32 from version 3.01. The Compiler Advisor window can be opened from the Tools → Analysis → Compiler Advisor menu, and it can be run from the Build or Clean and Build dropdown buttons (Fig.2). This option is labelled as (Clean and) Build with PRO Comparison. The project is compiled with several different optimisation settings, and the results (specifically program memory and data memory usage) are shown as a chart, as in Fig.3. The Compiler Advisor takes a bit of time to run, as it effectively runs a build for each available optimisation option (four in our example). You can easily switch to using one of the suggested optimisation configurations by clicking the link on the chart. You don’t need a PRO license to use the Compiler Advisor, although you will get more compilation options displayed if you do. As you can see (at least for this project), the PRO option offers substantial reductions in program memory usage. The release notes for version 6.15 of the IDE mention improved tool stability and using recent releases of the compilers to reduce build (compilation) times. We compared XC8 versions 2.40 and 2.41 and did notice quicker compilation with the newer version. The compilers are now throwing up more warnings, particularly in relation to C language standards. That’s a good thing, as it could pick up code errors that are not obvious. Another subtle difference we noted since versions 6.05 is that the “Build” (and “Clean and Build”) button now defaults (in versions 6.10 and 6.15) to doing a “Build for Debugging”, which you can see when you hover your mouse pointer over it. This can be a problem if you intend to build for production (deployment to a device), as debug builds can misbehave if no debugging tool is connected. Fig.2 shows how this appears in the IDE, with the “Clean and Build for Debugging” as the default at the top. So to do a Clean and Build for production now requires using the dropdown menu to select that specific item. You can also use the F11 and Shift+F11 key combinations. siliconchip.com.au Programmer-to-go Setting up the PICkit 5 to use the Programmer-to-go feature means sending a PTG image to the programmer. From the IDE, a dropdown option on the Program Device button will do that. Alternatively, the IPE has a section on the Settings tab to manage the PTG images. Fig.4 shows that section of the Settings tab and the Browse PTG window that can be opened. The IPE is the best option if you want to view and organise the PTG images and give them specific names. The PTG images are more than just the HEX files; they are folders incorporating all the settings used by the PICkit 5, such as whether the target or the PICkit circuit supplies power (and, if so, what voltage) and the programming speed. PICkit 4 obsolescence With the introduction of the PICkit 5, it appears that the PICkit 4 is being phased out, with Microchip Direct (www.microchipdirect.com) now listing it as “not recommended for new designs”. The PICkit 5 is listed at US$94.99, while the PICkit 4 is not much cheaper at US$88.54. Conclusion The PICkit 5 does everything the PICkit 4 can and more. Bluetooth, the PTG app and the USB-Serial port are all features that we plan to use. We see great potential for wireless communication in a programming and debugging tool. If your PICkit 4 is working well and you don’t need these new features, you probably don’t need to get a PICkit 5 right away. But for those looking at buying a programmer, the PICkit 5 is not much more expensive than the PICkit 4 and looks like it will have support into the future. Look for part number PG164150. As mentioned, you need at least MPLAB X 6.10 to use the PICkit 5. Even if you don’t have a PICkit 5, we don’t see any reason not to upgrade to the latest MPLAB X, although you will have to watch out that the Build buttons have changed their default behaviour. The PICkit 5 is available (at the time of writing) from the following suppliers: Microchip Direct: PG164150 DigiKey: 150-PG164150-ND Mouser: 579-PG164150 SC siliconchip.com.au PICkit 5 – Glossary of Terms Assembler Converts assembly language code (a human-readable low-level language) into binary object code. Compiler Converts code in a high-level language (such as C) into assembly language or object code. The process might be called compiling or building. Debugger A hardware or software tool that can be used to monitor what a program is doing and determine the cause of incorrect operation. Firmware Software that is programmed into persistent storage on an embedded device, typically a microcontroller, usually in the form of binary or hexadecimal code. IDE Integrated Development Environment; software that includes all necessary tools for writing software, compiling it into object code and programming the object code into a target microcontroller. Some also feature a debugger. Interactive debugging The process of interacting with a running microcontroller to see what it is doing and to assist in finding bugs/errors. This can include pausing operation through the use of breakpoints, inspecting variables and registers and stepping slowly through program instructions. The debugger may require specific object code produced by the compiler to work. Microcontroller A chip typically containing a microprocessor, integrated peripherals, memory and sometimes storage. These features allow such a device to operate as a standalone computing device that can directly interface with attached hardware. Basically, a one-chip computer. Object code Code in a machine-readable format that can easily be converted into a memory image for programming into a target device, ready to run. A typical image format is the Intel Hex (.HEX) file format that MPLAB X IDE can generate. Production build Object code that can be used for deployment to a finished product, as distinct from a debugging build, which contains extra information only needed by the debugger. Production code is usually smaller and faster than debug code. Programmer A hardware tool that can be used to transfer a firmware image to a microcontroller. Some programmers (including the PICkit range) are also capable of debugging. Target A microcontroller (and perhaps the circuit it is part of) that will be programmed or debugged. The LED status bar (located just above the logo) adds a slash of colour to the PICkit 5; its intensity can be adjusted. Blue indicates the device is idle, while flashing green means it is in PTG mode. Australia's electronics magazine November 2023 67