12
Getting Started with PSoC ® 3 June 24, 2011 Document No. 001-54181 Rev. *F 1 AN54181 Author: Ross M. Fosler Associated Project: Yes Associated Part Family: CY8C38xxx Software Version: PSoC Creator™ Production 1.0 Associated Application Notes: None Application Note Abstract If you are looking at PSoC ® for the first time, this is an excellent place to start learning about its features and to find more information. PSoC 1, PSoC 3, and PSoC 5 are programmable system-on-chips that do everything a microcontroller does and more. In this application note you learn about PSoC 3 and PSoC Creator™, an interactive IDE and graphical design tool that you use to develop your system-on-chip project. Introduction PSoC 1, PSoC 3 and PSoC 5 are all true programmable embedded system-on-chips that integrate configurable analog and digital peripheral functions, memory, and a central processor on a single chip. PSoC contains a processor, but it is not an MCU. The name—PSoC (programmable-system-on-chip)—defines its true identity. AN54181 introduces the programmable- system-on-chip concept with specific emphasis on PSoC 3. Here, you learn about PSoC 3 and what it can do for you and your projects. It also introduces PSoC Creator™, a powerful IDE development tool for PSoC 3 and PSoC 5. PSoC is More Than an MCU A typical MCU contains a processing core (such as 8051) with a set of peripheral functions such as ADCs, DACs, UARTs, SPI, and general I/O all connected to the main CPU. For this reason, you might say that the processing engine, the CPU within the MCU, is the “heart” of the device. The CPU manages everything from setup to data movement to timing; without the CPU the MCU is not an MCU. Figure 1 shows a basic view of an MCU with all the peripheral functionality linked to the CPU’s register interface. Figure 1. Typical MCU 8051 UART SPI I2C ADC DAC PWM Timer Port A Port B Port C Port D PSoC is quite different in that it is actually a superset of a generic MCU. Thus you can program PSoC to emulate an MCU, but you cannot program an MCU to emulate PSoC. Also, with PSoC, is the CPU, analog, digital, and I/O are equally important resources in a programmable system. It is the system interconnect, and programmability that is the heart of PSoC and not the CPU. The peripheral analog and digital are interconnected with a highly configurable matrix of signal and data bus meshing that allows you to create a completely unique device. Again, the CPU is not central to system functionality, but the programmable functionality and the programmable interconnect is central to the design. Figure 2 shows a high level view of PSoC architecture. Notice that the 8051 is not the central connecting interface to everything. Figure 2. Typical PSoC 3 Digital System (w/ Programmable Logic) 8051 Analog System Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O Gen I/O System Interconnect

Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

Getting Started with PSoC® 3

June 24, 2011 Document No. 001-54181 Rev. *F 1

AN54181 Author: Ross M. Fosler

Associated Project: Yes Associated Part Family: CY8C38xxx

Software Version: PSoC Creator™ Production 1.0 Associated Application Notes: None

Application Note Abstract If you are looking at PSoC® for the first time, this is an excellent place to start learning about its features and to find more information. PSoC 1, PSoC 3, and PSoC 5 are programmable system-on-chips that do everything a microcontroller does and more. In this application note you learn about PSoC 3 and PSoC Creator™, an interactive IDE and graphical design tool that you use to develop your system-on-chip project.

Introduction PSoC 1, PSoC 3 and PSoC 5 are all true programmable embedded system-on-chips that integrate configurable analog and digital peripheral functions, memory, and a central processor on a single chip. PSoC contains a processor, but it is not an MCU. The name—PSoC (programmable-system-on-chip)—defines its true identity. AN54181 introduces the programmable-system-on-chip concept with specific emphasis on PSoC 3. Here, you learn about PSoC 3 and what it can do for you and your projects. It also introduces PSoC Creator™, a powerful IDE development tool for PSoC 3 and PSoC 5.

