Project

Getting Started with PSoC®

August 27, 2015 by Marie Christiano

Getting started with PSoC®, the Programmable-System-on-Chip by Cypress Semiconductor for developing and testing embedded systems.

Introduction to PSoC®

PSoC® Programmable-System-on-Chip is Cypress Semiconductor's programmable design and test environment for embedded systems. The PSoC family includes PSoC1, PSoC3, PSoC4 and PSoC5, which differ in capabilities, microcontrollers, amount and type of memory available and types of interfaces included.  The PSoC environment includes an IDE for creating, building and debugging projects, a programmer to load firmware and an emulator.  Development kits for each PSoC family are available and contain everything to get started.  Tutorials, projects and information are available from the developer community, forums and Cypress Semiconductor's support team.  A 'Thank you' goes out to the Cypress Semiconductor PSoC Marketing Team for their support.

Required for this project:

  • PSoC4 BlueTooth Low Energy ( BLE) Development Kit.  Any PSoC kit with an LED can be used with appropriate changes for the individual component selection and pin assignments.  A CR2032 lithium-ion 3V, 250mAh button cell battery is included which is installed on the board to provide portable Vdd power. Cypress Semiconductor recommends removing the battery when not in use.
  • Windows-based PC that can support the development environment with a standard USB port.
  • PSoC Creator 3.2, the IDE for developing, programming and debugging the PSoC4.
  • Knowledge of c programming language is helpful

The PSoC Creator is available as a free download from the Cypress Semiconductor site after creating an account.  The PSoC Programmer is also available as a separate download, if using a different IDE.  There is also an emulator, CySmart for Windows PCs, as well as for Android Mobile and iOS Mobile Apps

Embedded Systems to PSoC

An embedded system is part of a larger system, usually providing the control and interface functions.  An embedded system may contain a processor, memory, data storage, signal conditioning, displays and controls. The embedded system 'lives' within the hardware and its capabilities are only available to users through specific interfaces, like switches or knobs, if there are any user controls at all. The embedded system originally consisted of discrete components on printed circuit boards (PCBs).

As manufacturing and chip technology improved, some components of an embedded system could be placed on a single chip, manufactured as a single integrated circuit (IC). This cut down on space requirements; data movement was faster and it enabled smaller devices.  Applications where the entire system resides on an IC are referred to as System-on-Chip (SoC).

Cypress Semiconductor took the idea behind programmable logic and field programmable gate arrays (FPGAs) and developed a SoC where certain elements were programmable, introducing the Programmable System-on-Chip (PSoC®) in 2002.  With the same board, different applications can be developed using hardware and software components.  The PSoC IDE gives developers the ability to select and configure hardware components, compile and control necessary software, program and test projects from one window.  By linking in datasheets, component information is available to developers when needed, providing a powerful development environment. 

PSoC Basics

The basic steps to programming a PSoC are:

Create your Project/Program using the PSoC IDE.  This is a multistep process, similar to the way some visual programming languages allow you to select GUI components and program them to respond to various events.  The PSoC IDE allows you to select components from the component library, configure them to your requirements, set up hardware connections between the microcontroller pins and your components, and then, if needed, write software to control or respond to various events. The PSoC Creator presents index tabs for the TopDesign where you select and configure components, the design-wide resource, where you set up the microcontroller port/pin connections and the main.c file where your initial code begins. The code can be as simple as the defaults given in main.c, to multiple *.c files to produce firmware for a complex system. 

Build the project.  Building the project produces a target loadable .hex file, in either a Release or Debug version for a given device. The build compiles the individual files, producing object files (*.o files) and list files. The .o files are combined to produce an .ELF (Executable and Linkable File) and finally a .hex file which contains the firmware to be migrated to the target device. During the build, several software components are generated by PSoC automatically. Debug versions includes additional control hooks that allow the program to be executed under debugger control.  A release version doesn't include extra controls and execution can begin immediately.

Program the PSoC. Using the kit's included USB cable, the .hex file is loaded into the PSoC memory. Programming of the microcontroller erases the previous program and reprograms the memory with the new .hex file. When successfully loaded, the microcontroller controls the execution of the program. Depending on the system and environment, the program may begin running immediately. Debug versions need to be started manually.  With the battery installed, once programmed, the PSoC can be disconnected from the PC and it will continue running.

