Sunteți pe pagina 1din 5

Application Note AN13943

Multichannel LED Dimmer with CapSense Control – AN13943

Author: Victor Kremin, Michael Makovetskij


Associated Project: Yes
Associated Part Family: CY8C21xxx
GET FREE SAMPLES HERE
Software Version: PSoC Designer™ 4.4
Associated Application Notes: AN2233a, AN2292, AN2318, AN2352, AN2355, AN2357
PSoC Application Notes Index

Abstract
This Application Note describes a multichannel LED dimmer controlled by capacitive sensors. The dimmer is capable of
setting the brightness of individual LEDs with nice fade effects.

Introduction When the button is deactivated, the LED brightness drops


smoothly back to 10% if the proximity sensor is still active
This Application Note demonstrates the PSoC’s ability to (meaning a hand is close to the device) or 0.5% when the
manage multiple LEDs with individual brightness control proximity sensor is not active, marking the device’s return
together with CapSense functions. The fade-in/fade-out to sleep mode. The fade-in and fade-out time is
effects are implemented for each LED individually, approximately one second, which provides a nice visual
activated by a proximity sensor or by touching a effect when a button is highlighted.
CapSense button. The associated design can be used as
All possible states of available capacitive sensors and
the foundation for a CapSense-driven key entry for media
corresponding LEDs are shown in Table 2.
players, digital radios/TVs, car electronics, children’s toys,
and various home appliances. Table 2. Touch Sensor and LED States
This design has four capacitive button sensors with Touch Proximity
individual status LEDs and one proximity sensor. The LED State
Sensor Sensor
device characteristics are summarized in Table 1. (Light Intensity In %)
State State
Table 1. Device Characteristics Off Off 0.5%
Off On Fade-in to 10% for all LEDs
Characteristic Value
On On or Off Fade-in to 100% for sensor LED
Capacitance Sensing Technique CSD
Off On Fade-out to 10% for sensor LED
Proximity Sensor Count 1
Off Off Fade-out to 0.5% for sensor LED
Proximity Sensor Sensitivity 10-14 cm
Touch Sensor Count 4 Figure 1 shows how the LED light intensity changes
depending on how long a hand is in range of the proximity
Power Supply Voltage 5 ± 0.25V
sensor, and whether or not it touches the sensor. If the
The device functions as follows. At power on, the hand does not touch the sensor, the brightness of the LED
brightness of all LEDs is set to 0.5% of maximum steadily increases the longer the hand is in range of the
brightness. This highlights the buttons in the dark. When sensor (up to 10% of maximum brightness). If the hand
the user places a hand near the device, the proximity does touch the sensor, the LED brightness level increases
sensor is activated and the brightness of all LEDs is to the maximum.
smoothly increased to 10%. This state reflects the
readiness of the device to accept commands. After
touching a sensor, the corresponding LED light intensity
smoothly increases to 100%.

July 20, 2007 Document No. 001-13943 Rev. ** -1-

[+] Feedback
AN13943

Figure 1. LED Fading If more CPU resources are needed, the 24 MHz CPU
clock can be used, or the hardware counter interrupt rate
Light can be reduced. Alternative implementations of the
Intensity software PWM can include the variable period or pseudo-
100% random source, sigma-delta modulators, etc. See
AN2357, “Multi-Channel Fan Speed Control System” for
one alternative based on the software sigma-delta
10% modulator.
An additional interval timer sets the sample rate to
smoothly change the light intensity for the fading control
0.5% software module. Fading control changes the duty cycle
1 2 3 4 5 6 7 8
for all software PWMs according to the capacitive sensor
states and the LED fading control algorithm. Taking into
Time account that the sensor scanning time with the CSD UM is
constant, this time is used as a timebase for the LED
1- Button Not Active, Proximity Not Active fading timer. This timer triggers an LED brightness update
2- Button Not Active, Proximity Active (Fade-In) every 6.8 ms. The LED dimming control functional
3- Button Not Active, Proximity Active diagram is shown in Figure 2.
4- Button Active, Proximity Active ( Fade-In)
5- Button Active, Proximity Active Figure 2. LED Dimming Functional Diagram
6- Button Not Active, Proximity Active (Fade-Out)
7- Button Not Active, Proximity Active Vdd
8- Button Not Active, Proximity Not Active (Fade-Out)

LED1
CapSense Configuration Hardware Interrupt
Counter
Software
Duty Cycle 1
The PSoC® firmware serves two functions: capacitive PWM1
sensor scanning and LED dimming. The scanning sensors
process the touch and proximity sensors’ state and pass Vdd
the information to the LED dimming control function. The
CSD User Module (UM) is used for sensor scanning. The
sensors are scanned with different resolutions, and the LED2
proximity sensor is scanned with a higher resolution to Software
obtain the maximum operational range. Table 3 Fading Duty Cycle 2
Control
PWM2
summarizes the settings. At the listed settings, the total
sensor scanning time is 24 ms. Vdd
Table 3. Sensor Scanning Parameters
Resolution Scanning Scanning Time LEDn
Sensor Interval
(Bits) Speed (ms) Timer Software
Proximity 14 Fast 5.8 PWMn
Duty Cycle n
Button 12 Normal 1
The human eye’s sensitivity to a light source’s brightness
looks like a logarithmic function (Figure 3). To provide a
Multichannel LED Dimming visible linear brightness change, the PWM duty cycle
The CSD UM occupies three digital blocks, leaving only should be changed in an exponential way.
one block for other purposes. There are insufficient
resources to allocate a hardware (digital block) PWM for
each LED state. Software PWMs are used to control LED
brightness. A single hardware timer generates periodic
interrupts for updating multiple software PWMs. Each
software PWM controls a PSoC GPIO pin that drives an
associated LED. A simple, fixed-period PWM source has
been emulated in the firmware. The hardware PWM timer
interrupt rate is 25 kHz and the software PWM resolution
is 8 bits, pushing the LED drive output frequency to 98 Hz,
which guarantees blink-free operation. The timer ISR
execution time is 13 µs, consuming only 30% of CPU
resources at a 12 MHz core frequency.

