You are here

DIM LED | Cypress Semiconductor


Last Updated: 
Mar 18, 2012

Project Introduction:

For this example project, which we will call ‘DIM LED’, the CY8CKIT-001 hardware will be used to control the brightness of an LED using a pulse width modulation (PWM) user module. This example will assume that you’ve completed the initial ‘PSoC Rocks!’ example project that instructed the user on creating new projects and discussed the basic layout of the software tool.

This example project focuses on integrating a digital user module, the Pulse Width Modulator (PWM), to control the brightness of an LED. This example project will primarily focus on introducing the PWM and instructing user on Chip Level routing. Knowledge on how to route digital and analog connections in the Chip Level view is critical in using PSoC Designer. In the PSoC Designer example projects we will use interconnect routing extensively.

Software Used:

PSoC Designer: Click Here
PSoC Programmer: Click Here

Hardware Used:

This example project will utilize the following hardware.

All of the above hardware is included in the CY8CKIT-001 kit.

Steps to Set Up Hardware:

To set up this hardware please perform the following actions:

  • Insert the CY8CKIT-020 processor module into the CY8CKIT-001 socket.
  • Connect a wire to the black bread board headers from LED1 to P0_0

Please see the wire connection in the image below. The wire is represented by the red line and must be connected to the black header running next to white bread board. The CY8CKIT-001 is shipped with a set of wires. Each wire has an exposed end. This exposed end must be inserted into the header. Each header whole has silk screening on the board that indicates the routing. If the header hole indicates P0_0, then this means that the header is routed to the port 0 pin 0 on the PSoC. The bottom black header indicates connections to components that are on the target board. For example the LED1 header hole will connect directly to the LED1. The wires allow us to physically connect a pin on the PSoC to a component on the board and use them in our embedded design.

Steps to Create Project

This example project assumes that you’ve completed the ‘PSoC Rocks’ introductory example project. The ‘PSoC Rocks’ example project walks the user through project creation and the software layout. It’s suggested to complete that example before completing this example project. To begin the example project create a new project using PSoC Designer.

  1. Open PSoC Designer by navigating Start -> All Programs -> Cypress -> PSoC Designer -> PSoC Designer. This will launch the PSoC Designer application.
  2. In the Recent Projects window at the top left please select the New Project… link.
  3. In the New Project window please enter in the name of the project “CY8C28445_DIM_LED”. Please select the project location by selecting the Browse button. Click OK
  4. The Select Project Type window will open. You can either click the drop down menu to select the target device or launch the device catalog by clicking the View Catalog button. We will be selecting the “CY8C28445-24PVXI” device.
  5. If you select the parts via the View Catalog option then please scroll down to the “CY8C28445-24PVXI” device and select the Select button.
  6. You will return to the Select Project Type window. Please select the “C” radio button for main.c file generation. This will mean that you will be developing a C-based project rather than an assembler based project. Select OK.

After you select the OK button PSoC Designer will open the Chip Editor view. In the following section we will cover the various options and actions available in the Chip Editor view. We will begin setting parameter values and designing our system.

User Module Placement and Configuration

In this section we will discuss how to design the embedded system by setting global parameters for the PSoC, adding User Modules, and making pin selections.

  1. Please navigate to the User Module window and select PWMs>PWM8. Right click on PWM8 and select Place. You will notice that the Workspace Explorer window was updated and now lists the PWM user module, “PWM8_1”.


  2. Select the PWM user module in the Workspace Explorer. You will notice that the Parameters window updates and now offers selections pertaining to the PWM user module.


  3. Under the Parameters window please rename the user module from “PWM8_1” to “PWM”. Please set the remaining PWM user module parameters to the values displayed in the image below.


  4. Next we will begin routing the PWM connections to the output pin, which is connected to the LED. Often when you are working on the chip interconnect it is helpful to zoom in and pan. To zoom in the user must select Ctrl+Click, to zoom out Shift+Ctrl+Click. To pan the user must hold Alt and then click and drag.
  5. Zoom into the PWM user module in the interconnect window. We will want to ensure that our PWM user module is connected to VCC through the Enable connection. This can be completed by selecting the Enable text and selecting High. We will see the line drawn. This connection can also be selected from the user module parameters window.


  6. We must route out the CompareOut connection from the PWM to the Row Output bus. To do this we can simply click on the CompareOut text on the PWM. This will present us with five options. We will want to select Row_0_Output_0. Once selected we will see a line drawn from the PWM output to the Row Output. This connection can also be selected from the user module parameters window.


  7. From the Row Output bus we will need to connect to the vertical Global Output Even bus. To do this we will click on the blue box at the right end of the Row Output bus. This will launch a small window that will present us with a number of options. Click on the top triangle and enable the GlobalOutputEven_0 value. This will connect the Row Output to the Global Output Even bus. Please select Close when the selection has been made.


  8. Finally we will want to connect the Global Out Even bus to our P0(0) pin. This is the pin we’ve connected on our board to the LED1 component. By making this connection we will have connected the output of the PWM to the LED. To make this connection pan up to the Port_0_0 icon. Simply click on the icon and a configuration window will appear. We want to click on the Select row and then on the drop down menu to view the available connections. We will want to select GlobalOutEven_0 from the available selections. When complete please click OK.


  9. Now that all of the user module placement and configuration is complete we need to generate the project source files based on our selections.Please navigate to the menu panel and select the Generate Configuration Files button. The output window will display the actions when generating the configuration files and report any design rule check (DRC) warnings. DRC warnings are used to warn the user if they have selections in their project that are outside of the best practices.

