The microcontroller MCU handles the LED brightness control

Publisher:电子艺术大师Latest update time:2015-03-14 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Microcontrollers (MCUs) are generally considered digital devices. By default, their output voltage levels are either high or low, not neutral. To achieve the requirement of LED brightness control, the first method that comes to mind is to use a standard digital-to-analog converter or design a controlled resistor network. Fortunately, most modern MCUs have a built-in pulse width modulation (PWM) unit, which is the easiest and lowest cost way to solve this problem.

According to our project requirements, the brightness of the two LEDs must be gradually adjusted from the darkest to the brightest and then from the brightest to the darkest in opposite order within a few seconds. During the "ramp 1" time, the pulse width of the PWM signal for LED 1 gradually increases, while the pulse width of the PWM signal for LED 2 gradually decreases. For example, assume that the ramp time is equal to 2 seconds and consists of 128 up/down steps. Therefore, each step lasts about 16ms. Please note that the pulse width should change only once in one PWM period. Therefore, the PWM period should also be equal to 16ms.

We used a low-end 8-bit Motorola MC68HC908-QT2 Flash MCU, which has an embedded oscillator. Its oscillation frequency is 12.8MHz, and the prescaler ratio is set to 1:64 in the program, and the timer clock period is 0.02 ms. Then, in order to generate a PWM period of 16ms, the number of clocks to be loaded into the timer/counter mode register (Tmod) should be equal to 16/0.02 = 800 (equal to $0320 in hexadecimal).

The maximum pulse width (PWmax) can be less than or equal to the PWM period. Consider the case where PWmax is approximately 15ms. For 128 steps, to get this maximum value from zero, each step value should be 15/128 = 0.117ms, which is rounded to 0.12ms. From this we can get PWmax = 15.36 ms, which is equivalent to 96% of the PWM period. Therefore, in each step, PW should be ramped up/down in increments of 0.12ms (equal to 0.12/0.02 = 6 timer clocks).

Any MCU with PWM and any timing consideration can be used to implement this technique. Resistors R1 and R2 should be selected according to the LED used. Pin pA2 = 1 is used to activate the brightness control and pin pA2 = 0 is used to disable the brightness control.

Reference address:The microcontroller MCU handles the LED brightness control

Previous article:The Current Status and Future of LED Lighting Driving Technology
Next article:Design of LED rotating screen based on AVR

Latest Power Management Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号