You are on page 1of 10

PSoC Designer Quick Start Guide

Installation
PSoC Designer is available for download at http://www.cypress.com/go/designer. You can also download an ISO image to create an installation CD. Each Starter Kit also includes an installation CD. If you need help installing PSoC Designer, call Cypress Support at 1-800-541-4736 and select 8. After installation of PSoC Designer you can access PSoC Designer from the Start menu. To start PSoC Designer, click Start > All Programs > Cypress > PSoC Designer 5.1 > PSoC Designer 5.1.

PSoC Designer Flow


Following are the steps in using PSoC Designer

This guide helps you to program a PSoC device through a quick start project using the PSoC evaluation boards such as the CY3210-PSoCEval1. The project reads the voltage from a potentiometer and sets the LED to off, on, or blinking depending on the voltage level. When you are finished with this guide you will be familiar with the entire design process. PSoC Designer Quick Start Guide Doc. No. 001-66310 Rev. ** 1

PSoC Designer Quick Start Guide

Step 1: Create a New Project


In PSoC Designer 5.1, you create a new project for your new design before you begin to design. 1. 2. Click the File menu and select New Project. Choose any desired name for the project and click OK.

Step 2: Choose a Base Device


The device editor that powers the Chip-Level view shows you the resources available on your chosen PSoC device. It allows you to configure and route those resources. After you have created a project, step two is to choose a device. 1. 2. 3. 4. Click the View Catalog button. In the Select Base Part dialog, choose the part used in your kit. The CY3210-PSoCEval1 uses the CY8C29466-24PXI. Consult your kit document for the proper device for your kit. Click Select. Under Generate Main file using, select C. Click OK.

Your project opens in the Device Editor Chip-Level view. The default view has secondary windows that show all kinds of information about your project. You can move, resize, close, and arrange all of these secondary windows to suit your preferences. The View menu contains the available windows.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

Step 3: Choose and Configure User Modules


This project divides the output of a potentiometer into three regions. An LED will be off, on, or blinking depending on the voltage range read from the potentiometer. The user modules required for this project are: PGA. A programmable gain amplifier is used to buffer the input from the potentiometer. ADCINC. An incremental ADC is used to convert the analog input from the potentiometer to a digital value that you can use for the program logic. Timer8. An 8-bit timer is used to blink the LED periodically.

Global Resources
Global Resources are those shared by all user modules in a particular configuration. The IDE Guide (Help > Documentation) contains a complete reference on the effect of each of the Global Resources.

1.

Set the CPU Clock to SysClk/1. Since the Power Setting is at the default of 5.0 V operation and a SysClk of 24 MHz, the CPU will also run at 24 MHz.

2. 3. 4.

Set the VC1 clock to SysClk/3. Set the VC2 clock to VC1/16. Set the VC3 Source to VC2 and the VC3 Divider to 250.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

PGA
1. 2. In the User Module Catalog (View > User Module Catalog), double click to expand the Amplifiers folder. Right-click PGA and select Place. The PGA is placed in the first available analog block. The default placement of the user module is sufficient. 3. 4. Select the PGA user module in the Workspace Explorer. In the Workspace Explorer window, right click on PGA_1 > Properties. The Parameters window for PGA_1 opens. Change the name of the user module to VR_PGA.

Note that the user module name in the Chip-Level view updates with the new name. Right click in an open area of the Interconnect view and select Zoom In to get a close up view of the resources. Press [Alt] and click the mouse to pan the window. Right click again and select Original View to restore the original view. 5. Set the Gain for VR_PGA to 1.000. The PGA is used to buffer the input of the potentiometer, so the Gain is 1. 6. Set the Input to AnalogColumn_InputMUX_0. The input for the PGA will come from the potentiometer routed from a pin to the AnalogColumn_InputMUX_0. By default, the AnalogColumn_InputMUX_0 is routed from P0[1]. You can click the mux and select one of four pins, but the default is works for this purpose. 7. 8. 9. For the VR_PGA Reference, select analog ground, AGND. For Analog Bus, choose Disable. On the diagram, click Port_0_1.

10. Change the name to VR_IN and click OK.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

ADCINC
There are many ADCs available. When choosing an ADC for your application, consult the ADC Selection Guide (there is a link to it at the beginning of each of the ADC datasheets). This project will use the ADCINC. 1. In User Modules, select the ADCs folder. Right click to place the ADCINC.

2. 3.

Select the Single Stage Modulator and select OK. In the Parameters Window, change the Name of the user module to VR_ADC.

4. 5. 6. 7.