PSoC is More Than an MCU A typical MCU contains a processing core (such as 8051) with a set of peripheral functions such as ADCs, DACs, UARTs, SPI, and general I/O all connected to the main CPU. For this reason, you might say that the processing engine, the CPU within the MCU, is the “heart” of the device. The CPU manages everything from setup to data movement to timing; without the CPU the MCU is not an MCU. Figure 1 shows a basic view of an MCU with all the peripheral functionality linked to the CPU’s register interface.

Figure 1. Typical MCU

8051

UART

SPI

I2C

ADC

DAC

PWMTimer

Port A Port B

Port C Port D

PSoC is quite different in that it is actually a superset of a generic MCU. Thus you can program PSoC to emulate an MCU, but you cannot program an MCU to emulate PSoC. Also, with PSoC, is the CPU, analog, digital, and I/O are equally important resources in a programmable system. It is the system interconnect, and programmability that is the heart of PSoC and not the CPU. The peripheral analog and digital are interconnected with a highly configurable matrix of signal and data bus meshing that allows you to create a completely unique device. Again, the CPU is not central to system functionality, but the programmable functionality and the programmable interconnect is central to the design. Figure 2 shows a high level view of PSoC architecture. Notice that the 8051 is not the central connecting interface to everything.

Figure 2. Typical PSoC 3

Digital System(w/ Programmable Logic)

8051

Analog System

Gen

I/O

Gen

I/O

Gen

I/O

Gen I/O

Gen I/O

Gen I/O

Gen I/O Gen I/O

Gen I/O Gen I/O

System Interconnect

Page 2: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 2

To highlight the distinction between a PSoC and an MCU, you can configure a PSoC to have elements that operate independently from the 8051. The projects included with this application note demonstrate this configuration. The PSoC is configured make an LED blink without the knowledge of the 8051 core. This means that the I/O and logic are configured and connected together to process the blinking of an LED in a unique way without the 8051 in between. A typical MCU requires firmware on the core to process state operation, use a timer for timing, and drive an output pin. Thus the functional path is almost always through the core on an MCU, but with PSoC asynchronous parallel processing is possible. As another example, you may have noticed already that PSoC 3 has no UART. However, if the application requires a UART, you can make one within the configurable logic provided on PSoC 3. Then, you define and build an interface to the 8051 to give it control of the UART. Note that a UART component designed and tested by Cypress is already available in PSoC Creator.

PSoC 3 Feature Set The PSoC 3 feature set is quite significant and well defined in the data sheet (www.cypress.com/go/psoc3). Only a brief summary is presented here. Single-cycle 8051 CPU

Up to 64 kByte of flash Up to 8k Byte of RAM Up to 2k Byte EEPROM

Digital Subsystem Up to 24 Universal Digital Blocks of

programmable logic CAN 2.0 Full-speed USB 2.0 Digital Filter Block

(48-bit digital signal co-processor) Up to four configurable timer/counter/PWMs

Analog Subsystem Up to four configurable analog blocks 8-bit to 20-bit configurable delta-sigma ADC Up to four 8-bit current DACs Up to four fast analog comparators Up to four fast opamps CapSense

I/O Subsystem Analog or digital on any GPIO fully routable Four I/O Voltage Domains Up to 5.5V I/O 25mA drive capability Configurable pull-up/down, open drain high/low,

push-pull, high-z

Refer to the datasheet (www.cypress.com/?rID=35178) for a full review of PSoC 3’s features.

Comparing PSoC 1, PSoC 3, and PSoC 5 The differences between PSoC 1, PSoC 3, and PSoC 5 are generally characterized by the scaling of all subsystem features within the devices as shown in Figure 3. The processing performance scales upward from PSoC 1 through PSoC 5. The digital and analog, quantity, performance, functionality, and configurability also scale upward from PSoC 1 through PSoC 5. Table 1 shows a more detailed summary of the differences.

Figure 3. Basic PSoC Differences

Product ClassP

erfo

rman

ce(P

roce

ssin

g/A

nalo

g/D

igita

l)

PSoC 1M8C CPUSC/CTs

Configurable Digital

PSoC 3Single-cycle 8051 CPUProgrammable Logic

Op-ampsComparators

CT/SCsDel-sig ADC

