Silicon ChipIntro to programming: Cypress' System on a Chip (SoC) - October 2018 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Seemingly helpful technology may not be that helpful
  4. Feature: Reusable Rockets by Dr David Maddison
  5. Project: GPS-synched Frequency Reference Pt.1 by Tim Blythman
  6. Project: Arduino-based programmer for DCC Decoders by Tim Blythman
  7. Project: Low-voltage, high-current DC Motor Speed Controller by Nicholas Vinen
  8. Serviceman's Log: I'm on holidays, but not from servicing! by Dave Thompson
  9. Feature: Developing CleverScope's high-performance CS448 by Bart Schroeder
  10. Project: Opto-Isolated Mains Relay by Tim Blythman
  11. Feature: Intro to programming: Cypress' System on a Chip (SoC) by Dennis Smith
  12. PartShop
  13. Product Showcase
  14. Vintage Radio: Emerson 838 hybrid valve/transistor radio by Ian Batty
  15. Subscriptions
  16. Market Centre
  17. Advertising Index
  18. Notes & Errata: Steam Train Whistle/Diesel Horn / Arduino Data Logger
  19. Outer Back Cover

This is only a preview of the October 2018 issue of Silicon Chip.

You can view 40 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "GPS-synched Frequency Reference Pt.1":
  • GPS-synched Frequency Reference PCB [04107181] (AUD $7.50)
  • PIC32MX170F256B-50I/SP programmed for the GPS-Synched Frequency Reference [0410718A.hex] (Programmed Microcontroller, AUD $15.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • Micromite LCD BackPack V2 complete kit (Component, AUD $70.00)
  • SMD parts for the GPS-Synched Frequency Reference (Component, AUD $80.00)
  • Firmware (HEX) files and BASIC/C source code for the GPS-Synched Frequency Reference [0410718A.hex] (Software, Free)
  • GPS-Synched Frequency Reference PCB pattern (PDF download) [04107181] (Free)
  • GPS-synched Frequency Reference drilling and cutting diagrams (PDF download) (Panel Artwork, Free)
Articles in this series:
  • GPS-synched Frequency Reference Pt.1 (October 2018)
  • GPS-synched Frequency Reference Pt.1 (October 2018)
  • GPS-synched, lab-quality frequency reference (Part 2) (November 2018)
  • GPS-synched, lab-quality frequency reference (Part 2) (November 2018)
Items relevant to "Arduino-based programmer for DCC Decoders":
  • DCC Decoder Programmer PCB [09107181] (AUD $5.00)
  • DCC Decoder Programmer PCB plus stackable headers [09107181] (AUD $7.50)
  • Small 2A boost step-up regulator module (MT3608) (Component, AUD $3.00)
  • DCC Decoder Programmer sketches (Software, Free)
  • DCC Decoder Programmer PCB pattern (PDF download) [09107181] (Free)
Items relevant to "Low-voltage, high-current DC Motor Speed Controller":
  • Four-channel High-current DC Fan and Pump Controller PCB [05108181] (AUD $5.00)
  • PIC16F1459-I/SO programmed for the Four-channel High-current DC Fan & Pump Controller (0510818A.HEX) (Programmed Microcontroller, AUD $10.00)
  • Firmware for the Four-channel High-current DC Fan & Pump Controller (0510818A.HEX) (Software, Free)
  • Four-channel High-current DC Fan and Pump Controller PCB pattern (PDF download) [05108181] (Free)
Articles in this series:
  • Low-voltage, high-current DC Motor Speed Controller (October 2018)
  • Low-voltage, high-current DC Motor Speed Controller (October 2018)
  • Low voltage DC Motor and Pump Controller (Part 2) (December 2018)
  • Low voltage DC Motor and Pump Controller (Part 2) (December 2018)
Items relevant to "Opto-Isolated Mains Relay":
  • Opto-Isolated Relay PCB plus two extension boards [10107181] (AUD $7.50)
  • Opto-Isolated Relay PCB pattern (PDF download) [10107181] (Free)
Items relevant to "Intro to programming: Cypress' System on a Chip (SoC)":
  • Cypress PSoC4 CY8CKIT demonstration project files (Thermistor/LCD) (Software, Free)
Articles in this series:
  • Intro to programming: Cypress' System on a Chip (SoC) (October 2018)
  • Intro to programming: Cypress' System on a Chip (SoC) (October 2018)
  • Cypress “system on a chip” part 2 (September 2019)
  • Cypress “system on a chip” part 2 (September 2019)

Purchase a printed copy of this issue for $10.00.

Introduction to Programming ˃Cypress’ System on a Chip A Programmable System on a Chip (PSoC) is much more than just a microcontroller. It also contains analog circuitry which can be configured in thousands of different ways, greatly reducing the external components required. Does it sound exotic? Well, you can buy a module with one of these chips for around $6 and be up and programming it within an hour or so! ˃By Dennis Smith T he CY8CKIT-049-42XX Prototyping Kit is one of the best development platforms available at the moment. It can be used with Cypress' Integrated Development Environment (IDE) with “schematic capture” system. This allows you to draw up the circuit configuration that you need, write some software, then compile it all together, using the very components you have just placed on your schematic. The product page for this unit, with a wealth of documentation and downloads, is at siliconchip.com.au/ link/aaku This development board is available in Australia for around $6 (at time of writing) from element14 (2420489) or Radio Spares (RS 124-4190). The IDE, complete with compiler and device specific libraries, is totally free and available for download from the link above. PSoC4 details According to its data sheet: “PSoC 4 is a scalable and reconfigurable platform architecture for a family of mixed-signal programmable embedded system controllers with an ARM Cortex-M0 CPU. It combines programmable and reconfigurable analog and digital blocks with flexible automatic routing.” “The PSoC 4200 product family, based on this platform, is a combination of a microcontroller with digital programmable logic, high performance analog-to-digital conversion, op amps with comparator mode, and standard communication and timing peripherals.” 82 Silicon Chip Its features include: • 32-bit microcontroller • Programmable analog and digital circuitry • Low power 1.71-5.5V operation • Capacitive button sensing • Segmented LCD driver • Serial communication • Integrated timers and pulse-width modulation (PWM) generators • Up to 36 programmable general purpose I/O pins (GPIOs) Included with the PSoC kit is a removable USB-to-serial adaptor. It's visible in the photo of the PCB, at the left-hand end. The PCB plugs straight into a USB port for programming. Once you have finished your project, assuming you don’t need USB communications, this section of the board can be snapped off and used as a general-purpose USB/serial adaptor. This adaptor also has the ability to be used as a USB-to-GPIO device – just one of the many “hidden gems” in this design. Preparing the board To get started, plug the board into a USB port on your PC. An orange LED lights up on the USB/serial adaptor to indicate that power has been applied. You should also see a blue LED flashing on the main section of the board, which indicates that all is well and the program loaded into the board during manufacture is running. Now unplug the board and plug it back in again but this time, hold down the button at the end of the board while you plug it in. Notice how the blue light now flashes at a faster rate. This is because the board is now in bootAustralia’s electronics magazine loader mode. We will use this facility later to load our program onto it. But first, you need to download the IDE (PSoC Creator 4.1, siliconchip. com.au/link/aakv) and device-specific files from the bottom of the main product page above. These additional files are the “USB-Serial Software Development Kit” (www.cypress. com/?docID=47673) and the “CY8CKIT-049-42xx Kit Only (Kit Design Files, Documentation, Examples)” (www. cypress.com/file/135786/download). Note that at the moment, the IDE is only available for Windows PCs (Windows 7, 8, 8.1 and 10). The IDE download is 499MB and the device-specific file is only 15.4MB. When you elect to download these files, the download page will ask if you wish to use the Akamai download manager. I suggest that you bypass the download manager (Cypress provide a link for that) since otherwise, it requires a separate program to be installed on your PC which remains there for future downloads. However, either approach should get you the files that you need. Once downloaded, start the installation by double clicking first on the “PSoCCreatorSetup_4.1_Update1_ b3210.exe” file (the name may change with future updates). Accept the default file installation locations and the license agreement. The IDE and compiler support files, including drivers, will be installed. You may be prompted to install a Microsoft .NET Runtime if this isn't already on your system. Just follow the prompts, as this is required for the IDE to run. siliconchip.com.au You will be asked for some contact details (name, company and e-mail address). You can opt to skip this step by selecting the “Continue Without Contact Information” checkbox. We recommend that at this stage, you check the “Launch Update Manager” option, to ensure you have the latest version of the software. Next, double click on the “USBSerialSDKSetup.exe” to install the USB driver. Finally, double click the “CY8CKIT04942xxSetupOnlyPackage_ revSA.exe” file. Once again, accept the default file installation locations and license. For some bizarre reason, when we downloaded this file it was named “VirtualBox-4.3.14-95030-Win.exe”. VirtualBox is a different piece of software entirely! But when we opened it, it installed the Cypress IDE. This seems to be a quirk of their download mechanism. Our example project We're going to start off with a premade example project which you can get up and running easily. The PSoC IDE has a plethora of other example projects you can easily test (over 500). This example project monitors ambient temperature using an NTC thermistor and displays this temperature on a standard 16x2 alphanumeric LCD. The next step therefore is to download the demonstration project files for this article from the Silicon Chip website. The package is named “PSoC4_ Thermistor Code.zip” and is just over 4MB. Having downloaded this, unzip the contained files to the “PSoC Creator” subdirectory in your Documents folder. You can place them elsewhere if you wish but this is the suggested location. Navigate to the “PSoC4_Thermister.cydsn” folder inside the files you unzipped and double-click on the file named “PsoC4_Thermistor.cyprj”. This will open PSoC Creator 4.1 IDE and load the project files automatically. Alternatively open PSoC Creator 4 from the Start Menu, click “Open Existing Project” on the Start page and navigate to the project folder. You may be asked to create a MyCypress account at this stage but you can click the “Register Later” button to skip it, if you don't want to. The IDE window should then look something like the screen grab shown in Fig.1 below. If the diagram is not shown, double click on the “TopDesign.cysch” item at the top of the left-hand panel. Now you are ready to put the hardware together. Click on the Page 2 tab at the bottom of the diagram, this will display a wiring diagram. We've prepared an easier-to-read version of this diagram and it's shown in Fig.2. We recommend that you solder pin headers along the edges of the PSoC board and then use jumper leads to plug them into a breadboard, where you can arrange the components. Alternatively, you could simply solder the components onto those pads directly but that would make it difficult to re-configure the circuit for other uses. Then the components should be wired up to the PSoC board as shown in Fig.2. Now that you've built the hardware, we need to compile and upload the firmware to the chip for it to do its thing. Using PSoC Creator 4.1 The PSoC Creator workspace has four main areas as shown below: 1 3 2 4 Fig.1: the main view of the PSoC Creator IDE. After building the code, you will receive a confirmation in the output window which shows the total flash and SRAM usage. While the photos show version 4.2, it’s functionally identical to 4.1. siliconchip.com.au Australia’s electronics magazine October 2018  83 Fig.2: circuit diagram for the thermometer example project, with the equivalent IDE view shown in Fig.3. Note that you may want to make the Vdd connection for the thermistor on the opposite side of the board, in case you want to break off the USB section. 1. Files and Resources, at centre. This contains a series of tabs with open files and resources which can be viewed and edited. Fig.1 shows four pages currently open: the Start page, TopDesign.cysch (the schematic diagram), PSoC4_Thermistor.cydwr (the Design Wide Resource) and main.c (where most of our program goes). 2. Component Catalogue, at right. A tree view list of all components currently available, both internal to the board (like ADC, Digital functions, Analog functions etc), and “off-chip” components such as resistors, capacitors etc. To use a component, you drag the one you are interested into the Top Design view. 3. Workspace Explorer, at left. This is a tree view list of all files in the project. Double-click on a file in this list to open it for editing. In our example, only three files need to be edited: Top Design, Design Wide Resource and main.c. 4. Output, at bottom. This panel shows results of compiling the project 84 Silicon Chip such as the compilation time, warnings and errors. Connecting and configuring components We need to tell the IDE which parts of the chip we will be using and how they will interact. This is done by dragging the internal components into the Top Design view and virtually wiring them up. After dragging these components into place, they need to be assigned parameters and connected to other components to form a circuit. To connect them, use the drawing tools to the left side of the Top Design, just to the right of the Workspace Explorer. The “Connect” icon is used to join the components. The other tools are for annotating it to improve clarity. They do not form part of the actual circuit. You will notice that the lines drawn using the Connect tool will change from solid to broken lines (dashes) depending on whether you are connecting internal or external components. Australia’s electronics magazine To change the parameters for a component, you double click on it and this brings up the “Configure Box”. For each component, there is a data sheet accessible through a button in this box. This explains how the component works, how to change it dynamically from your code and what each of the parameters does. Having opened the sample file, we suggest you double-click on some of the components such as the ADC, Thermistor and LCD and read the data sheets to get an idea of what's available. Most of the time you will be using external components with the board, such as a Mosfet to control the brightness of a LED or the speed of a motor. If you want to use the board's internal functions so that they can interact with the outside world, you need to assign a pin (or a full port) to that function. In the supplied example program, you will notice labels such as “Vhi” and “Vlow”. These refer to external siliconchip.com.au Parts List – example project 16x2 alphanumeric LCD 1 10kW NTC thermistor 1 10kW resistor 1 10kW potentiometer Fig.3: schematic diagram for the example project as shown in the IDE. You can view this on page 2 of the TopDesign.cysch file as marked below. ▼ Enlarged view of the circuit layout shown in Fig.1. This example project (a thermometer) displays the current temperature, Vdd and Vbat (Solar) values. siliconchip.com.au Australia’s electronics magazine October 2018  85 In our example, we have three main components: the ADC, AMux (analog multiplexer) which selects which signals are fed to the ADC inputs, and the LCD controller. The code initialises all three of these components as follows: /* Start all the hardware components required */ ADC_Start(); AMux_Start(); LCD_Start(); Fig.4: the pin configuration used in the example project for the PSoC chip. This is viewed in the PSoC4_Thermistor.cydwr file under the pins sub-heading. pins on the chip (a pin being a component from the Cypress Component Catalogue). If you double-click on the “Pins” item in the tree under “Design Wide Resources” (in the Workspace Explorer, at left) you will get a view of the PSoC chip as shown in Fig.4 above. This indicates which I/O pins are available and lets you assign labels to them; double click on a pin to change its properties, including the name. You can also see a list at the right edge which shows the names assigned to each pin or port. The “\ LCD:LCDPort[6:0]\” entry indicates that six pins of port P0, starting at pin 0, are assigned to the 16x2 character LCD. You can check the LCD component data sheet for a description of what each pin does. When you add a pin to your schematic diagram, from the Component Catalog at right, it will be assigned to one of the pins on the package. If you aren't happy with its chosen assignment, you can simply drag it to any other free pin. Double clicking on a pin in the schematic brings up an impressive list of options. It can be made into an analog input, digital input, digital output with eight different drive methods (including open drain or with a resistor in 86 Silicon Chip series with either or both output transistors) or bidirectional. You also can select which system clock is used to determine when the input or output state changes. For outputs, you can have a separate “output enable” line which allows other parts of the system to enable or disable that pin. In fact, there are a lot more options for I/O pins than are available with just about any other type of microcontroller. Combining code with the schematic The aforementioned component data sheets contains not only details of the parameters required for the component but also details of the software commands that can be used to control the component. This is the API (Application Program Interface). You will often find yourself referring to this when writing your own programs. Examine the contents of main.c by clicking on the main.c editor tab at top, or by double clicking “main.c” in the Workspace Explorer window to open it. You will see many API calls in the code. One of the most important is the Component_Start() function. This initializes the component and gets it ready for use. Australia’s electronics magazine For those of you that are used to the Arduino environment, you will notice there is no “setup” or “loop” section. This is because PSoC Creator uses standard ANSI C/C++. All your code will go into the main() function with setup code at the top and repeated code within a for(;;) or while(1) statement block. The rest of the code first clears the LCD screen and then measures the voltage across the thermistor and reference resistor. An API function is called to obtain the temperature by comparing the two aforementioned voltages. A string containing the temperature in degrees Celsius (to two decimal places) is made and printed to the first line of the display. This is followed by measuring and printing the Vbat value on the second line of the display, after which it updates this line with the supply voltage Vdd and keeps alternating between displaying either of the two values with half second delays between each. This process repeats indefinitely. Compiling, linking and uploading the code You need to compile and link the C code before it can be uploaded to the chip. To do this, click on the build icon in the tools bar just above the Workspace Explorer window. If all is well you will see “Build Succeeded...” appear in the Output window, as shown in Fig.1. Plug the board into a USB port on the PC (a USB extension cable comes in handy for this) while holding down the programming button at the rear of the board and make sure the blue light is flashing rapidly indicating that the board is in programming mode. Click on the Tools menu item at the top of the PSoC Creator main window and select “Bootloader Host…”; the window shown in Fig.5 will appear: Click on the drop-down arrow at the right-side of the box and make sure the siliconchip.com.au Fig.5: the programming window which you use to upload your project to the device. Note you will need the bootloader file which is found in your project's directory. Fig.6: the log output in the Bootloader Host window when programming is successful. Fig.7: if programming fails for some reason, an error message will be displayed. In this case, the wrong COM port was selected. siliconchip.com.au Australia’s electronics magazine “Baud:” parameter is set to 115200. Select the binary file for uploading to the board by clicking the “…” button at the right of the “File:” parameter. Navigate to the “ARM_GCC_541\ Debug\PSoC4_Thermistor.cyacd” file, which will be located in the “PSoC4_ Thermistor.cydsn” project folder and click “Open”. You may see numerous Communications Port entries depending on what devices are present on your PC but the bottom one is usually the PSoC board so select this by clicking on it. Finally, click the “Program” button just below the “Actions” menu item. If programming is successful you will see something similar to Fig.6. Otherwise, if it fails you will see an error message as shown in Fig.7. Check that you get the successful program indication. If programming fails, you may have selected the wrong Communication Port selected. Try to find the board in “Devices and Printers” in the Windows Start menu to find out which COM port has been assigned. Otherwise, check that the board is in programming mode by unplugging it from the computer, and while holding the pushbutton at the end of the board re-insert it. Assuming it worked, you should see the current temperature plus Vdd and Vbat voltages displayed on the LCD, if not check your connections. Also check the datasheet of the particular LCD you are using as there are different types, some even have the Vdd and Ground connections reversed. Also try adjusting the contrast potentiometer from one end to the other. There is always much to learn when embarking on a new development environment but the Cypress PSoC range of Microprocessor boards and the PSoC Creator IDE are some of the most intuitive systems around, and at a total cost of around $6 (plus components you probably already have in your parts box) for a board which includes a 32-bit ARM CPU (not 8-bit) makes the device hard to beat. In future articles I hope to explore the PSoC CY8CKIT-059 series of boards that have more computing power and a USB-to-serial adaptor, which doubles as a Serial Wire Debug (SWD) device that enables programming of the board without needing the Bootloader. It even has real-time single step debugging of your code. SC October 2018  87