RGB LEDs - parsing the control circuit

Rgb LEDs, sometimes referred to as 3-color LEDs, are nothing more than a red, green and blue diode combined in a single package. Knowing this, it is easy to imagine how rgb LEDs are arranged. Each of the 3 colors has its own cathode leg, and one more - a common anode. The lead under the anode is the longest, and the cathodes are usually arranged in the following order:

  • blue;
  • green;
  • Red.

To make the device glow with one of the indicated colors, a signal must be applied to the corresponding cathode. If you need some other shade, you can get it using pulse width modulation (PWM, PWM signal). The number of resulting colors depends on how the control is implemented and the width of the PWM. White is also quite easy to obtain - you just need to light all the LEDs at the same time.

RGB LEDs can have a different structure, which determines their main characteristics (how powerful they are, etc.). In the case of a device with a common cathode, each color has its own ignition threshold, separated from the next by a couple of volts. Devices with a common "+" turn on the desired LED when the value is "0" at the output of the microcontroller, and with a common "-" - at "1".

RGB LED control can be implemented on 8-bit microcontrollers of the Pic, AVR family (ATtiny, ATmega) and more powerful models, the program for which is compiled in assembler.

In theory, the legs of microcontrollers should be designed for a certain amount of passing current, but rgb LEDs can be connected through a current-limiting resistor or pnp transistor.

RGB LED control

LED control consists in setting the desired value of their parameters. For this, rectangular pulses of a certain duty cycle should be applied to the outputs, which will affect the value of the average current, and, accordingly, the average brightness.

If the pulse rate is insufficient, the LEDs will flash. In order for them to shine constantly, the lower frequency threshold should be about 60-70 Hz (monitors of older models), and ideally at least 100 Hz (more powerful and modern ones).

In the simplest implementation, controlling an RGB LED would require 3 PWMs. The circuit itself is not that difficult to implement, even if the devices are quite powerful. The task is rather in the correct implementation of the software part.

Low-end controllers, as a rule, do not have not only 3 PWMs, but even 3 timers with interrupts (on the basis of which it is easy to implement PWM). How the control scheme will be implemented should be considered with specific examples, depending on the architecture of a particular device.

Theoretical basis for the implementation of the rgb LED control circuit

First, you need to remember what PWM is. Briefly, this is the operating mode of the device, in which the duty cycle (signal level) is controlled by the microcircuit according to specified algorithms.

To implement a PWM channel, you need to know:

  • algorithm for determining the fill factor (set by the user);
  • timing for the upper level signal;
  • the time of the entire pulse.

In practical implementation, this will require 2 counters, which will work according to the following algorithm:

  1. Start of counters, the output is set to "1".
  2. Interrupt counter # 1 (high level time), the output switches to "0".
  3. Counter # 1 turns off.
  4. Interrupt counter # 2 - repeat all operations from the beginning.

It turns out that the rgb LED control circuit, regardless of how powerful the devices are, should include 2 counters for the PWM channel, that is, 6 in total.

Even if we make the pulse duration the same for all channels, their number will be reduced by 2. Simple controllers will not have 4 counters in any way, but do not forget that the time report is discrete.

Here you need to choose a time slice, which will be multiples of the pulse durations on each channel.

T = 1 / (f * (2 n -1)),

n is the value of the width of the PWM;

f is the frequency.

The circuit can include 1 counter for counting the interval T. In order for it to perform the required function, 4 settings must be set:

  1. The number of high-level samples for 1 PWM channel.
  2. Number of high level samples for 2 PWM channels.
  3. Number of high level samples for 3 PWM channels.
  4. Total pulse duration.

Other operations for the software counter (switching, zeroing, etc.) are performed by interrupts of the hardware counter.

This algorithm is just an example of a control circuit, the operation of which can differ significantly, depending on the microcontroller used and also on how exactly the LEDs are planned to be used. More powerful devices can also operate on LED strips.