The Projects

The PSoC4-BLE kit includes an ARM Cortex-M0 micrcontroller, an onboard capacitance sensor (CSD) and BLE technology. The block diagram from Cypress Semiconductor shows the subsystems:

 

Clocks, timers, analog and digital configurable elements and General Purpose I/O (GPIO) pins are included..   Application Programming Interfaces (APIs) for each component enable software access and control. The APIs are listed in the Datasheet, available from the component configuration window.  This project uses the pin, LED, clock and PWM components. 

Project ideas are endless, but to get started and introduce the flexibility of PSoC the following will be covered:

1.  A hardware only project to light the onboard LED; it requires no additional software.
2.  A hardware control project to blink the onboard LED; software is needed to enable the hardware components but the LED blinking is under hardware control.
3.  A software control project to blink the onboard LED under control of a software program.

 

1.  Light the onboard LED

This initial project will have the PSoC light the onboard red LED. It uses the circuitry provided within the PSoC: the red LED cathode is connected to P2[6] with a copper trace so all connections are provided on the board. 

NOTE: Every PSoC device has different LED port assignments. The Red, Green, Blue (RGB) LEDs have different ports for each color.  Refer to the schematic included with your kit for the appropriate ports. The LED ports are also shown via the silkscreen on the back of the PCB.    For the PSoC4-BLE, the red LED is P2[6]; Green is P3[6] and Blue is P3[7]. 

Open the PSoC Creator, and begin a new project:

 

Select the default for your PSoC. Here, PSoC4 BLE with an empty schematic is selected.

This brings up the TopDesign tab, with an empty schematic.  On the right, the components library has Cypress and Off-Chip tabs to select components.

 

 

The PSoC Creator shows all aspects of your project, and you can select views using the toolbar View tab.  The Workspace Explorer has tabs for Source, Components, Datasheets and Results. The Results tab will hold the list, ELF, hex and map files resulting from the build. The component library shows available components;  the Code Explorer shows the files and functions.

Select your target device using Project-> Device Selector.

If you forget and use the default device selection, you'll get an error when you try to program your device. You can just select the correct device and rebuild the project.

 

A simple circuit to light an LED may include the LED, power source and current limiting resistor in series to ground, as shown:

To produce this circuit with the PSoC4-BLE, at the TopDesign tab, select a Digital Output Pin component and drag to the schematic.

 

The pin is configured by clicking on the image to bring up the configuration window. A HW connection is the default; you can select the external terminal to show the terminal as well configure other aspects of the pin.   All components can be renamed from their configuration window.  Once renamed, APIs for the component will reflect the selected name.  

 

 

 

The pin represents a connection tor the microcontroller; it must be connected using the design wide resources tab. Clicking the *.cydwr file in the Project tree brings up the design wide resource tab with the microcontroller pinouts.

For the PSoC4, connect Pin_1 to Port: P2[6]  Pin 43, for the red LED.

 

To complete the circuit, at the TopDesign tab, a logic low, 0, is connected to the pin.

 

Cypress and Off Board Component Selections

Shown below are two circuit representations for the LED circuit: one showing a single pin; one with additional components from the “Off-Chip” library selections.  These are identical to the PSoC Creator, but one is much easier to understand!

 

 

The schematic representation of Vdd, 10K Resistor R_1 and LED D_1 are just 'visual aids', they are
1)   available from the Off-Chip library component tab
2)   shown in blue

These are not considered in the PSoC programming; any components in blue are not used when the build is invoked. Blue components can help other engineers understand the circuit, but they are not used to build the project.  With either representation, the pin component must be connected to P2[6] for the PSoC4_BLE red LED circuit.  The LED circuit is shown via the silkscreen on the back of the PCB.  All the components can be renamed for clarity:

No additional software is needed in main.c and that completes the LED circuit.

 

Build the project using the Build tab or Build icon (leftmost).  You can select a Debug or Release version.

 

The Output window shows the build results; a successful build produces a .hex file, and displays the amount of flash and SRAM used, as well as the stack and heap available.  As a result of the build, a Generated_Source branch in the Project tree shows included files; the list files and .hex file are in the Results tab.

 

Any errors will stop the build; messages identifying the problem(s) will display.

 

To program the PSoC with the newly built firmware, connect the PSoC board to the PC using the USB cable.

