Computer literacy, assistance and repair

Adjusting the brightness of LEDs. PWM controller

A pulse-width modulated signal is very often used in electronics to transmit information, regulate power, or generate a constant voltage of an arbitrary level. This article describes an operational amplifier device, 20x20mm in size, made of 15 elements, which generates a PWM signal.

A PWM signal (PWM) is a sequence of pulses, the frequency of which is constant, and the duration of the pulses is modulated. Most microcontrollers easily cope with this task, but what if you don’t want to program and use such a powerful tool for such a simple task? In this case, discrete elements can be used.

First, you need to generate a sequence of sawtooth pulses and apply it to the input of the comparator. A modulating signal, for example, voltage from a variable resistor, is supplied to the second input of the comparator. If the generator voltage is higher than the voltage at the second input, the output voltage is close to the supply voltage. If the generator voltage is lower, the output is zero.

In the figure, Uк is the command voltage (constant level set by a variable resistor), Ugen is the generator voltage, UPWM is the PWM signal.

Scheme

All these tasks can be easily accomplished using two operational amplifiers as shown in the diagram.

The circuit uses the LM358N chip, which uses single-supply power and contains two channels in one SO8 package.

Printed circuit board

All elements, except resistor R3, are designed for surface mounting and are located on the board with a minimum size. R3 is located on the back of the board. Oscillator circuits are very capricious from the point of view of tracing printed circuit boards. If you change the board topology, its functionality cannot be guaranteed. The first version of the board generated a sawtooth voltage with very low amplitude and was unusable.

Assembly and operation of the circuit

The board itself is very small - 20x20 mm and can be easily manufactured using the LUT method. It is only slightly larger than a variable resistor that changes the duty cycle of the signal.

Specifications

  • supply voltage, 5-15V
  • duty cycle range, from 1 to infinity
  • operating frequency, 500Hz
  • current consumption, no more than 2mA

The operating frequency is determined by capacitor C1. To reduce the frequency, you can increase its capacity and vice versa.

List of elements

  1. IC LM358N in SO8 (DA1) package, 1 pc.
  2. Resistors 20 kOhm in housing 0805 (R1, R2, R4-R6), 5 pcs.
  3. Resistors 10 kOhm in housing 0805 (R7, R8), 2 pcs.
  4. Any variable resistor with a lead pitch of 5 mm and a resistance of 50 kOhm
  5. Capacitors 0.1 µF in housing 0805 (C1, C2, C4), 3 pcs.
  6. Tantalum capacitor 47uF, 16V, size C, T491C476K016AT (C3), 1 pc.

Video of work

The board operates quite stably. The video shows how the brightness of the LED changes. The only inconvenience is that only half of the range of resistor R3 is used. That is, in the first and last quarter of the shaft position, the voltage remains unchanged.

Photo of the generator.

What can this generator do? Let's take a look at the parameters.

  1. Operating voltage: 3.3 - 30V;
  2. Generation frequency: 1Hz - 150KHz;
  3. Frequency generation accuracy: 2%;
  4. Load power: 5…30mA;
  5. The amplitude of the output signal is equal to the supply voltage;
  6. Ambient temperature: -20 … +70 °C.

Only 2 numbers of 3 digits each can be displayed. The bottom line displays the PWM duty cycle as a percentage, and the top line displays the frequency. The frequency is displayed according to the following rules:

  • XXX, 1Hz step, range 1 – 999Hz;
  • X.XX, step in 0.01 kHz, in the range 1.00 - 9.99 kHz;
  • XX.X, step in 0.1 kHz; in the range 10.0 - 99.9 kHz;
  • X.X.X, 1 kHz step; in the range 100 - 150 kHz.

The display is controlled by the HT1621B chip, the display is universal, it contains the symbols necessary to build a thermometer, hygrometer, voltmeter, ammeter and wattmeter, but in our case they are not used. The display has a bright blue backlight. By the way, I note that the display on my generator turned out to be shabby, as if it had been removed from somewhere.

The main chip of the generator is the STM8S003F3P6 microcontroller. And since this microcontroller has EEPROM memory, the settings are saved when turned off.

You can control the generator in two ways: buttons and via UART. Everything is clear with the buttons, one pair of buttons controls the frequency, the second the duty cycle. But with UART everything is much more interesting. Data exchange must occur with the following parameters:

  • 9600 bps Data bits: 8
  • Stop bit: 1
  • Check digit: none
  • Flow control: none