DACs

PSoC 5ARM Cortex-M3 CPUProgrammable Logic

Op-ampsComparators

CT/SCsDel-sig ADCSAR ADCs

DACs

Comparing PSoC 3 and PSoC 1 Although the fundamental programmable-system-on-chip philosophy remains the same, there are many differences between PSoC 3 and PSoC 1. Refer to www.cypress.com/go/psoc1 for more information on PSoC 1. Here are a few of the major distinctions that differentiate the two major families.

Processing Subsystem A high performance 33 MIPS single-clock-per-instruction 8051 CPU that significantly extends the processing capability over the traditional 4MIPS M8C CPU in PSoC 1.

Analog Subsystem An expansion over PSoC 1’s CT and SC blocks with the addition of an ADC, DACs, comparators, and opamps. In addition to the quantity, the performance of the analog is improved.

Digital Subsystem Includes programmable logic and more of it, which is distinctly different than PSoC 1’s configurable fixed-function digital blocks in which each block in PSoC 1 can be configured for one of a set of peripheral functions. Also, PSoC 3 includes some more advanced processing and communications functions such as the Digital Filter Block and CAN support.

I/O and Interconnect Subsystem Provides significantly more flexibility on analog and digital routing to the I/O, which eliminates the port restrictions that exist on PSoC 1, and provides significantly more routing flexibility between various digital and analog elements. Also, PSoC 3 provides a highly configurable DMA interface for bussing data between many data-based system functions.

Page 3: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 3

Comparing PSoC 3 and PSoC 5 There are only a few distinct differences in the processing and analog sub-systems that differentiate PSoC 3 and PSoC 5. See www.cypress.com/go/psoc5 for additional information about PSoC 5. The major differences are as follows.

Processing Subsystem A high performance 100 MIPS 32-bit ARM Cortex M3 when compared with PSoC 3’s 33MIPS high performance 8-bit 8051.

Analog Subsystem PSoC 5 has Two additional 1 Msps SAR ADCs, which extends analog-to-digital processing performance capability.

Table 1. Comparison between PSoC 1, PSoC 3, and PSoC 5

Feature PSoC 1 PSoC 3 PSoC 5

CORE 8-bit M8C 4 MIPS

8-bit 8051 33 MIPS

ARM Cortex-M3 100 DMIPS

FLASH 4 KB – 32 KB 16 KB – 64 KB 32 KB – 256 KB

SRAM 256B – 2 KB 2 KB – 8 KB 16 KB – 64 KB

EEPROM – 512B – 2 KB 512B – 2 KB

POWER Active: 2 mA Sleep: 3 uA

Active: 1.2 mA Sleep: 1 uA Hibernate: 200 nA

Active: 2 mA Sleep: 2 uA Hibernate: 300 nA

ADC 6- to 14-bit ΔΣ 12- to 20-bit ΔΣ 12- to 20-bit ΔΣ 2x 12-bit SAR (1 Msps)

DAC 6- to 8-bit 8- to 12-bit 8- to 12-bit

VOLTAGE REFERENCE ± 1.53% Vref Accuracy ± 0.1% Vref Accuracy ± 0.1% Vref Accuracy

DIGITAL BLOCKS Up to 16 Digital Blocks Up to 24 UDBs PLD-based

Up to 24 UDBs PLD-based

CONNECTIVITY UART, I2C, SPI, USB UART, I2C, SPI, USB, CAN, LIN, I2S

UART, I2C, SPI, USB, CAN, LIN, I2S

I/Os Up to 64 Up to 72 Up to 72

Page 4: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 4

Available Resources Many resources are available for PSoC 3 developers, including datasheets, reference manuals, videos, application notes, and much more.

For Engineers Just Getting Started In addition to this application note, there are other resources for engineers who are very new to PSoC and are interested in exploring it.

Table 2. Resources for New Users

Resource Location

Quick Start Guide

PSoC Creator menu Help Documentation Quick Start Guide

Introduction Video

