PSoC Lab 01: First Embedded System - Control LED without Using C Code
- Learn how to directly control an LED using the hardware without CPU intervention (currently not possible with other MCUs)
- Learn Programmable System on a Chip (PSoC) architecture and configuration
Cypress PSoC 5LP has internal routing paths (similar to FPGAs) for digital and analog signals that can be configured to establish connection between the internal components and external physical pins. Those are hardware connections that do not need the CPU to transmit signals. At this time, other microcontrolers do not have such configurable architectures, therefore, their CPUs must be involved in transmission of all signals within their interfaces.
In Lab 01, we will program the PSoC 5LP board to control an LED by pressing the button, and using internal connection to directly connect the input button to the output LED without any software code.
Required Components List
If you are using the Cypress CY8CKIT-059 Kit, the onboard LED and button will be used in this lab.
The following components are required for this lab.
|Push Button||x 1|
|Resistor: 200ohm||x 1|
|Red LED||x 1|
Circuit / Schematic
Required Reading Material
Creating A New Project
Launch the PSoC Creator and create a New Project. In the New Project wizard, select Empty Schematic, edit the name of the Project and Workspace.
Adding PSoC Creator Components
After you create a project, the PSoC Creator will bring up the TopDesign.cysch tab, with an empty schematic. You need to add some of the components to the TopDesign.cysch. On the right side of PSoC Creator window, you can see a tree-structure panel called the "Component Catalog", which has Cypress and Off-Chip tabs for component selection.
- Cypress Components are always installed. These are developed by Cypress for use in your designs.
- Off-Chip or "External" Components, if installed, are used to document connections the device may have on the development board. They are used for documentation purposes only.
According to the schematic design, we need one digit input pin to read the current status of the push button, and one digit output pin to turn on an LED. Therefore, you have to select Digital Input Pin and Digital Output Pin Components from Cypress tab in Ports and Pins catalog, and drag them to the schematic as shown on the following diagram.
When you drag the components to the schematic, always place Input components on the left-hand side, and Output components on the right-hand side.
Configure the Components
In your next step, you will need to configure these components.
- Double-click on Pin_1 component, the input pin. You will get the component configuration window, where you can set all various parameters that define the part at the build time.
Change the component name to nSW.
Select the External terminal checkbox to show the terminal pin and enable the connections to Off-Chip Components in the schematic.
Change Drive mode to Resistive pull up.
- Perform identical procedure for the output pin, but do leave the drive mode with its default setting. Double-click on Pin_2 component, the output pin.
Change the component name to LED.
Select the External terminal checkbox to show the terminal pin.
In this lab, we want to turn on the LED by pressing the push button, so you need to make a wire connection between the input and output component.
- Signal-click on the Wire Tools button to draw one wire connection.
- Double-click on the schematic to start or end a wire drawing process.
- Double-click on the Wire Tools button to draw to draw multiple wires at once.
- Press [ESC] key to quit drawing wires.
Drawing External Circuit on the Schematic
Drawing the complete external circuit on the schematic will help you with quick understanding of input and output signals.
On the Component Catalog panel, change to Off-Chip tab, and then drag external components to your schematic as shown on the following diagram.
The schematic representation of Vss (Ground), 10K Resistor R_1, LED D_1, and Switch (SPST) SW_1 are just 'visual aids', These visual aids are:
- available in the Off-Chip library component tab
- show in blue
These components are not taken into consideration in the PSoC programming stage; All components shown in blue are not used when the build is involved.
The Green wires are digital connections. They connect the components through the internal routing path to transmit the signals.
The Blue wires and Blue components are off-chip documentation components. They are used to illustrate circuitry external to PSoC device only. It can help you and other engineers to easily understand the circuit, but they are not used for building the project.
The last thing to do before building the code is to assign these logical pins to a physical pin on the PSoC 5LP device. To do this, open the Design Wide Resources file (.cydwr) from the Workspace Explorer on the left side of the window. You will get similar pin assignment window as shown in the following figure:
On the right side, there is a list of pin objects, port pins, and physical pin numbers. If you do not assign a pin to a physical port, the PSoC Creator will do it for you. In this Lab, the LED is connected to port 2, pin1, and the push button is attached to port 2, pin2. So, you have to assign P2 to LED, and P2 to nSW.
Building the code and Programming
No additional software is needed in main.c for this experiment. Therefore, you can build the project using the Build menu or Build icon . The Output panel shows the build results. Any errors will stop the build process and messages identifying these problems will be displayed in the Output panel.
To program the PSoC with the newly build firmware, connect the PSoC board to the PC using the USB cable. Load the program using either the Debug➤Program selection or the following Program icon . The programming status is also shown in the Output panel.
When programmed, you can press the push button and observe the status of the LED.
- Is the LED on when the button is pressed and off when it is released? If not, can you just add one more component from Component Catalog to the Schematic file in the PSoC Creator without changing any physical hardware outside the device? Explain.
- Why the Drive mode in nSW (Digital Input Pin) must be Resistive Pull Up? Change the Drive mode to High Impedance Digital, then program the PSoC and see what happen? Explain.
- Most of microcontrollers do not have configurable routing paths to connect internal components. How to implemented this Lab on the these MCU? Show your solutions using the Flowchart or pseudocode on the report.
EX 1: Toggle the LED
Design a hardware that toggles the LED each time the button is pressed.
Using exact same external circuit and connections that were previously used in the Lab. Create a new project and draw the schematic file as shown in the following diagram.
Build the project and program the code to the PSoC board, then press the button to observe the changing of the LED.
- Does the LED change status at the moment when you press the button? Explain why.
- Redo this exercise by using D Flip Flop (with a logic gate) instead of Toggle Flip Flop, and modify your TopDesign to change the LED status at the moment when you press the button. Show your TopDesign on the report.