In order to set the generation frequency, you need to send the frequency as it is displayed on the display by adding the letter F in front of the frequency value. For example, to set the frequency to 100 Hz you need to send F100, for 105 kHz - F1.0.5, for 10.5 kHz - F10 .5 and so on.

To set the duty cycle, you must send a three-digit duty cycle number by adding the letter D in front of it. For example, D050, D100, D001.

If a correct command is sent, the generator will respond DOWN, if an incorrect one - FALL. But there is one BUT, I was never able to configure work with the generator via UART.

I decided to test the generator using a logic analyzer. This is what happened.

Frequency 1 Hz, duty cycle 1%. As we can see, the error is still small.

Frequency 1 Hz, duty cycle 50%.

Frequency 1 Hz, duty cycle 99%.

Frequency 1 kHz, duty cycle 1%.

Frequency 1 kHz, duty cycle 50%.

Frequency 1 kHz, duty cycle 99%. Here we see that with the duty cycle set to 99%, the fill is actually 100%.

Frequency 1 kHz, duty cycle 91%. I began to reduce the duty cycle, and up to 92% the filling was 100%, and only at 91% the situation improved.

Frequency 50 kHz, duty cycle 1%. As you can see, it’s only 0.2% instead of 1%.

Frequency 50 kHz, duty cycle 50%. Here it differs by 1%.

Frequency 50 kHz, duty cycle 99%. And here again the deviation is -1%.

Frequency 100 kHz, duty cycle 1%. But there’s nothing here yet.

Frequency 100 kHz, duty cycle 2%. And at 2% the signal appears, but in fact the filling is 0.4%.

Frequency 100 kHz, duty cycle 50%. The deviation is almost -2%.

Frequency 100 kHz, duty cycle 99%. And here it’s almost -1%.

Frequency 150 kHz, duty cycle 1%. No signal again.

Frequency 150 Hz, duty cycle 3%. And the signal appears only at 3%, but the filling is 0.6%.

Frequency 150 kHz, duty cycle 50%. But in fact, the filling is 46.5%, a difference of -3.5%.

Frequency 150 kHz, duty cycle 99%. And there is an error, but only 1.5%.

The sample is quite rough, but the research is not over yet. I decided to measure the duty cycle at different duty cycles (5% steps) and at different frequencies (25000 Hz steps) and put them in a table.

Necessity DC voltage regulation to power powerful inertial loads most often occurs among owners of cars and other auto-moto equipment. For example, there was a desire to smoothly change the brightness of interior lighting lamps, side lights, car headlights, or the unit for regulating the speed of the car air conditioner fan failed, and there is no replacement.
Sometimes it is not possible to fulfill such a desire due to the high current consumption of these devices - if you install transistor voltage regulator, compensation or parametric, the regulating transistor will release very high power, which will require the installation of large radiators or the introduction of forced cooling using a small fan from computer devices.

The way out is to use pulse-width circuits that control powerful field-effect power transistors MOSFET . These transistors can switch very high currents (up to 160A or more) with a gate voltage of 12 - 15 V. The resistance of an open transistor is very low, which allows for a significant reduction in power dissipation. Control circuits must ensure a voltage difference between gate and source of at least 12 ... 15 V, otherwise the channel resistance increases greatly and power dissipation increases significantly, which can lead to overheating of the transistor and its failure. For pulse-width automotive low-voltage regulators, specialized microcircuits are produced, for example U 6 080B ... U6084B , L9610, L9611, which contain a unit for increasing the output voltage to 25 -30 V with a supply voltage of 7 -14 V, which allows you to turn on the output transistor according to a circuit with a common drain, so that you can connect a load with a common minus, but it is almost impossible to get them. For most loads that consume no more than 10A current and cannot cause sag onboard voltage you can use simple circuits without an additional voltage booster unit.

First PWM regulator assembled atlogic K invertersMOS chips. The circuit is a generator of rectangular pulses on two logic elements, in which, due to diodes, the time constant of charging and discharging the frequency-setting capacitor is changed separately, which allows you to change the duty cycle of the output pulses and the value of the effective voltage on the load.

The circuit can use any inverting CMOS elements, for example K176PU2, K561LN1, as well as any AND, OR-NOT elements, for example K561LA7, K561LE5 and the like, grouping their inputs accordingly. The field effect transistor can be any of MOSFET, which can withstand the maximum load current, but it is advisable to use a transistor with as high a maximum current as possible, because it has lower open-channel resistance, which reduces power dissipation and allows the use of a smaller radiator area.
Advantages of the PWM controller on the K561LN2 chip - simplicity and accessibility of elements,
flaws- the range of changes in the output voltage is slightly less than 100% and it is impossible to modify the circuit in order to introduce additional modes, for example, a smooth automatic increase or decrease in voltage at the load, because regulation is carried out by changing the resistance of a variable resistor, and not by changing the level of the control voltage.

