Documente Academic
Documente Profesional
Documente Cultură
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.
[+] 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.
[+] 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)
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.
[+] Feedback
AN13943
+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
[+] 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.
[+] Feedback