www.cypress.com/?rID=37516 www.cypress.com/?rID=37513 www.cypress.com/?rID=37514 www.cypress.com/?rID=37515

Quick Start Guide – Another place to start is within PSoC Creator, the integrated development environment for PSoC 3 and PSoC 5. PSoC Creator includes a large collection of documentation and examples including the Quick Start Guide (Figure 4).

Figure 4. Quick Start Guide

Introduction Videos – There are several videos available to introduce PSoC 3 and PSoC Creator. Table 2 lists some specific videos that target engineers who are new to PSoC.

Engineers Looking for More For engineers exploring PSoC 3 for a project or simply to learn, there are many resources available.

Table 3. Developers Looking for More Information

Resource Location Device Datasheet www.cypress.com/?id=2232&rtID=107

Component Datasheet www.cypress.com/?id=2232&rtID=377

Device Errata www.cypress.com/?id=2232&rtID=111 System Reference Guide

PSoC Creator menu Help Documentation System Reference Guide

Application Notes www.cypress.com/?id=2232&rtID=76

Code Examples www.cypress.com/?id=2232&rtID=113

Knowledge Base www.cypress.com/?id=2232&rtID=118

General Help PSoC Creator menu Help Topics

Development Kit Information

www.cypress.com/go/CY8CKIT-001 www.cypress.com/go/CY8CKIT-003 www.cypress.com/go/CY8CKIT-030

Training www.cypress.com/go/training

Device Datasheets – The device datasheet provides a summary of the features, pinouts, device-level specifications and fixed functional peripheral electrical specifications.

Component Datasheets – The flexibility of PSoC allows the creation of components visualized within PSoC Creator. Components can be peripherals that exist natively in PSoC 3 (such as. CAN, USB, and others), or they can be created from the programmable elements within PSoC 3 (such as a UART made from UDBs). For all components released by Cypress there are component datasheets. Component datasheets provide all of the information needed to select and use a particular component, including a functional description, API documentation, example code, and electrical specifications. Component datasheets are available within each component’s configuration window and online; Figure 5 shows an example of the UART with the component datasheet.

Figure 5. UART Configuration Window

Page 5: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 5

Device Errata – Provides details on device deviations when compared to the device datasheet. System Reference Guide – Describes functions supplied by Cypress to provide better access to chip resources. The functions are not part of the component libraries but may be used by them. You can use the function calls to reliably perform needed chip functions such as clock, interrupt DMA, Flash, EEPROM, and Low Power modes. Refer to Documentation on the PSoC Creator Help menu (Figure 6).

Figure 6. System Reference Guide

PSoC Creator Help Topics – PSoC Creator incorporates help (Figure 7) topics that can be useful when exploring PSoC Creator.

Figure 7. PSoC Creator Help

General Training – There is an enormous amount of documentation, code examples, and video on the Cypress web site available to help you get started.

For Advanced Developers Although out of the scope of this application note, documentation is available for advanced developers.

Table 4. Resources for Advanced Developers

Resource Location Architecture Technical Reference Manual www.cypress.com/?rID=35180

Register Technical Reference Manual www.cypress.com/?rID=37833

Component Author Guide

PSoC Creator menu Help Documentation Component Author Guide

Technical Reference Manuals (TRM) – Describes all peripheral functionality in detail, with register-level descriptions. The documentation is divided into two parts, the Architecture TRM and the Register TRM. They are very detailed and very long. Component Author Guide (CAG) – For advanced users who want to create their own distributable components. It provides instructions and information that will help create components for PSoC Creator. Refer to Documentation on the PSoC Creator Help menu.

My First PSoC 3 Design This section has two different flavors depending on your available time and interest. The first portion allows you to build the pre-packaged project and then program your PSoC 3. You start with the known project, and you can explore with the already working design. The second option is more guided. It takes you step by step through design, picking and placing components, drawing nets, and writing some code. By taking this guided approach you will gain an introductory understanding of PSoC Creator, the design environment for PSoC 3 and PSoC 5, while you are getting a first-time look at PSoC 3 and the programmable-system-on-chip concept.