The second scheme has much better characteristics, but the number of elements in it is slightly larger.

The effective voltage value on the load is adjusted from 0 to 12 V by changing the voltage at the control input from 8 to 12 V. The voltage adjustment range is almost 100%. The maximum load current is entirely determined by the type of power field-effect transistor and can be very significant. Since the output voltage is proportional to the input control voltage, the circuit can be used as an integral part of a control system, for example, a system for maintaining a given temperature, if a heater is used as a load and a temperature sensor is connected to a simple proportional controller, the output of which is connected to the control input of the device. The described devices are based on an asymmetrical multivibrator, but PWM regulator can be built on a waiting multivibrator chip

A simple modulated generator is proposed that can be used to generate and process various signals in amateur radio devices.

First, let's look at the circuit of a rectangular pulse generator (Fig. 1), which is made on two RS flip-flops from the logic elements of a MOS or CMOS microcircuit.

The flip-flops will remain in this state until the log level appears at input 1. 0. This time is determined by the input capacitance C2, the input leakage current* and the difference between the log voltage. 1 (approximately equal to Upit) and the threshold voltage of the microcircuit (about half Upit): t = C2-(Upup·Upor)·Iut.

After the capacitance C2 is discharged to the threshold voltage, the second trigger will switch again, C2 will be charged again and the discharge of C1 will begin. When the threshold voltage is reached, the second trigger will switch again; Subsequently, the processes are repeated.

The duration of the pulses in such a generator can be controlled by changing the discharge current of the input capacitances of the logic elements. Based on this principle, a generator with pulse width modulation can be built.

Let's consider this modulation option in more detail. We will connect two current sources controlled by a modulated signal to inputs 1 and 6 of DD1 elements (Fig. 2). When the input signal changes, the current of one source increases by ΔI, and the current of the other decreases by ΔI.

Accordingly, one period will be: T = t1+ t2 = C1 X Upor/(I + ΔI) + C2 x X Upor/(I - ΔI).

As can be seen from the formula, the greater the discharge current of the input capacitors, the shorter the period and, accordingly, the higher the frequency of the modulator.

Restoring the original (modulating) signal is possible using a simple integrating circuit, at the output of which, at a constant pulse amplitude (Uamp), the output voltage will be: Uout = Uamp x t1(t1+t2). It is easy to conclude that with ΔI = 0, identical input capacitances and threshold voltages of the logic element inputs, a voltage close in value to half the supply voltage will operate at the output of the integrating circuit. The change in output voltage and the transmission coefficient for the modulating signal correspond to the expressions: ΔUout = Uamp X ΔI/2I; K = ΔUout/ΔUin = (Uamp/2I)∙(2I/Ut) = Uamp/Ut, where Ut is the temperature voltage equal to 26 mV at a temperature of 300 K.

One more note. Under the influence of the input signal, both the pulse duration and the pause duration change. The pulse frequency also changes slightly: as the input signal increases, it decreases. This determines the fairly large dynamic range of the device. A practical generator circuit is shown in Fig. 3. Its elements were selected for reasons of availability and repeatability of parameters.

The input differential stage (VT1, VT2) is made on KT315 bipolar transistors (with any letter index), preferably with similar base current transfer coefficients. The diodes used were KD102 with low reverse current. To increase the stability of the generator, negative feedback is introduced into the circuit from output 4 through a low-frequency filter consisting of resistor R5, capacitor C2 and resistor R4 with a cutoff frequency of about 16 Hz.

In some cases, for example, in flashlights or home lighting devices, it becomes necessary to adjust the brightness of the glow. It would seem that nothing could be simpler: just change the current through the LED, increasing or decreasing . But in this case, a significant part of the energy will be spent on the limiting resistor, which is completely unacceptable when powered independently from batteries or rechargeable batteries.

In addition, the color of the LEDs will change: for example, the white color will have a slightly greenish tint when the current drops below the nominal (for most LEDs 20mA). In some cases, such a change in color is completely unnecessary. Imagine these LEDs illuminating a TV screen or computer monitor.

