CE210557 PSoC® 4 Timer Interrupt.pdf

CE210557 – PSoC® 4 Timer Interrupt
Objective
This example demonstrates how to generate a periodic interrupt using a fixed-function timer/counter/PWM (TCPWM).
Overview
This example uses a PSoC 4 TCPWM block to generate a periodic interrupt. The interrupt handler function (ISR) toggles a
GPIO pin, causing an LED connected to the pin to blink at a periodic rate.
Requirements
Tool: PSoC Creator™ 3.3 SP1 or higher.
Programming Language: C (GCC 4.9-2015-q1-update),
Associated Parts: All PSoC 4 parts
Related Hardware: All PSoC 4 kits; see Table 1 for pin assignments.
Design
The hardware part of the design features a TCPWM Component, as Figure 1 shows. The TCPWM is configured as a downcounting timer with a terminal count (TC) interrupt. The period is automatically reloaded when the terminal count is reached,
generating a periodic interrupt signal. The interrupt line is connected to an Interrupt Component “isr_Timer”. The Digital Output
Pin “Pin_LED” is used for LED drive. This LED pin is toggled in the ISR.
Figure 1. Periodic Interrupt Generation Schematic
Components
Table 1 lists the PSoC Creator Components used in this example as well as the placement used by each.
Table 1. List of PSoC Creator Components
www.cypress.com
Component
Placement
TCPWM
1 TCPWM, or ~1 UDB
Clock_Timer
1 clock divider
isr_Timer
One entry in interrupt
vector memory
Pin_LED
1 pin
Document No. 002-10557 Rev.**
1
PSoC® 4 Timer Interrupt
Parameter Settings
Figure 2 shows the changed settings for the isr_Timer Component.
Figure 2. isr_Timer Configuration
Figure 3 shows the changed settings for the TCPWM Component.
Figure 3. TCPWM Configuration
www.cypress.com
Document No. 002-10557 Rev.**
2
PSoC® 4 Timer Interrupt
Figure 4 shows the changed settings for the Clock_Timer Component.
Figure 4. Clock_Timer Configuration
Figure 5 shows the changed settings for the Pin_LED Component.
Figure 5. Pin_LED Configuration
Design-Wide Resources
By default, the code example is for development kit CY8CKIT-042. If you are developing the project on other development kit,
change the pin assignment for Pin_LED as per Table 2.
Table 2. Pin Assignment for Pin_LED
www.cypress.com
Name of the component
Port No.
Development Board
Pin_LED
P0[2]
CY8CKIT-042
Pin_LED
P0[2]
CY8CKIT-040
Pin_LED
P2[6]
CY8CKIT-042-BLE
Pin_LED
P2[6]
CY8CKIT-044
Pin_LED
P5[2]
CY8CKIT-046
Document No. 002-10557 Rev.**
3
PSoC® 4 Timer Interrupt
Operation
After the completing the schematic, follow the steps given below to test the project:
1.
Build the project to generate hex file.
2.
Connect the PC to the development board with the USB cable.
3.
Download the hex file to the PSoC 4 chip.
4.
Notice that the LED on development board blinks every second.
Related Documents
Table 3 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component
datasheets.
Table 3. Related Documents
Document
AN79953
AN90799
Title
Comment
®
Getting Started with PSoC 4
PSoC® 4 Interrupts
®
®
Introduces you to PSoC 4, an ARM Cortex®-M0 MCU-based programmable systemon-chip. It helps you explore the architecture and Creator development tools
Provides interrupts architecture and its configuration
AN86439
PSoC 4 - Using GPIO Pins
How to use PSoC 4 GPIO pins effectively and take full advantage of their features.
Major topics include GPIO basics, configuration options, mixed-signal use, registers,
interrupts, and low-power behavior.
AN89610
PSoC® 4 and PSoC 5LP ARM
Cortex Code Optimization
This application note shows how to optimize C and assembler code for the ARM
Cortex CPUs in PSoC 4 and PSoC 5LP. GCC and Keil Microcontroller Development
Kit (MDK) C compilers are supported.
001-94480
System Reference Guide
This System Reference Guide describes functions supplied by the PSoC Creator
cy_boot Component. The cy_boot Component provides the system functionality for a
project to give 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.
CE210558
Timer Interrupt with PSoC® 4
This example demonstrates how to set up PSoC 4 GPIO interrupts. It also shows how
to create your own interrupt handler function (ISR) instead of using the default ISR
generated by PSoC Creator.
CE95400
Watchdog Timer Reset and
Interrupt for PSoC® 4 Devices
This example demonstrates how to use the watchdog in PSoC 4 devices to both reset
the system and wake up from the Deep Sleep low power mode.
PSoC Creator Component Datasheets
TCPWM
The TCPWM component is a multifunction component that implements core microcontroller functionality, including
Timer/Counter, PWM, and Quadrature Decoder using the PSoC 4 TCPWM block.
Clock
Creates local clocks, and allows connection to system and design-wide clocks
Pins
Controls the interface with physical I/O port pins
Interrupt
The Interrupt Component defines hardware triggered interrupts. It also provides a software method to generate an
interrupt.
Device Documentation
PSoC 4 Datasheets
PSoC 4 Technical Reference Manuals
Development Kit (DVK) Documentation
PSoC 4 Kits
www.cypress.com
Document No. 002-10557 Rev.**
4
PSoC® 4 Timer Interrupt
PSoC Resources
Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device for your design, and
quickly and effectively integrate the device into your design. For a comprehensive list of resources, see KBA86521, How to
Design with PSoC 3, PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 4:






Overview: PSoC Portfolio, PSoC Roadmap
Product Selectors: PSoC 1, PSoC 3, PSoC 4, or
PSoC 5LP. In addition, PSoC Creator includes a device
selection tool.
Datasheets
describe
and
provide
electrical
specifications for the PSoC 4 device families
CapSense Design Guide: Learn how to design
capacitive touch-sensing applications with the PSoC 4
family of devices.
Application Notes and Code Examples cover a broad
range of topics, from basic to advanced level. Many of
the application notes include code examples.
Technical Reference Manuals (TRM) provide detailed
descriptions of the architecture and registers in each
PSoC 4 device family.


Development Kits:
 CY8CKIT-042 PSoC 4 Kit, is an easy-to-use and
inexpensive development platform. These kits include
connectors for Arduino™ compatible shields and
Digilent® Pmod™ daughter cards.
 CY8CKIT-044 PSoC 4 Kit, is platform enabling design
and debug of PSoC 4 M-Series devices.
 CY8CKIT-046 is a low-cost hardware and software
platform to enable design and debug of the PSoC 4200L
device.
 CY8CKIT-001 is a common development platform for all
PSoC family devices.
The MiniProg3 device provides an interface for flash
programming and debug.
PSoC Creator
PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware
design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 6 – with PSoC Creator, you can:
1.
Drag and drop Components to build your hardware
system design in the main design workspace
3.
Configure Components using configuration tools
4.
Explore the library of 100+ Components
2.
Codesign your application firmware with the PSoC
hardware
5.
Review Component datasheets
Figure 6. PSoC Creator Features
www.cypress.com
Document No. 002-10557 Rev.**
5
PSoC® 4 Timer Interrupt
Document History
Document Title: CE210557 - PSoC® 4 Timer Interrupt
Document Number: 002-10557
Revision
ECN
**
5096932
www.cypress.com
Orig. of
Change
ASRI
Submission
Date
01/21/2016
Description of Change
New code example
Document No. 002-10557 Rev.**
6
PSoC® 4 Timer Interrupt
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
Automotive
cypress.com/go/automotive
psoc.cypress.com/solutions
Clocks & Buffers
cypress.com/go/clocks
PSoC 1 |PSoC 3 | PSoC 4 |PSoC 5LP
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
Memory
cypress.com/go/memory
PSoC
cypress.com/go/psoc
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Cypress Developer Community
Community | Forums |Blogs | Video |Training
Technical Support
cypress.com/go/support
PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. 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
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2016. 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.
www.cypress.com
Document No. 002-10557 Rev.**
7