About The Design This design simply blinks two LEDs. One of the LEDs is linked through a pin to the 8051 CPU. Thus firmware controls this LED in what might be referred to as classical MCU fashion. The LED is toggled by the CPU for every rollover of a counter. And the counter in this design is just incremented for every roll of the main() loop. Thus the blink rate is deterministic based on the execution of the main loop. In general, this is not the best approach but sufficient for this demonstration. The second LED blinking function is completely autonomous from the CPU and is driven by logic in a slightly more unique way than the firmware controlled case. To be specific, two PWMs are initialized to generate square waves; however, their periods are set slightly off from each other. The signals are XORed together to generate an output frequency 2x the clock input, and the signal out is connected directly to the output pin (to the LED), a characteristic typical for PSoC (not for an MCU). The slight shift in period causes a beat harmonic that is proportional to the difference in the period. Thus the LED appears to transition on and off as if it is breathing as the output modulates to the beat.

Page 6: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 6

Building My First Design To successfully build this project you will need PSoC Creator Production Release 1.0 or greater. The software is available at: www.cypress.com/go/creator.

Figure 8. About PSoC Creator

The following steps demonstrate building the example project:

1. Open PSoC Creator.

2. Download and unzip the project file that comes with this application note onto your desktop (or a location of your choice).

3. Open the Getting_Started_w_PSoC3.cyprj file from the Getting_Started_w_PSoC3.cydsn folder. When the project opens, all of the project files can be found under the Workspace Explorer as shown in Figure 9.

Figure 9. Workspace Explorer Window

4. Open TopDesign.cysch from the Workspace Explorer

Window to view the project schematic. The schematic view shows all of the currently placed components and how they are logically connected.

Figure 10. Schematic View

5. Select Build Getting_Started_w_PSoC3 from the

Build menu.

Figure 11. Select Build

PSoC Creator builds the project and displays the results in the Output window. When the build succeeds, the device is ready to be programmed.

Figure 12. PSoC Creator Output

Page 7: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 7

Setting Up the CY8CKIT-030 This demonstration is compatible with the CY8CKIT-030 hardware. More information about this kit can be found at: www.cypress.com/go/CY8CKIT-030

Perform the following steps to configure and program the CY8CKIT-030 kit. Note that this particular kit has the programming hardware incorporated on the demonstration board. No extra programming hardware is required to program the PSoC 3.

Figure 13. A View of the CY8CKIT-030 Demo

1. With no cables connected to the demo board, set J10

and J11 to configure the development board for 5 V operation.

Figure 14. Jumper Settings

2. With the USB cable, connect the CY8CKIT-030

(connector J1) to your computer. All of the necessary drivers are included when installing PSoC Creator. If Windows asks for drivers, have Windows find them automatically.

Figure 15. Connect USB

Setting Up the CY8CKIT-003 This demonstration is compatible with the CY8CKIT-003 hardware. More information about this kit can be found at: www.cypress.com/go/CY8CKIT-003

Perform the following steps to configure and program the CY8CKIT-003 kit. Note that this particular kit has the programming hardware incorporated on the demonstration board. No extra programming hardware is required to program the PSoC 3.

Figure 16. A View of the CY8CKIT-003 Demo

1. With no cables connected to the demo board, set J1

and J4 to their default positions. Default is pins 2 and 3 shorted.

2. With the USB cable, connect the CY8CKIT-003 to your computer. All of the necessary drivers are included when installing PSoC Creator. If Windows asks for drivers, have Windows find them automatically.

Figure 17. Connect USB

Page 8: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 8

Setting Up the CY8CKIT-001 This demonstration is compatible with the CY8CKIT-001 hardware. More information about this kit can be found at: www.cypress.com/go/CY8CKIT-001

Perform the following steps to configure and program the CY8CKIT-001 kit. Note that the CY8CKIT-001 requires the MiniProg3 programmer to program the PSoC 3.

Figure 18. View of the CY8CKIT-001 Demo

1. With no cables connected (no power) to the demo

board, set the jumpers to configure the development board as follows:

SW3 – VDD Select. Default Position: 3.3V (down position)

J8 – 5V Source. Default Position: VREG (upper two pins)

J7, J6 – VDD Digital, VDD Analog. Default Position: VDD (upper two pins, both headers)

J12 – LCD Power. Default Position: ON (lower two pins)

J2-J5 – VDDIO Power Select. Default Position: VDD (upper left two pins)

J10 – RS232 Power (Serial Communications). Default Position: Installed

J14 – Radio Power. Default Position: Installed

J11 – Variable Resistor Power. Default Position: Installed

2. Connect P1_6 to LED3 and connect P1_7 to LED4

with jumper wires that are provided with the kit.

Figure 19. Connect the LEDs to the Pins

3. Connect the MiniProg3 to your computer with the

USB cable. All of the necessary drivers are included when installing PSoC Creator. Attach the ribbon cable on the MiniProg3 to the header on the processor module labeled PROG. Then, connect the power. Note: if Windows asks for drivers, have Windows find them automatically.

Figure 20. Connect the Programmer and Power

Page 9: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 9

Programming My First PSoC 3 Programming is the same for all the demonstration boards.

1. From the Debug menu, select Select Debug Target.

Figure 21. Select Debug Target

2. Click Port Acquire.

Figure 22. Configure the Target

3. From the Debug menu, select Program to program

the development board with the previously built design. The programming status is reflected on the PSoC Creator status bar (lower-left corner of the window).

Figure 23. Program the Target

Figure 24. Programming Status

4. On the development board, press Reset to reset the

hardware. Both LED3 and LED4 should be blinking; however, LED3 should be softly transitioning from full on to full off over several seconds.

Creating My First PSoC 3 Design This section takes you step-by-step on a guided tour through the design process. It starts with creating an empty project to design entry and ends with programming your demonstration hardware. 1. From the File menu select New Project.

Figure 25. Select File New Project

Choose Empty PSoC 3 Design project, and give the project a name such as My_First_Project. Choose an appropriate directory for your new project. When finished, a project directory will be generated with a baseline set of files.

Figure 26. Create a New Empty PSoC 3 Project

2. Click on TopDesign.cysch, which links to the working

schematic. Then drag two PWM components from the Component Catalog onto the worksheet (also refer to Figure 29).

Figure 27. Drag PWM to Schematic

3. Configure the PWMs as shown. However, make the

period of one of the PWMs slightly shorter. For example, make PWM_1 Period = 254 and CMP Value = 127. Then, make PWM_2 Period = 252 and CMP Value = 126. The idea is to create a square wave for both PWMs, but with a slightly different operating frequency. The difference will result in a beat frequency that can be modulated on the LED.

Page 10: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 10

Figure 28. Configure the PWMs

4. Drag from the component catalog two Digital Output

Pins, the Logic High and Low functions, the clock, and the XOR logic gate as shown in Figure 29.

Figure 29. Drag the Other Components.

Select the wire tool to connect the logic (also available by pressing ‘w’ as a shortcut).

Figure 30. Select the Wire Tool

Figure 31. Wire the Nets.

a. Wire the clock to both PWM inputs.

b. Wire the logic high and logic low functions to the enable and reset inputs on the PWM.

c. Wire the PWM outputs to each side of the XOR gate.

d. Wire the XOR to an output port pin.

5. Configure the pins for driving the LEDs. The pin connected to the XOR logic will by default be configured appropriately except for a useful name. For readability change the pin name to LED3.

The second pin, which is not connected to any logic, LED4, must be changed to remove its direct hardware input. This allows the CPU to write directly to the pin.

Figure 32. Configure the Pins

Page 11: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 11

6. Configure the clock for 5 kHz and leave all other settings as is.

Figure 33. Set up a Clock Source

At this point all the hardware is set up except for the pins. Although the pins are shown in the schematic, they are not yet associated to a physical pin location (such as P2[0], or P2[1]). The pin association will depend on the demonstration board. Here are the some suggestions based on LED connections and locations on the development boards.