In these cases it applies PWM - regulation (pulse width). Its meaning is that it periodically lights up and goes out. In this case, the current remains nominal throughout the flash, so the glow spectrum is not distorted. If the LED is white, then green shades will not appear.

In addition, with this method of power regulation, energy losses are minimal, the efficiency of circuits with PWM control is very high, reaching more than 90 percent.

The principle of PWM control is quite simple, and is shown in Figure 1. The different ratio of the time of the lit and extinguished state is perceived by the eye as: like in a movie - separately shown frames are perceived as a moving image. Here everything depends on the frequency of projection, which will be discussed a little later.

Figure 1. Principle of PWM regulation

The figure shows diagrams of the signals at the output of the PWM control device (or master oscillator). Zero and one are designated: a logical one (high level) causes the LED to glow, a logical zero (low level) causes it to go out.

Although everything can be the other way around, since everything depends on the circuit design of the output switch - the LED can be turned on at a low level and turned off at a high level. In this case, physically a logical one will have a low voltage level, and a logical zero will have a high voltage level.

In other words, a logical one causes the activation of some event or process (in our case, the illumination of an LED), and a logical zero should disable this process. That is, the high level at the output of a digital microcircuit is not always a LOGICAL unit, it all depends on how the specific circuit is built. This is just for information. But for now we will assume that the key is controlled at a high level, and it simply cannot be any other way.

Frequency and width of control pulses

It should be noted that the pulse repetition period (or frequency) remains unchanged. But, in general, the pulse frequency does not affect the brightness of the glow, therefore, there are no special requirements for frequency stability. Only the duration (WIDTH) changes, in in this case, a positive pulse, due to which the entire pulse-width modulation mechanism works.

The duration of control pulses in Figure 1 is expressed in %%. This is the so-called “fill factor” or, in English terminology, DUTY CYCLE. It is expressed as the ratio of the duration of the control pulse to the pulse repetition period.

In Russian terminology it is usually used “duty factor” - the ratio of the repetition period to the pulse time A. Thus, if the fill factor is 50%, then the duty cycle will be equal to 2. There is no fundamental difference here, therefore, you can use any of these values, whichever is more convenient and understandable for you.

Here, of course, we could give formulas for calculating duty cycle and DUTY CYCLE, but in order not to complicate the presentation, we will do without formulas. As a last resort, Ohm's law. There’s nothing you can do about it: “If you don’t know Ohm’s law, stay at home!” If anyone is interested in these formulas, they can always be found on the Internet.

PWM frequency for dimmer

As was said just above, there are no special requirements for the stability of the PWM pulse frequency: well, it “floats” a little, but that’s okay. By the way, PWM regulators have similar frequency instability, which is quite large, which does not interfere with their use in many designs. In this case, it is only important that this frequency does not fall below a certain value.

What should the frequency be, and how unstable can it be? Don't forget that we are talking about dimmers. In film technology there is a term “critical flicker frequency”. This is the frequency at which individual pictures shown one after another are perceived as a moving image. For the human eye, this frequency is 48Hz.

It is for this reason that the shooting frequency on film was 24 frames/sec (the television standard is 25 frames/sec). To increase this frequency to a critical one, film projectors use a two-bladed shutter (shutter) that twice overlaps each displayed frame.

In amateur narrow-film 8mm projectors, the projection frequency was 16 frames/sec, so the shutter had as many as three blades. The same goals in television are served by the fact that the image is shown in half-frames: first even, and then odd lines of the image. The result is a flicker frequency of 50Hz.

LED operation in PWM mode consists of individual flashes of adjustable duration. In order for these flashes to be perceived by the eye as a continuous glow, their frequency must be no less than the critical one. You can go as high as you like, but you can't go lower. This factor should be taken into account when creating PWM regulators for lamps.

By the way, just as an interesting fact: scientists have somehow determined that the critical frequency for a bee's eye is 800Hz. Therefore, the bee will see the movie on the screen as a sequence of individual images. In order for her to see a moving image, the projection frequency will need to be increased to eight hundred half-frames per second!

To control the LED itself, it is used. Recently, the most widely used for this purpose are those that allow switching significant power (the use of conventional bipolar transistors for these purposes is considered simply indecent).

Such a need (a powerful MOSFET - transistor) arises with a large number of LEDs, for example, with, which will be discussed a little later. If the power is low - when using one or two LEDs, you can use low-power switches, and if possible, connect the LEDs directly to the outputs of the microcircuits.