Load the program using either the Debug-> Program selection or Program icon (leftmost)

The available targets are shown...  select the PSoC 4200 BLE.

 

The programming status is also given in the Output window:

When programmed, the red LED on the PSoC is lit.

 

2.  Blink the onboard LED using a Pulse Width Modulator (PWM)

A PWM produces a pulsing signal that can control power supplied to electrical devices.  The PSoC component library includes a PWM that can control the LED from the line output.  A clock input provides timing.  The same pin connection is used, connected to P2[6] as before with the HW connection set.

 

The PWM is configurable; clicking on the image brings up the configuration window:

The datasheet contains information on the component:

 

 

 

The PWM and clock are system components that need to be started in software.  The PWM_Start API description is:

void PWM_Start(void) Description: This function intended to start component operation. PWM_Start() sets the initVar variable, calls the PWM_Init function, and then calls the PWM_Enable function. Parameters: None Return Value: None Side Effects: Sets the enable bit in the control registers of the PWM. If the Enable Mode is set to Hardware Only, this has no effect on the PWM. If the Enable Mode is set to Hardware and Software, then this will only enable the software portion of this mode and the hardware input must also be enabled to finally enable the PWM.

 

In main.c the following functions have to be included to start the clocking:

Clock_Start();
PWM_Start();

 

They are placed in the initialization / startup code section in main.c:

 

Build the project and program the PSoC.  Once started, the PWM will control the LED.  Debug versions require the program to be manually started, since debug versions start program control at main.c.  The red LED blinks as configured. 

Try changing the blink cycle, by reconfiguring the PWM and clock.  

3.  Blink the onboard LED using Software Control

Software functions are available to access pin locations directly. The pin component datasheet lists the APIs available including:

Pin_Read()     Reads the physical port and returns the current value for all pins in the component

Pin_Write()     Writes the value to the component pins while protecting other pins in the physical port if shared by multiple Pins components 

Pin_1_Write() directly controls the red LED. writing a 1 to enable the LED; 0 to turn it off.  Because the ARM is so fast, a system delay is included using the delay API CyDelay(500); so the blinking is visible.

At the TopDesign tab, the circuit looks the same but the pin is now configured for software by unchecking the HW connection in the configuration.  At the design wide resource tab, the pin is again connected to the red LED, P2[6].

 

The Write/Read functions and the delay are added to main.c, within the for loop.  After any initialization, code within the for (;;) loop will be continuously executed.  A simple blink program can write to the LED the inverse value of whatever the LED reading is currently, delay a half second, then write the reverse:

 

The program can be more complex, establishing global values to use in the read and write functions.

 

 

When software is included, the Debug feature of PSoC Creator is useful to check program execution.  Build with Debug selected, then use the Debug tab or icon (leftmost in the picture) to start the debugger.

 

The debugger allows breakpoints to be set by clicking in the statement margins:

 

 

In the debugger, use the debug controls to resume, halt and stop execution, step into, out of or over functions and enable/disable all breakpoints and interrupts:

 

In the debug mode you can also view local variables, registers,  and memory by selecting the display from the tabs at the bottom of the screen. 

 

Note:  If not all the variables in your program are shown in the Locals display, the compiler may be optimizing the code.  If it determines a variable isn't used, it may not allocate space for it.  

 

Use the Registers and Memory 1 tabs to bring the displays into view:

 

Executing the program with breakpoints on will turn the LED on and off as the breakpoints are hit and then execution resumed.  Removing the breakpoints allows the program to run freely and the red LED blinks.  

Once programmed, with the battery installed, the PSoC can be removed from the PC and the program continues to execute under microprocessor control; the LED continues to blink, as shown.   If the cell battery is removed, the blinking stops, but reinstalling the battery will start the execution again and the LED blinks automatically.

Try using all the LED ports to blink the LEDs in sequence.  You can build more complex projects, using hardware and software components to explore the PSoC environment.  In addition to learning individual components, PSoC is a great way to learn the microcontroller capabilities and systems.

Summary

PSoC is a powerful design and test tool for embedded systems. Hardware components can be programmed to design requirements, firmware can tested, and tradeoffs explored. The programmable aspects of the PSoC allows designers to modify system components without requiring boards to be redone for design modifications.  From very simple projects, you can build up to complex circuit designs.

Give this project a try for yourself! Get the BOM.