Select Unsigned for the DataFormat. For Resolution, select 8 Bit. For Data Clock, select VC1. For PosInput, select ACB00. This connects the output of the VR_PGA GAIN block to the PosInput of the VR_ADC. Check the diagram to make sure that there is a line connecting them. If you are using a chip that has a different configuration of analog blocks than the CY8C29466-24PXI used in the example, choose the block that contains the VR_PGA GAIN block in place of ACB00.

8.

Set the NegInput to ACB00 and the NegInput Gain to Disconnected. This sets the ADC to use a single-ended input.

9.

For PWM Output select None.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

Timer8
The 8-bit timer is used to flash the LED periodically. It uses the interrupt generated by the timer to toggle the LED.

1.

In User Modules, select the Timers folder, and place a Timer8 user module.

2.

In the Parameters Window, rename the user module to LEDFlashTimer.

3. 4. 5.

Set the Clock to VC3. Set Capture to Low. Set TerminalCountOut to Row_0_Output_2. You will route the Terminal Count output to a pin so you can get some practice routing resources in PSoC Designer. You will connect the pin to an LED and set the Drive mode on the pin so that it will flash the LED for a single clock cycle every time the timer reaches terminal count.

6. 7.

Set CompareOut to None. Set the Period to 250. The flash rate of the LED will be 1/4 second: (24 MHz 3 (VC1) 16 (VC2) 250 (VC3 Divider) 250 (Period)) The timer will hit terminal count 8 times per second and each of these terminal counts toggles the LED. The other example project uses the SleepTimer user module rather than the Timer8. The SleepTimer is configurable down to 1 Hz without using the clock dividers. The Timer8 was used in this example to show routing of a user module output to a pin. The same technique can be used to route the output of one user module to the input of another.

8. 9.

Set the CompareValue to 0. Set the CompareType to Less Than.

10. Set the InterruptType to Terminal Count. 11. Set ClockSync to Sync to SysClk.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

Step 4: Connect the User Modules


Each user module has inputs and outputs that can be routed to other user modules and to pins. The output of the VR_PGA user module was routed to the VR_ADC user module in the parameter selection. So to practice routing, you will route the output of the LEDFlashTimer TerminalCountOut to a pin to flash an LED when the counter reaches terminal count. The main LED from the project will be attached to P0[0] (port 0, bit 0), and the potentiometer input is on P0[1], so you will route this signal to P0[2]. Youve already routed the TerminalCountOut to row 0 output 2 in the LEDFlashTimer properties. 1. 2. 3. Locate the RO0[2] (Row_0_Output_2) line in the Interconnect view. It is the blue horizontal line that your LEDFlashTimer is attached to. Click the digital interconnect box on the right end of the Row_0_Output_2 line. In the Digital Interconnect dialog, click the top triangle (Row_0_Output_2_Drive_0) and select GlobalOutEven_2.

4. 5. 6. 7. 8. 9.

Click Close. In the Pinout window (View > Pinout) click to expand P0[2]. Change the Name to LED2. Set the Select to GlobalOutEven_2. Set the Drive to Strong. Click OK.

10. Click to expand P0[0] (the other pin that will have an LED attached). 11. Change the Name to LED1. 12. Set the Drive to Strong. 13. Click OK. 14. Click to expand P0[1] and verify that it is set to accept AnalogInput and is named VR_IN. In the Interconnect view, there is now a line from the TerminalCountOut of the LEDFlashTimer to RO0[2], then to GlobalOutEven_2, and finally to Port_0_2. You have successfully routed the terminal count of your timer user module to a pin and configured the pins for the inputs and outputs attached to them.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

Step 5: Write Firmware


The first step in writing the firmware is generating the application. Generating the application creates all of the source files, library files, and headers that are needed to begin writing the firmware. The APIs generated for each of the user modules you have selected are detailed in the user module data sheets associated with each of the user modules. 1. 2. 3. 4. From the Build menu, select Generate/Build Project. In the Workspace Explorer, double click to expand your project folder. Under the Source Files folder, double click main.c. Copy and paste the following code into main.c. Replace the entire contents of main.c with the text below. The code is fully commented, so you may want to look through the program logic. It starts all three user modules. The ADC begins sampling before the program goes into an infinite loop that samples the ADC and performs some simple logic on the results. After the main program, there is an interrupt service routine written in C.
//---------------------------------------------------------------------------// C main line //---------------------------------------------------------------------------#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules #pragma interrupt_handler LEDFlashTimer_ISR_C // Write the interrupt handler for the Flash Timer in C. #define #define #define LED1_PORT PRT0DR //Constant definition for the data port (Port 0) where the LED (LED1) resides. LED1_ON 0x01 //Constant definition to OR with the LED1_PORT to turn on the LED (LED1). LED1_OFF 0xFE //Constant definition to AND with the LED1_PORT to turn off the LED (LED1).