Figure 2 shows the functional diagram of a PWM regulator. The diagram conventionally shows resistor R2 as a control element. By rotating its knob, you can change the duty cycle of the control pulses, and, consequently, the brightness of the LEDs, within the required limits.

Figure 2. Functional diagram of a PWM regulator

The figure shows three chains of LEDs connected in series with limiting resistors. Approximately the same connection is used in LED strips. The longer the strip, the more LEDs, the greater the current consumption.

It is in these cases that powerful ones will be required, the permissible drain current of which should be slightly greater than the current consumed by the tape. The last requirement is satisfied quite easily: for example, the IRL2505 transistor has a drain current of about 100A, a drain voltage of 55V, while its dimensions and price are quite attractive for use in various designs.

PWM master generators

A microcontroller can be used as a master PWM generator (most often in industrial settings), or a circuit made on low-integration microcircuits. If you plan to make a small number of PWM regulators at home, and there is no experience in creating microcontroller devices, then it is better to make a regulator using what is currently at hand.

These can be logical chips of the K561 series, an integrated timer, as well as specialized chips designed for. In this role, you can even make it work by assembling an adjustable generator on it, but this, perhaps, is “for the love of art.” Therefore, only two circuits will be considered below: the most common one on the 555 timer, and on the UC3843 UPS controller.

Master oscillator circuit based on 555 timer

Figure 3. Master oscillator circuit

This circuit is a conventional square-wave generator, the frequency of which is set by capacitor C1. The capacitor is charged through the circuit “Output - R2 - RP1- C1 - common wire”. In this case, a high level voltage must be present at the output, which means that the output is connected to the positive pole of the power source.

The capacitor is discharged along the circuit “C1 - VD2 - R2 - Output - common wire” at a time when there is a low level voltage at the output - the output is connected to the common wire. It is this difference in the charge and discharge paths of the timing capacitor that ensures the receipt of pulses with an adjustable width.

It should be noted that diodes, even of the same type, have different parameters. In this case, their electrical capacitance plays a role, which changes under the influence of voltage on the diodes. Therefore, along with a change in the duty cycle of the output signal, its frequency also changes.

The main thing is that it does not become less than the critical frequency, which was mentioned just above. Otherwise, instead of a uniform glow with different brightness, individual flashes will be visible.

Approximately (again, the diodes are to blame), the frequency of the generator can be determined by the formula shown below.

PWM generator frequency on timer 555.

If you substitute the capacitance of the capacitor in farads and the resistance in Ohms into the formula, then the result should be in hertz Hz: there is no escape from the SI system! This assumes that the variable resistor RP1 slider is in the middle position (in the RP1/2 formula), which corresponds to a square wave output signal. In Figure 2, this is exactly the part where the pulse duration is 50%, which is equivalent to a signal with a duty cycle of 2.

Master PWM generator on UC3843 chip

Its diagram is shown in Figure 4.

Figure 4. Circuit of the PWM master oscillator on the UC3843 chip

The UC3843 chip is a PWM controller for switching power supplies and is used, for example, in ATX format computer sources. In this case, the typical scheme for its inclusion has been slightly changed towards simplification. To control the width of the output pulse, a control voltage of positive polarity is applied to the input of the circuit, and a pulse PWM signal is obtained at the output.

In the simplest case, the control voltage can be applied using a variable resistor with a resistance of 22...100KOhm. If necessary, the control voltage can be obtained, for example, from an analog light sensor made on a photoresistor: the darker it is outside the window, the brighter it is in the room.

The regulating voltage affects the PWM output in such a way that when it decreases, the width of the output pulse increases, which is not at all surprising. After all, the original purpose of the UC3843 microcircuit is to stabilize the voltage of the power supply: if the output voltage drops, and with it the regulating voltage, then measures must be taken (increase the output pulse width) to slightly increase the output voltage.

The regulating voltage in power supplies is generated, as a rule, using zener diodes. Most often this or similar ones.

With the component ratings indicated in the diagram, the frequency of the generator is about 1 KHz, and unlike the generator on the 555 timer, it does not “float” when the duty cycle of the output signal changes - concern for the constancy of the frequency of switching power supplies.

To regulate significant power, for example, an LED strip, a key stage on a MOSFET transistor should be connected to the output, as shown in Figure 2.

We could talk more about PWM regulators, but let’s stop there for now, and in the next article we’ll look at different ways to connect LEDs. After all, not all methods are equally good, there are some that should be avoided, and there are simply a lot of mistakes when connecting LEDs.

Related publications