Microcontroller Handles LED Brightness Control

Dec. 8, 2004
Usually, an MCU is considered a digital device. By default, its output voltage level can be either high or low and nothing in between. With the requirement to create an LED brightness control, the first idea that comes to mind is using a standard...

Usually, an MCU is considered a digital device. By default, its output voltage level can be either high or low and nothing in between. With the requirement to create an LED brightness control, the first idea that comes to mind is using a standard digital-to-analog converter, or design a controlled resistor network. Luckily, most modern MCUs have built-in pulse-width modulation (PWM), and this leads to the easiest and cheapest way to solve the problem.

According to our project requirements, the brightness of two LEDs has to be gradually changed from minimum to maximum and back, in the opposite phase and in a time of about several seconds. Also, the several seconds of delay between the ramps should be as shown in Figure 1. During Ramp 1 time, the PWM signal's pulse width is incremented for LED 1 and decremented for LED 2. For example, let's have the ramp time equal 2 seconds and consist of 128 up/down steps. Thus, each step lasts about 16 ms. Note that the pulse-width change should occur only once during the PWM period. Hence, the PWM period should also equal 16 ms.

The low-end 8-bit Motorola MC68HC908-QT2 flash MCU with built-in oscillator is used. Its oscillation frequency equals 12.8 MHz, together with the prescaler programmed to a selection of 1:64, and supplies a timer clock period of 0.02 ms. Then, to generate a PWM with a 16-ms period, the number of clocks to be loaded into Timer Counter Modulo Register (Tmod) should equal 16/0.02 = 800, or $0320 in hexadecimal.

The maximum pulse width (PWMAX) can be less than or equal to the PWM period. Consider PWmax to be equal to about 15 ms. To get this maximum value from zero, for 128 steps, each step should have a value of 15/128 = 0.117 ms. By rounding it to 0.12 ms, we get PWMAX = 15.36 ms , i.e., 96% of the PWM period. Thus, in each step, the PW should ramp up/down on 0.12-ms increments, equal to 0.12/0.02 = 6 timer clocks.

Any type of MCU with PWM and any timing consideration can be used to implement this technique. Resistors R1 and R2 should be chosen according to the LEDs used. Pin pA2 is used to activate (pA2 =1) or deactivate (pA2=0) the brightness control.

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!