unsigned char ucVR_ADCResult; //This global variable holds the converted output of the potentiometer (VR). void main(void) { M8C_EnableGInt; LEDFlashTimer_Start();

//Enables the Global Interrupt //Start the Timer UM

VR_PGA_Start(VR_PGA_HIGHPOWER); //Performs all required initialization for the PGA User Module and sets the power //level for the PGA to high power (VR_PGA_HIGHPOWER). VR_ADC_Start(VR_ADC_HIGHPOWER); //Performs all required initialization for the VR_ADC User Module //and sets the power level to high power. VR_ADC_GetSamples(0); //Sets the VR_ADC to run continuously by providing a 0 in the paramater list. while(1) //infinte loop. { if (VR_ADC_fIsDataAvailable() != 0) //This function checks the availability of sampled data. The function returns //a non-zero value if data has been converted and is ready to read. { ucVR_ADCResult = VR_ADC_bClearFlagGetData(); //This function clears the data ready flag and gets converted data as an // unsigned char and stores it in the variable ucVR_ADCResult. //This function also checks to see that data-flag is still reset. //If not the data is retrieved again. This makes sure that the ADC interrupt //routine did not update the answer while it was being collected. if (ucVR_ADCResult <= 85 )

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

//Test to see if the potentiometer is less than 1/3 of the way up //its 8-bit scale. { LEDFlashTimer_DisableInt(); //Disabling the Interrupt for the Timer stops the blinking LED1_PORT &= LED1_OFF; //Turns the LED Off } //end (ucVR_ADCResult <= 85) else if (ucVR_ADCResult <= 170) // Test to see if the potentiometer is less than 2/3 of the way up //its 8-bit scale. { LEDFlashTimer_EnableInt(); //Flashes the LED } // end (ucVR_ADCResult <= 170) else // Don't need to test the top third. { LEDFlashTimer_DisableInt(); //Disabling the Interrupt for the Timer stops the blinking LED1_PORT |= LED1_ON; //Turn on LED1 by setting Bit 0 of Port 0 to high. } } } } void LEDFlashTimer_ISR_C(void) { //Read Port0 and XOR it with 0x01 to change the status from On to Off and vice-versa. PRT0DR ^= 0x01; } //end else //end (VR_ADC_fIsDataAvailable() != 0)

5. 6. 7. 8.

Save main.c. Open the lib folder and then the Library Source Files folder. Open the interrupt routine for the LEDFlashTimer user module, LedFlashTimerINT.asm. Insert the following line after the @PSoC_UserCode_BODY@ banner in the _LEDFlashTimer_ISR section.
ljmp _LEDFlashTimer_ISR_C ; jump to the ISR written in C in main.c

9.

Save and close the LEDFlashTimerINT.asm file.

10. From the Build menu, select Generate/Build Project. You are now ready to program your PSoC device.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

PSoC Designer Quick Start Guide

Step 6: Program and Test Your PSoC Device


1. From the Program menu, select PSoC Programmer. The PSoC Programmer application opens.

2. 3. 4.

Place your PSoC chip into the evaluation board, and plug your programmer into the Target ISSP connector. Click the Program button, and the program is loaded into your PSoC chip. Unplug the programmer from the Target ISSP connector, and connect wires on the evaluation boards breadboard(s) to route the signals to their respective pins. (Wire connections are performed after programming to prevent conflicts with the PSoC programmer.) Press the Target Reset button. Check to see that the program works as desired by adjusting the input voltage to 1 V, 2 V and 4 V (you can use a DVM monitor to assist), and observing the LED response. To observe the blinking LED state, which is expected at 2 V, make sure to maintain 2 V for at least 1 second.

5. 6.

Beyond This Example


This introductory example has familiarized you with the basic design methodology of PSoC Designer and resulted in a functional PSoC design. However, the example did not address many of the more advanced aspects of PSoC Designer, nor did it explain why some of the design decisions were made. More information about PSoC Designer is available in the PSoC Designer IDE Guide found in the Help > Documentation directory. More training on PSoC Designer and other Cypress solutions is available at http://www.cypress.com/training/.

2010 Cypress Semiconductor Corporation. PSoC Designer is a trademark and PSoC is a registered trademark of Cypress Semiconductor Corporation. All rights reserved. All trademarks or registered trademarks referenced herein are the properties of their respective owners.

PSoC Designer Quick Start Guide

Doc. No. 001-66310 Rev. **

10

You might also like