Silicon ChipPICn’Mix - May 2021 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Techno Talk by Mark Nelson
  9. Feature: Net Work by Alan Winstanley
  10. Project: 7-Band Mono or Stereo Equaliser by John Clarke
  11. Project: Touchscreen car altimeter by Peter Bennett
  12. Project: DIY Solder ReFLow Oven with PID Control by Phil Prosser
  13. Feature: Max’s Cool Beans by Max the Magnificent
  14. Feature: Make it with Micromite by Phil Boyce
  15. Feature: PICn’Mix by Mike Hibbett
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Circuit Surgery by Ian Bell
  18. Feature: Practically Speaking by Jake Rothman
  19. PCB Order Form
  20. Advertising Index: Max’s Cool Beans cunning coding tips and tricks

This is only a preview of the May 2021 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
PIC n’Mix Mike Hibbett’s column for PIC project enlightenment and related topics Part 5: PIC18F Development Board I n the previous article of this series (March 2021) we covered the PCB design and assembly of our PIC18F development board. We ran some initial ‘smoke tests’ to see whether revision 1 of the PCB was fit for purpose – and it was… more or less! A few minor issues were found during initial testing, and a couple more in the weeks that followed during initial use of the board. Some of the resulting changes are to minimise component count (isolating the copper underneath IC1, to avoid needing a TO220 insulation shim when screwing the regulator down) and the addition of solder pads for two previously unused op amps. We had also missed a few useful silkscreen labels, which were easily added. The low-value capacitors had been placed with a package footprint intended for a 0.1-inch pitch radial part, but to increase the flexibility for using the alternative 0.2-inch pitch packages, we have changed the PCB footprint to a ‘combo’ package, that provides an extra pad at the alternate spacing. It’s surprisingly difficult to find 12pF capacitors (used by the low-frequency real-time clock oscillator) in a 0.1-inch pitch these days. We do miss Maplin! PCB revision The final PCB layout can be seen in Fig.1. The schematic has been updated slightly to re-order some of the header labels, but the addition of the two previously unused op amps had already been captured in the schematic published in the previous article (drawings being quicker to update than physical PCBs. The other changes discussed are PCB related rather than schematic.) Fig.2 shows the parts of the schematic that have changed – we will reprint the full schematic in the next article just in case there are any further changes as we prepare the PCB for manufacturer. The bare PCB will be available to order when the next article in this series is published in the July issue. So, you have plenty of time to order components. The parts list is shown in Table 1. Notice how this has been split into ‘Essential’, those components required for basic operation, ‘Recommended’, and ‘Optional’. The optional components are ones that will be used in some future article, or your own designs. Sourcing components can be a challenge these days with the demise of high street vendors like Radio Shack or Maplin, and delivery charges from the likes of Farnell or RS Components can be excessive for the low-cost of the parts you will be ordering. Do check our own component suppliers advertising in the magazine, and also consider eBay and even Amazon – it can be surprising where components or PCB assemblies pop up. In particular, we make use of many 0.1-inch pitch header pin strips. These can be purchased cheaply on eBay, and also Amazon. While the bulk of the items can be ordered through Digikey, it can be worth looking for the same manufacturer parts through other suppliers, such as RS Components or Farnell. Do watch out for delivery fees – it may be worth buying several sets of components or other items to avail yourself of free delivery for orders above purchase cost thresholds. Generally useful things Besides the components listed in Table 1, there are some items that you will find useful to have at hand. De-soldering braid, to help with cleaning up solder shorts. Also, hook-up wires, in all three styles (male-female, female-female, male-male.) These are very cheap on eBay and it’s well worth buying lots of these, as they are cheap and seem to disappear quickly in our lab. Isopropyl alcohol (from a chemist,) cotton buds and a toothbrush are useful for cleaning soldering flux from boards – which not only makes your board look nicer, but also will help you spot any soldering splashes or dry joints. The PCB will be available for purchase, along with details for ordering in the next PIC n’Mix article. This month, while we wait for PCBs to arrive, we will proceed with the software setup. Setting up the IDE Fig.1. Final PCB component layout, revision 2 of the design. 50 As many of you will be aware, Microchip produce their own integrated development environment for developing Practical Electronics | May | 2021 Table 1: PIC18F Development Board components and suppliers. Circuit ref No Description Supplier Part number 1 Essential 2 PCB 1 Bare PCB PE pic18f-dev-pcb C2,C5,C6,C7,C11 5 0.1µF ceramic, 0.1-inch pitch Digikey BC1148CT-ND 1 C1,C4 2 10µF Tant, 0.2-inch pitch Digikey 478-7368-1-ND 2 C8,C9 2 12pf ceramic, 0.1-inch pitch Digikey BC1002CT-ND C3,C10 2 1µF ceramic, 0.1-inch pitch Digikey 445-173261-1-ND R1,R5,R6,R9,R14 5 240Ω 1/4W Digikey 240QBK-ND R2 1 390Ω 1/4W Digikey CF14JT390RCT-ND R3 1 330Ω 1/4W Digikey CF14JT330RCT-ND R4,R10,R11 3 4.7kΩ 1/4W Digikey A105934CT-ND R7,R8 2 1MΩ 1/4W Digikey CF18JT1M00CT-ND R12,R13 2 220kΩ Trimpot Digikey 1993-1085-ND D1,D2,D3 3 1N4001 Digikey 1N4001RLGOSCT-ND X1 1 32.768kHz, 12pF loading Digikey 2151-R26-32.768-12.5-ND LED1 1 Green 5mm LED Digikey C503B-GCN-CY0C0792CT-ND 2 3 1 2 3 H D R 3 2 1 2 2 2 2 3 3 3 H D R 3 1 Digikey C503B-RAN-CZ0C0AA2CT-ND TN2106N3-G-ND H D R 3 5 IC1 1 LM317T TO220 regulator Digikey 497-1575-5-ND 1 PIC18F47K42-I/P-ND 1 H D R 3 4 MCP2221A DIL14 Digikey MCP2221A-I/P-ND MCP604P DIL14 Digikey MCP604-I/P-ND JP1 HDRs 1 0.1-inch header jumper Digikey 609-6251-ND 1 7 way 0.1-inch socket header Digikey SAM1209-07-ND 1 4 way 0.1-inch socket header Digikey SAM1209-04-ND 1 5 way 0.1-inch socket header Digikey SAM1209-05-ND 1 2×4 0.1-inch socket header Digikey SAM1204-04-ND 3 0.1-inch header strip, 40 long eBay eg, eBay 192345923109 1 DC barrel jack Digikey 3185-FC681465-ND 1 40-pin DIL socket Digikey 2057-ICM-640-1-GT-HT-ND 2 14-pin DIL socket Digikey ED3014-ND 4 Adhesive rubber feet Digikey 2042-1007-ND 3 1 Digikey 1 2 3 1 Red 5mm LED 1 1 2 1 2N2106 FET IC3 1 H D R 2 4 1 IC4 3 H D R 2 5 H D R 2 3 H D R 2 6 IC 4 b 1 M C P 6 0 4 P 5 + 2 7 3 6 – H D R 2 7 H D R 2 8 1 2 Digikey 2 1 IC 4 a M C P 6 0 4 P H D R 2 2 3 LED2 PIC18F47K42-I/P 4 – 2 TR1,TR2 1 1 + 3 3 IC2 Op am p subsystem H D R 2 1 H D R 3 6 1 1 H D R 3 0 1 0 + 9 – 1 2 + 1 3 – 3 H D R 2 9 IC 4 c M C P 6 0 4 P 1 8 H D R 3 3 IC 4 d M C P 6 0 4 P 1 1 4 1 1 H D R 3 8 H D R 3 7 G nd Recommended CON1 P ower supply S Y S T E M _ V IN OU T A D J IC 1 L M 3 1 7 Optional Wi-Fi module 1 Wi-Fi module various eg, http://bit.ly/pe-may21-ESP8266 USB connector 1 USB connector Pololu www.pololu.com/product/2586 SD-Media socket 1 SD-Media socket Pololu www.pololu.com/product/2597 software using their processors. This is not the only tool available, and a completely open-source compiler is available, called SDCC. We’ve stuck with Microchip tools over the years (25 and counting) and found them reliable and continuously in development. The tools we will use are free of charge – you can pay a large sum for the professional version of the compiler, but unless you are a commercial developer you are missing nothing using the free tools. The paidfor version has additional optimisations available (resulting in slightly smaller programs, and slightly faster run time) but you will not notice the difference. The PIC18F47K42 has more than enough Practical Electronics | May | 2021 code space for our needs, and at 64MHz clock speed it is more than fast enough to run our programs. There is one downside to the software tools being updated frequently – you may find yourself following these instructions when a newer version of the tools have been released, and you may find the step-by-step instructions are not quite right for the newer version. To help avoid this, we are providing instructions for installing the latest tools, as of March 2021. We recommend that you install the same version of the software tools, which will still be available for download from the Microchip site even if they have updated the version. Also, as the C 2 1 0 0 nF J P 1 *** R 1 0Ω R 2 3 0Ω 1 2 R 3 330Ω G N D Fig.2. Revised sections of the PIC18F Development Board’s schematic – changes from the March 2021 version marked in red. PIC18F47K42 is a mature processor, it is unlikely that a new version of software will introduces any essential features for our processor. You can, of course, update to a new version at a later date. To minimise the likelihood of unexpected software installation issues, we are starting with a completely fresh 51 are programming a device with a program supplied by someone else. XC-8 This is the C compiler. It takes the source files for the program you have written and converts them into a format that can be executed directly by the processor (machine code.) XC-8 has to be downloaded and installed independently of MPLABX, but once installed, MPLAB-X will find it and use it automatically. MCC Microchip Code Composer Fig.3. IDE Installation – device support options. installation of Microsoft Windows 10. These instructions should be fine for earlier releases of the Windows operating system, if you have not yet caught up. (You should do though, as earlier versions of Windows have Internet security weaknesses – but that’s the subject of a different article!) Software and hardware tools The tools are available for use under Linux and Apple Mac OSX, but we will focus on the Windows installation, as this will be the most widely used. Let’s start by reviewing what we will be installing. MPLAB-X This is actually two programs – MPLABX IDE is the source code editor and debugger, really a framework that binds file management, editing, building and debugging in one handy application. When developing projects, this is where you will spend most of your time. MPLAB-X IPE is a stand-alone programmer, a simpler application used to download pre-created programs to a processor. This is useful when programming a batch of devices, or when you Fig.4. MPLAB X start-up screen. 52 This is a plug-in to MPLAB-X that provides a simple user-interface, assisted by a graphical selection tool, for automatically generating source code files for configuring the peripherals of the processor to your specific requirements. This does not remove the need to have an understanding of the processor, but it does remove a significant amount of experimentation, and saves a lot of typing. Besides being able to write code for all of the peripherals on the processor, it also contains a number of extremely useful ‘higher level’ functions that build on top of these peripherals – such as a bootloader, SD-media interface and disk file systems. MCC is installed within MPLAB-X rather than being directly downloaded. It’s a tool that takes some getting used to but is very much worth the effort of acquiring familiarity – we will make extensive use of it. PICkit 4 This final item is hardware rather than software. To program or debug a PIC microcontroller, we need a special interface, which connects to the PC with a supplied USB cable. At around £56 it is not cheap, but it is future proof and will support all your PIC programming needs. The older PICkit 3 also supports the PIC18F47K42 processor and can be found more cheaply, but we recommend the PICkit 4. The instructions for use are identical between the two interfaces. There is also the low-cost MPLAB Snap, a simple PCB that supports PICs, but this has not been tested with our PIC of choice. Microchip do have two other software tools, but we can ignore these. MLA (Microchip Library for Applications) is a now obsolete software package, and Harmony, a software library for PIC32 processors only. Installation So, let’s get started. We will first download MPLAB-X IDE from Microchip’s website. Navigate to http://bit.ly/pe-may21-mcide and scroll down to the downloads section at the bottom of the page and click in the ‘download’ label to the right of the MPLABX-vx.yz-windows-installer.exe line. At the time of writing, the version number is 5.45. If the current version is later than that, you can find the v5.45 installer under the ‘Archives are located here.’ link. The file is 1.1GB in size, so make sure you have space on your drive, and a fast Internet connection. Once downloaded, double-click on the file to start installation. Click ‘Accept’ and ‘Next’ when prompted to accept all defaults until you reach the ‘Select Applications’ window, as shown in Fig.3. We would recommend un-selecting 16bit, 32-bit and ‘Other MCU’ support, to save disk space – but go ahead and leave them selected if you anticipate working with other devices later on. Clicking ‘Next’, then ‘Next’ again will start the installation process. Continue installation by accepting ‘Install’ where prompted, finalised by ‘finish’, which will result in a number of web pages opening in your browser. You can close these. Navigate to: http://bit.ly/pe-may21-mcxc and scroll down halfway to the ‘Downloads’ section. Click on the ‘MPLAB XC8 Complier v2.32’ (or whatever is the latest version) link to start the download. It does not matter if this is a more recent version. Click on the file to start the program and accept all default options to perform the installation. When prompted to complete the licensing information, just click next, to select the free option, followed by ‘Finish’. You can now double click on the ‘MPLAB X IDE’ icon on your desktop to start the application. On first start-up you may see a warning from your security software that MPLAB is trying to access the Internet – click OK to this; MPLAB ‘dials home’ to check for updates, and this is a good thing, from a reputable organisation like Microchip. Now, you Practical Electronics | May | 2021 Click ‘Finish’ to complete the installation, which requires a restart of the PC. Using MPLAB-X IDE Fig.5. Initial project setup. are greeted with the start-up screen, as shown in Fig.4. At this point we are ready to start developing programs. We are however missing one final tool, MCC, which will make our lives a lot simpler. We can install this through MPLAB-x IDE, so let’s go ahead and do that now. On the main menu bar, click on ‘Tools’, followed by ‘Plugins’. Click on ‘Available Plugins’, then scroll down if needed and click to enable ‘MPLAB Code Configurator’. Now click ‘Install’. Click ‘Next’, ‘Agree’ Followed by ‘Install’. Following a reboot, MPLAB-X IDE will restart, giving you a start-up screen similar to Fig.4. We assume many of you will be familiar with MPLAB-X (but don’t worry if that’s not the case, we will be bringing everyone on this journey,) but expect that the MCC tool will be new. Let’s take a quick look at what it provides by building a simple test program. First, we plug the PICkit 4 device to the PC, so it will be detected by MPLAB-X. From the main menu of MLPAB-X we click ‘File’ followed by ‘New Project...’. In the dialogue that pops up, click on ‘Standalone Project’, followed by ‘Next’. Whenever you are creating a new project, this is always the appropriate option to choose. In the ‘Device:’ field of the following dialogue box, scroll down or type in PIC18F47K42. Then under the ‘Tool’ drop-down, select PICkit 4. You have the option to pick the simulator, which if you are following along at home without hardware would be a good choice. Then, click ‘Next’. In the next dialogue we get to choose which compiler we want MPLAB-X to use. The XC8 compiler we just downloaded should appear in the list, so click on that and then ‘Next’. If you wanted to write your application in assembly language, you could have selected that instead. However, we will be focusing on using the ‘C’ programming language in our examples. We now get to give our project a name and specify where the files will be place. Type in gpios for the project name, leave the other options as they are and click ‘Finish’. At this stage we have created the project, as can be seen in the left-hand dialogues, as shown in Fig.5. The top window shows the files, and the lower the project configuration. At this point, no source files exist. From here, we would normally create a main.c file and start writing software, but let’s see how MCC helps us. First though, here are the requirements for our simple project. Turn on the green LED, which is connected to digital pin RE2. Set an alternating high-low pattern on the pins of HDR16 (the LCD interface header.) With that in mind, click on the blue MCC icon in the top menu bar. On first launch you will be prompted to store the MCC configuration file – just click save, the default name and location are acceptable. Then, MPLAB-X reconfigures itself to show MCC’s graphical user interface, as shown in Fig.6. Notice the long list of entries under ‘Device Resources’ – the MCC tool understands all of the peripherals on our microcontroller, and can generate code for them. This is a large departure from classical source code editors, but it highlights the Fig.6. MCC configuration view. Practical Electronics | May | 2021 53 Fig.7. Output pins defined. value of an IDE – although we are about to click on graphical images and click on icons, the results end up as text-based source files that we can edit and add our own additional requirements later on. We can switch between the two code editing methods too. For now, however, we will continue in the MCC tool and implement our (somewhat contrived) program requirements without typing a single line of code. The details that follow work with and without hardware (using the simulator in that case) so feel free to follow along at home. Conveniently, on start-up the GUI displays the key dialogue – The ‘System Module’ page, where we get to define the chip’s start-up behaviour. These Fig.8. GPIO pin configurations. selections get programmed into the processor’s configuration bits and define how the processor configures itself before your software starts running. Click on the ‘Oscillator Select’ field and select HFINTOSC, the high frequency internal oscillator – we have chosen to not use an external high frequency crystal oscillator. Then under ‘HF Internal Clock’ we chose ‘16_MHz’, as this is not exactly a high-speed program. Pins and things From here we can move down to the ‘Pin Manager: Grid View’ in the lower dialogue. Here we can single click each of the GPIO pins, in the ‘output’ row, to assign our desired pins to be configured as outputs. As you click, the icon changes from unlocked to locked. You can see the result in Fig.7. Having defined the pins we need as being outputs, click on the ‘Pin Manager’ tab at the top of the MPLAB-X window. The pins you have selected as used by your application appear here, with their configuration settings, as shown in Fig.8. This is where things get interesting. Configuring PIC processor GPIO pins has always been a pain, especially with some being analogue by default, requiring additional code to reverse that. Here, you have a clear table. Let’s go ahead and modify this table. We have already defined the pin settings to be output, so all we need to do is set the pins we want to high level as ticks in the ‘Start High’ column, and turn off ‘Analog’ in all cases. The final result is shown in Fig.9. Although this looks a bit odd, it should result in the green LED being turned on, and an alternating high/low pattern on HDR 16. To convert this set of graphical settings into code, we have to click on the ‘Generate’ button on the tab list of the ‘Project Resources’ dialogue on the left. Once finished, the generator has created our main source file and the ‘driver’ files required to implement our requirements. We don’t need to edit code at this stage; we just click the run icon on the main menu list. With the PICkit 4 plugged in and power applied, the LED lit and the header pins had the expected voltages. With that running we have confirmed our development environment installation is complete, and we are now ready to start our first real project! Coming up Fig.9. GPIO pins, configured. 54 With the development board supporting an LCD, SD-Media Card, PC interface, servo drivers and a Wi-Fi interface the range of projects that could be supported by this board is enormous. If you have an interesting idea that you would like to see tackled in an article, drop us an email (pe<at>electronpublishing.com) via the editor – you could see your idea in print! In our next article, we will fire up the LCD and SD-Media interfaces and test out data exchange between the development Practical Electronics | May | 2021