July 20, 2007 Document No. 001-13943 Rev. ** -2-

[+] Feedback
AN13943

Figure 3. Human Eye Brightness Perception vs. LED Another way is to us a computer graphic algorithm that
Luminous Flux obtains maximum flexibility in setting the LED fading
parameters. This project uses Bresenham’s line algorithm
[1] to create LED fade in/out effects. Generating fade
Visible effects can be thought of as the need to change the
Brightness brightness level from value y1 at point of time t1 to value y2
at point of time t2, (Figure 5). The Bresenham algorithm
allows you to arbitrarily set the fade effect duration and is
characterized by low computation integer arithmetic (only
adding/comparison operations are required).
Figure 5. The Fade Effect as Line Drawing

Light Source
Brightness (t2, y2)

The linear brightness levels are transferred to exponential


duty cycle values using the lookup table. The following
expression is used for the conversion:

N out = A ( exp ( N in ⋅ b ) − 1) ;
N max
A= ; (t1, y1)
exp ( N max ⋅ b ) − 1
Figure 4 illustrates the table graphs at different values of
parameter b. Note that Nmax has been set to 255. This t
expression converts an 8-bit unsigned BYTE value to the
same range. In Figure 4, you can easily see that the Parameters Customization
transfer characteristic becomes more exponential as the b The design parameters can be easily customized for
parameter increases. different applications. This example has three different
Figure 4. The LED Duty Cycle Conversion Table LED brightness levels that are set in the leddimerhl.h file:
LowLevel, MiddleLevel, and HighLevel. The fade-in/fade-
LED Lookup table out time can be adjusted by tuning the constants
250 TimeFadeOn and TimeFadeOff. Note that if you change
b =0.005
b =0.014
the CSD UM parameters, you need to adjust hardware
b =0.023 counter period in order to obtain the desired interrupt
200
b =0.032 frequency because the counter is driven by the VC2
b =0.041 source and VC1/VC2 dividers are varied by changing the
CSD UM resolution/scanning speed.
Nou t

150

Device Schematic
100
A schematic of the CapSense-based LED dimmer is
shown in Figure 6. The dimmer project was implemented
50 using the standard CY3213A-CAPSENSE CapSense
Sigma-Delta (CSD) Training Kit board with the sensor
LEDs connected to the LCD connector pins.
0
0 50 100 150 200 250
Nin

LED Fading
There are several ways to create LED fade effects. One
possible way is to use a digital low pass filter and apply a
step input signal. A filter response at different points in
time can also be used for fading.

July 20, 2007 Document No. 001-13943 Rev. ** -3-

[+] Feedback
AN13943

• Many applications can use springs between the PCB


Construction Recommendations for and the case panel. In this example, the LED can be
LED-Illuminated CapSense Buttons installed in the center of the spring, and located on
the same side as the spring. The recommended
When a project places LEDs under button sensors, the spring diameter is 10 mm or more; for thick overlays,
following recommendations can help achieve the best the larger diameter springs are recommended for
results: better propagation of electric fields over the
insulators.
• The hole in the PCB should be located at the center
of the button, on the opposite side of the PCB. In this
case, the special surface mount device reverse References
mounting LED should be used.
1. Bresenham's line algorithm is available online at:
• The LED port pin drive mode should be set to http://en.wikipedia.org/wiki/Bresenham's_line_algorith
STRONG (depending on port data) at all times to m.
connect the LED pin to Vss or Vdd.
• Light diffuser/pipe/micro lenses (special plastic, silicon
rubber, etc.) can be used to provide uniform
illumination of the button shape. Diffuser thickness
needs to be determined in order to obtain uniform
LED illumination and the appropriate CapSense
system signal-to-noise ratio.

Figure 6. Device Schematic

+5V

C1 C2
R1 R2 10nF 0,1uF R4 R3
330 330 330 330

D1 D2 U1 D3 D4
CY 8C21434
32
31
30
29
28
27
26
25
Vdd
Vss
P0[3]
P0[5]
P0[7]

P0[6]
P0[4]
P0[2]

1 24
LedBtn_0 2 P0[1] P0[0] 23 LedBtn_1
3 P2[7] P2[6] 22 LedBtn_2
LedBtn_3 4 P2[5] P2[4] 21
5 P2[3] P2[2] 20
R5 1k 6 P2[1] P2[0] 19 1k R6 BTN1
7 P3[3] P3[2] 18
PROXIMITY 1 8 P3[1] P3[0] 17
P1[7] XRES
P1[5]
P1[3]
P1[1]

P1[0]
P1[2]
P1[4]
P1[6]
Vss

1k R7 BTN2
2.2k R8
9
10
11
12
13
14
15
16

1k R9 BTN3
ISSP
5 1k R10 BTN4
4
3
2
1 +5V

J1

July 20, 2007 Document No. 001-13943 Rev. ** -4-

[+] Feedback
AN13943

PSoC Designer™, Programmable System-on-Chip™, and PSoC Express™ are trademarks and PSoC® is a registered trademark of Cypress
Semiconductor Corp. All other trademarks or registered trademarks referenced herein are property of the respective corporations.

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, 2007. 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.

July 20, 2007 Document No. 001-13943 Rev. ** -5-

[+] Feedback

S-ar putea să vă placă și