Table 5. Suggested LED Pin Assignment

Demo Board LED3 LED4

CY8CKIT-001 P1[6] P1[7]

CY8CKIT-003 P2[0] P2[1]

CY8CKIT-030 P6[2] P6[3]

Click on My_First_Project.cydwr from the Workspace Explorer, and select the Pins tab. The pins in the design will appear in the list. At this point you can associate the schematic pins to the desired physical pin.

Figure 34. Associate the Pins

7. The hardware portion of the design is done. Before

we transition to writing some firmware, it is best to have PSoC Creator generate all the code that is associated to the components. This is not required; however, it is easier to have the code generated to be able to reference it when you start writing your own firmware routines. Go to Build Generate Application. If there are no errors, PSoC Creator will generate several files that correspond to the project.

8. Now write code to toggle LED4. You can refer to the component datasheet for output pin related APIs; you can also look at the headers. Here is a simple example that you can copy and paste.

Code 1. Main Code for Blinking LED void main() { uint16 count; /* Initialize the PWMs */ PWM_1_Init(); PWM_2_Init(); for(;;) { /* Toggle an LED ON/OFF */ if (count == 0) { LED4_Write(~LED4_ReadDataReg()); } count++; } }

9. Select Build Build My_First_Project from the menu to build your project. At this point (if everything is wired correctly and the code is grammatically correct) the project should build and be ready to program.

10. Refer to the Programming My First Design section to program your project to the target.

Summary The most important concept to be gained from exploring this application note is that PSoC is more than an MCU. PSoC enables engineers to look beyond the processor-centered nature of an MCU.

Contributions Thanks to Todd Dust and Udayan Umapathi who developed the first version of the blinking LED project, and who also wrote and edited the first versions of this application note.

About the Author Name: Ross Fosler

Title: Member of Technical Staff Applications Engineer

Background: Ross is an electrical engineer with several years experience designing digital controls and embedded firmware for numerous silicon and system applications.

His technical interests are real-time embedded processing, control theory, and power electronics.

Contact: [email protected]

Page 12: Author: Ross M. Fosler : Yes : CY8C38xxx : PSoC Creator ...mymcu.ru/storage/content/articles/Cypress/AN54181.pdf · Port A Port B Port C Port D. PSoC is quite different in that it

AN54181

June 24, 2011 Document No. 001-54181 Rev. *F 12

Document History Document Title: Getting Started with PSoC® 3 – AN54181

Document Number: 001-54181

Revision ECN Orig. of Change

Submission Date

Description of Change

** 2724905 TDU 06/26/2009 New Application Note

*A 2749147 FSU 08/06/2009 Minor change to remove the document from the web.

*B 2786097 TDU 10/13/2009 Minor change to post the document to external web.

*C 2880116 TDU 02/17/2010 Updated content from Beta 3 to Beta 4. Changed the Digital Ports to Digital Output Pins.

*D 3048871 UDAY 10/05/2010 Changed title. Added Associated Project. Removed Figure 1. Replaced screenshots. Added FTK programming instructions. Added Additional Resources. Changed pins P0[7] and P1[7] to P2[0] and P2[1], respectively. Edits to Building My First PSoC 3 Design.

*E 3287465 ROSS 06/17/2011 Complete rewrite of the application note. Added discussion about PSoC and the variations between families. Included some specific discussion about PSoC 3. Changed the project design to perform a different kind of blinking. Added support for the CY8CKIT-030.

*F 3292422 ROSS 06/24/2011 Renamed the project file.

PSoC is a registered trademark of Cypress Semiconductor Corporation. PSoC Creator is a trademark of Cypress Semiconductor Corporation. All other trademarks or registered trademarks referenced herein are the property of their respective owners.

Cypress Semiconductor 198 Champion Court

San Jose, CA 95134-1709 Phone: 408-943-2600

Fax: 408-943-4730 http://www.cypress.com/

© Cypress Semiconductor Corporation, 2009-2011. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.

This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress.

Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.

Use may be limited by and subject to the applicable Cypress software license agreement.