
CE219490 – PSoC 6 MCU Ramping LED
using Smart I/O
www.cypress.com Document No. 002-25568 Rev.*A 1
Objective
This example demonstrates the flexibility of Smart I/O in PSoC® 6 MCU, by implementing an LED ramping effect exclusively in
hardware with no CPU usage beyond initialization.
Requirements
Tool: ModusToolbox™ IDE 1.1
Programming Language: C
Associated Parts: All PSoC 6 MCU parts
Related Hardware: PSoC 6 BLE Pioneer Kit, PSoC 6 WiFi-BT Pioneer Kit, PSoC6 WiFi-Prototyping Kit
Overview
This example uses a PWM resource and Smart I/O in PSoC 6 MCU to implement a ramping LED, where an LED gradually
cycles through increasing and decreasing brightness levels. There is no CPU usage except for the initialization of PWM and
Smart I/O.
Hardware Setup
This example uses the kit’s default configuration. See the kit guide to ensure the kit is configured correctly.
Note: The PSoC 6 BLE Pioneer kit and the PSoC 6 WiFi-BT Pioneer kit ship with KitProg2. ModusToolbox only works with
KitProg3. Before using this code example, make sure that the kit is upgraded to KitProg3. See ModusToolbox Help >
ModusToolbox IDE Documentation > User Guide; section PSoC 6 MCU KitProg Firmware Loader. If you do not upgrade, you
will see an error like “unable to find CMSIS-DAP device” or “KitProg firmware is out of date”.
Software Setup
None.
Operation
Follow the instructions that came with your kit to make sure that your kit is connected to your PC
1. Connect the kit to your PC using the provided USB cable.
2. Import the application into a new workspace. See KBA225201.
3. Build the application. Choose Project > Build All.
4. Program the PSoC 6 MCU device. In the project explorer, select the mainapp project. In the Quick Panel, scroll to the
Launches section and click the Program (KitProg3) configuration. Program configurations also build the code.
5. Using a jumper wire, connect P9[4] to P13[7].
You can observe the ramping effect on the LED connected to P13[7] on the kit.
Debugging
You can debug the example to step through the code. Use the Debug (KitProg3) configuration. If you are unfamiliar with how
to start a debug session with ModusToolbox IDE, see KBA224621.

PSoC 6 MCU Ramping LED using Smart I/O
www.cypress.com Document No. 002-25568 Rev.*A 2
Design and Implementation
This design consists of a PWM resource and a Smart I/O resource, both creating square waves of slightly different frequencies.
These square waves are routed through an exclusive-OR (XOR) gate within the Smart I/O resource, yielding a signal with a
gradually changing duty cycle. The rate of change is proportional to the difference between the output square wave frequencies.
The signal is then output to I/O4 of the Smart I/O port 9. Driving LED with this signal results in a “ramping” effect, where the LED
gradually get brighter and dimmer alternately.
The PWM is driven by a 10-kHz clock with a period of 399 counts and a compare value of 200 counts. This gives a 50 percent
duty cycle square wave with a 40-ms period. The Smart I/O is clocked at 99 Hz using a divided clock sourced from CLK_PERI.
This input clock is divided by 4 using the lookup tables (LUTs) of the Smart I/O resource to produce a square wave with a
40.4-ms period.
To generate a square wave signal with a time period close to 40 ms, a 99-Hz clock is divided by 4 using a synchronous sequential
circuit, which is realized using the LUTs of the Smart I/O resource.
To implement a divide-by-4 sequential circuit, consider the state transition values shown in Table 1:
Table 1. State Transition Table for a Divide-by-4 Sequential Circuit
From this state transition table, you can observe that Q0 is half the frequency of Clk_SmartIO and Q1 is 1/4th frequency of
Clk_SmartIO. This sequential logic can be implemented using the LUTs of the Smart I/O resource.
Figure 1 shows the implementation of this logic using LUT 2 and LUT 3. In addition, the divided clock is XORed with the PWM
output using LUT 4 to generate a signal with the duty cycle gradually increasing and decreasing over time. The output of LUT 4
is driven to I/O 4 output.

PSoC 6 MCU Ramping LED using Smart I/O
www.cypress.com Document No. 002-25568 Rev.*A 3
Figure 1. LUT Configuration and Timing Diagram
Q
Q
SET
CLR
D
99 Hz
LUT2
Q
Q
SET
CLR
D
LUT3 LUT4
chip 4 (TCPWM line)
I/O 4 (LED)
99 Hz
LUT2
output
LUT3
Output
(99/4 Hz)
LUT4
output
chip 4
PWM
output
D0
D1
Q0
Q1
Resources and Settings
Table 2 lists the ModusToolbox resources used in this example, and how they are used in the design. For pin usage and
configuration, open the Pins tab of the design.modus file.
Table 2. ModusToolbox Resources
Timer Counter PWM (TCPWM)
Generates 25 Hz, 50% duty cycle square wave
Implements divide-by-4 sequential circuit
Provides visual feedback using the LED
Figure 2 highlights the non-default settings for the TCPWM.