Now that we have completed the user module selection and configuration we will proceed to add source code to call the user module code we generated.

Adding Source Code

When generating the project we selected that the project be generated for C language development. We will now add our C code to the main.c file.

  1. Navigate to the Workspace Explorer window, expand the source files directory and double-click the main.c file.
  2. The main.c file is now open in the editor tab window. Users will notice that the Workspace Explorer is still available on the right side and can scroll between the text editor and the Chip Editor. Users can open additional files by double-clicking files in the Workspace Explorer.
  3. We will not add source code to our project to enable the PWM’s control of the LED. The code is linked below and should be added into the main function.

    void main(void)
           /* ensure interrupt is disabled */
           /* start the PWM8! */
           /* set period of the clocks */
           /* set pulse width to generate a duty cycle */

  4. Once the code has been entered into the main.c file we will then build the project by selecting Build>Generate/Build, pressing F6, or by selecting the Build button .
  5. The build status will be displayed in the Output window. The output window will display either a successful build or a list of build errors associated with the project. In this case we will have no build errors.
  6. Make sure that the Miniprog3, included in the CY8CKIT-001 kit, is connected to the white 5-pin programming connector to the USB port on the PC.
  7. To program our target device please select Program>Program Part. This will launch the PSoC Designer embedded programmer. Please choose the Power Cycle radio button and then select the Program button, which is located at the bottom right of the embedded programmer.


  8. Now that the device is programmed we want to power the CY8CKIT-001 and see the message displayed on the LCD screen. To do this keep the Embedded Programmer open and select the Toggle Power button .
  9. Once power is applied LED1 on the board should be in the on state but dim. Now go back to the example code in step 3 and vary the values (0-255) in the PWM_WritePeriod and PWM_WritePulseWidth functions. Repeat steps 4-8 to see the new LED1 output.

Analysis of the Code:

In this section we will go into more depth on the source code we added to the example project. In our example project we added a number of function calls to the generated PWM user module code.

Our first two actions cover PWM initialization. We first disabled the PWM interrupts as we are not using this feature in this example and then we make a call to Start the user module.

/* ensure interrupt is disabled */

/* start the PWM8! */

Next two PWM functions are called PWM_WritePeriod and PWM_WritePulseWidth. These two functions set critical parameters that affect the output of the PWM. Initial static values have been entered into the function call. For more advanced projects users can enter in variables and have the embedded project change the values to vary the LED brightness.

/* set period of the clocks */

/* set pulse width to generate a duty cycle */

Summary of the Project:

The goal of this project was to introduce the user to the PWM, Chip Level routing procedures, and how to use the PSoC user modules to control external components. In this example project we used a PWM as a variable brightness controller for an LED.

For more information on the PWM user module and its functions please see the user module datasheet. Users can access this datasheet by right clicking on the user module in the Workspace Explorer window. This datasheet details parameter selections, API descriptions, and example code.

Related Projects:

PSoC Rocks!: The user will interface an LCD with the PSoC to display a statement.
LED Blinky: The user will utilize a pulse width modulator (PWM) to dim an LED
ADC LCD: Use a potentiometer to display an analog voltage value on an LCD screen.