Portal for car enthusiasts

Wide pulse modulation. What is shim

For example);

  • a resistor with a nominal value of 190 ... 240 Ohms (here is an excellent set of resistors of the most common ratings);
  • personal computer with the Arduino IDE development environment.
  • Instructions for using PWM in Arduino

    1 General information about pulse width modulation

    Arduino digital pins can only output two values: logic 0 (LOW, low) and logic 1 (HIGH, high). That's why they're digital. But Arduino has “special” conclusions, which are indicated PWM. They are sometimes denoted by a wavy line "~" or circled or otherwise distinguished from others. PWM stands for Pulse-width modulation or pulse width modulation, PWM.

    A pulse-width modulated signal is a pulsed signal of constant frequency, but variable duty cycle(the ratio of the pulse duration and the period of its repetition). Due to the fact that most physical processes in nature have inertia, sudden voltage drops from 1 to 0 will be smoothed out, taking on some average value. By setting the duty cycle, you can change the average voltage at the PWM output.

    If the duty cycle is 100%, then all the time the digital output of the Arduino will have a logic voltage of "1" or 5 volts. If you set the duty cycle to 50%, then half the time the output will be logic "1", and half the time - logic "0", and the average voltage will be 2.5 volts. Well, and so on.


    In the program, the duty cycle is not set as a percentage, but as a number from 0 to 255. For example, the command analogWrite(10, 64) tells the microcontroller to apply a signal with a duty cycle of 25% to digital PWM output # 10.

    Arduino PWM pins operate at around 500Hz. This means that the pulse repetition period is about 2 milliseconds, which is measured by the green vertical strokes in the figure.

    It turns out that we can simulate an analog signal on a digital output! Interesting, right?!

    How can we use PWM? Lots of applications! For example, control the brightness of the LED, the speed of rotation of the engine, the current of the transistor, the sound from the piezo emitter, etc. ...

    2 Schematic for demonstration Pulse Width Modulation in Arduino

    Let's look at the most basic example - controlling the brightness of an LED using PWM. Let's take a classic pattern.


    3 Sketch example with PWM

    Let's open the "Fade" sketch from the examples: File Samples 01.Basics Fade.


    Let's change it a little and load it into the Arduino memory.

    Int ledPin = 3; // declare a pin that controls the LED int brightness = 0; // variable for setting brightness int fadeAmount = 5; // brightness step void setup()( pinMode(ledPin, OUTPUT); } void loop() ( analogWrite(ledPin, brightness); // set brightness brightness on ledPin pin brightness += fadeAmount; // change the brightness value /* when the borders of 0 or 255 are reached, change the direction of the brightness change */ if (brightness == 0 || brightness == 255) ( fadeAmount = -fadeAmount; // change the step sign) delay(30); // delay for greater visibility of the effect }

    4 LED brightness control using PWM and Arduino

    We turn on the power. The LED gradually increases in brightness, and then gradually decreases. We simulated an analog signal at a digital output using pulse width modulation.


    Watch the attached videos, which clearly shows the change in the brightness of the LED, on the connected oscilloscope you can see how the signal from the Arduino changes.

    It is convenient to regulate the supply voltage of powerful consumers using pulse-width modulation regulators. The advantage of such regulators is that the output transistor operates in a key mode, which means it has two states - open or closed. It is known that the greatest heating of the transistor occurs in the half-open state, which leads to the need to install it on a large-area radiator and save it from overheating.

    I propose a simple PWM controller circuit. The device is powered by a 12V DC voltage source. With the specified instance of the transistor, it can withstand current up to 10A.

    Consider the operation of the device: On transistors VT1 and VT2, a multivibrator with adjustable pulse duty cycle is assembled. The pulse repetition rate is about 7 kHz. From the collector of the transistor VT2, the pulses are fed to the key transistor VT3, which controls the load. The duty cycle is regulated by a variable resistor R4. At the extreme left position of the slider of this resistor, see the upper diagram, the pulses at the output of the device are narrow, which indicates the minimum output power of the regulator. At the extreme right position, see the bottom diagram, the pulses are wide, the regulator works at full power.


    PWM operation diagram in CT1

    With this regulator, you can control household 12 V incandescent lamps, a DC motor with an insulated housing. In the case of using the regulator in a car, where the minus is connected to the case, the connection should be made through a p-n-p transistor, as shown in the figure.
    Details: Almost any low-frequency transistors can work in the generator, for example, KT315, KT3102. Key transistor IRF3205, IRF9530. We will replace the P210 p-n-p transistor with a KT825, while the load can be connected to a current of up to 20A!

    And in conclusion, it should be said that this regulator has been working in my car with an interior heating engine for more than two years.

    List of radio elements

    Designation Type Denomination Quantity NoteShopMy notepad
    VT1, VT2 bipolar transistor

    KTC3198

    2 To notepad
    VT3 Field-effect transistorN302AP1 To notepad
    C1 electrolytic capacitor220uF 16V1 To notepad
    C2, C3 Capacitor4700 pF2 To notepad
    R1, R6 Resistor

    4.7 kOhm

    2 To notepad
    R2 Resistor

    2.2 kOhm

    1 To notepad
    R3 Resistor

    27 kOhm

    1 To notepad
    R4 Variable resistor150 kOhm1 To notepad
    R5 Resistor

    It's time to figure out how pulse-width modulation works. Let's try to delve into the physics of the process and at the same time slightly catch the operating modes of the timer.

    Let's consider two charts with a periodically repeating signal. For simplicity, consider one period. So, if we take an ordinary voltmeter and measure a constant voltage, then in the first case we will measure 5V. There seems to be no doubt about it.

    What will the voltmeter show in the second case? It turns out that the period of such a signal will be equivalent to a certain constant voltage. The voltage value, respectively, depends on the pulse filling value (the time when the signal is not zero). Let us agree that the duration of the presence of voltage and absence are equal, i.e. 50% of the time there is a signal, 50% is absent, the analogue of such a signal will be half the full voltage, respectively, the voltmeter will show 2.5V.

    By the way, the amount of filling is called the duty cycle of the signal. By analogy, when the duty cycle is 100%, the signal looks like a straight line. If the duty cycle is 70%, then, accordingly, the voltmeter will show 0.7 * 5 \u003d 3.5V. This principle of voltage regulation is called pulse-width modulation.

    Now let's move on to how the duty cycle of the signal is formed. To begin with, we will generate a sawtooth signal with an amplitude of 5V. The frequency can be arbitrary.

    Now let's get this signal to a comparator set to 2.5V.

    What will we see at the output of the operational amplifier? As long as the saw signal increases from zero to 2.5V, the output of the comparator will be minus power. But, since we have zero power minus, it means that the output is zero. As soon as the signal at the non-inverting input (i.e. saw) becomes more than 2.5V, then 5V will appear at the output of the op-amp. Thus, 50% of the time the op-amp will produce a logical zero, 50% of the time a logical one.

    Now let's try to change the duty cycle to 10%? If 100% is 5V, then 10% is ? Calculate by proportion. (10 * 5) / 100 \u003d 0.5V, set the comparator to 0.5V and get a 10% filling.

    Here we are disappointed instead of 10%, we got 90%, which is quite logical, there is nothing from zero to 0.5V at the output, but as soon as the saw voltage exceeds this value, 5V appears at the output of the comparator. Thus, we come to the first of the timer modes, called non-inverted fast PWM.

    Yes, these are the same settings for it and the minimum duty cycle corresponds to 0xFF.

    The reverse, more convenient to use, is the inverted PWM mode. In this case, it is enough to swap the inverting and non-inverting inputs of the comparator.

    Those. with a small voltage at the input of the comparator, the output will be a signal with a low duty cycle. So it's more convenient and understandable. For the timer, the mode is called Fast PWM, Output: Inverted.

    For the modes, Phase correct PWM and Phase and frequence correct PWM, triangle is used as the reference. but the essence remains the same.

    This approach allows you to get a more accurate PWM value. However, the carrier frequency is halved.

    In Phase Correct PWM mode, when changing the duty cycle, the OCR value is updated only when the upper value is reached. It is believed that this avoids signal phase shift.

    Phase and Frequency Correct PWM is good because when the duty cycle changes, the OCR value is updated only when the counter reaches the lower value. Those. this avoids frequency shifting of the signal.

    So far, I can’t give examples of using Phase Correct and Phase and Frequency Correct, because there is no suitable material yet, but in the near future I will probably supplement the article. But examples of Fast PWM are enough.

    In this article, we will talk with you about PWM controllers : what is it, for what and where it is applied.
    PWM - pulse width modulator.
    To convert voltage in television equipment and other electronic devices, PWM controllers . With the help of the device, it was possible to introduce innovative ideas and new technologies into production. The main advantages of PWM controllers are modest dimensions, excellent performance and high reliability.

    Most in demand PWM controllers in the manufacture of modules pulse power supply type. The constant voltage at the input of the device is converted into rectangular pulses, generated with a certain frequency and duty cycle. With the help of control signals at the output of the device, it is possible to carry out regulation operation of the high power transistor module. As a result, the developers received a voltage control unit regulated type.

    In television equipment, compact PWM controllers are in high demand. In addition, the devices are used in other electronic equipment, as well as components of the speed control system of electric drives in household appliances. Depending on the system parameters and the control signal, PWM controllers change the speed of the power unit. Feedback can be performed both by the value of the current strength and by the level of voltage.

    The typical design of a PWM controller used in television and other electronic equipment is characterized by the presence of several outputs. The common pin is connected to the same pin. scheme module power supply. The power control pin and the power pin are located next to each other. The first of them is responsible for monitoring the voltage at the output of the circuit and turns it off when the value drops below the threshold value. The second output is responsible for the power supply scheme .

    The output voltage is taken from the corresponding output. There are two-arm and one-arm PWM controllers. The first of them are used to control standard transistors. If it is necessary to close them, the controller closes the corresponding contact to a common cable. When working with a bipolar type transistor, a single-arm cascade is used, since a change in current strength is required for adjustment. To turn off the transistor, it is necessary to prohibit the passage of current. Therefore, a short to common contact is not used.

    PWM controllers used in television equipment are characterized by the following features:
    • The devices are capable of generating a reference voltage with a high degree of accuracy. Often this output is switched with a common wire. In this case, a capacitance of 1 mF or more is used, which improves the quality of stabilization of the output value.
    • The current limiter is triggered when the voltage at the corresponding output is significantly higher than the threshold. In this case, the power switches are automatically turned off.
    • Soft start is used to gradually increase the value of the output pulses to the calculated values. The presence of capacitance between the corresponding output and the common wire leads to its gradual charging. As a result, each pulse becomes wider until the desired value is reached.

    Modern power supplies for various equipment are designed on the basis of PWM controllers. The life of the module depends on the quality of the components. The main purpose for which PWM controllers are included in voltage source circuits is to provide a stable output voltage. The small dimensions of the controllers give them an advantage over standard circuits using transformers.

    PWM controllers used in power supplies , in addition to stabilizing the output voltage, they implement several more additional features. The use of pulse-width modulation allows you to control the magnitude of the signal. In this case, it is possible to change the length of the pulse and the duty cycle.
    PWM controllers have high efficiency rates, which can significantly expand the scope of their use. This is especially true for audio equipment. In addition, when using PWM controllers in power supplies, the range of available device powers is significantly expanded.

    Devices based on PWM controllers are universal and can be used not only in television equipment, but also in many other devices. Power supplies for various electrical equipment are implemented based on these controllers. The use of devices reduces the cost of operating equipment and improves its quality. High efficiency makes the development of sources based on PWM controllers a promising and in-demand area of ​​activity.

    Consider what is PWM or PWM. And also, what is the difference between PWM and WIR. The pulse-width modulation algorithm is used to smoothly change the power on the load coming from the power source. For example, in order to regulate the speed of rotation of the motor shaft; smoothness of change in the brightness of lighting or backlight. A separate wide area of ​​application of PWM are switching power supplies and stand-alone inverters.

    To power the load, it is often necessary to change the amount of voltage supplied from the power source. In principle, two methods of voltage regulation can be distinguished - linear and pulsed.

    An example of a linear method can serve. In this case, a significant part of the power is lost on the resistor. The greater the voltage difference between the power source and the consumer, the more noticeable the power loss, which simply “burns out” on the resistor, turning into heat. Therefore, the linear method of regulation is rational to use only with a small difference between the input and output voltages. Otherwise, the efficiency of the power supply as a whole will be very low.

    In modern converter technology, pulsed power control at the load is mainly used. One of the ways to implement impulse control is pulse width modulation PWM . In English literature PWM - pulse-width modulation .

    The principle of impulse control

    The main elements of any type of switching power controller are semiconductor switches - transistors or thyristors. In its simplest form, the switching power supply circuit is as follows. DC voltage source Uip key K connected to the load H. Key TO switches at a certain frequency and stays on for a certain amount of time. In order to simplify the diagram, I do not depict other mandatory elements on it. In this context, we are only interested in the operation of the key TO.

    To understand the principle of PWM, we will use the following graph. Let us divide the time axis into equal intervals, called period T. Now, for example, we will close the key for half the period K. When the key is closed, to the load H voltage is supplied from the power source Uip. The second part of the half-cycle of the key is in the closed state. And the consumer will be left without food.

    The time during which the key is closed is called impulse time t . And the duration of the open key is called pause time tp . If you measure the voltage at the load, then it will be equal to half Uip.

    The average value of the voltage across the load can be expressed by the following relationship:

    Uav.n \u003d Uip ti / T.

    Pulse time ratio ti to the period T called fill factor D . And the reciprocal of it is called duty cycle :

    S = 1/D = T/t and .

    In practice, it is more convenient to use the fill factor, which is often expressed as a percentage. When the transistor is fully open throughout the entire time, then the duty cycle D is equal to one or 100%.

    If D \u003d 50%, then this means that half the time during the period the transistor is in the open state, and half in the closed state. In this case, the waveform is called a square wave.
    Therefore, by changing the coefficient D from 0 to unity or up to 100%, you can change the value of Uav.n from 0 to Uip:

    Usav.n \u003d Uip ∙D.

    And, accordingly, adjust the amount of input power:

    Pav.n = Pip∙D.

    In Western literature, there is practically no distinction between the concepts of pulse-width regulation of PWM and pulse-width modulation of PWM. However, we still have a difference between them.

    Now in many microcircuits, especially those used in DC-DC converters, the PWM principle is implemented. But at the same time they are called PWM controllers. Therefore, now there is practically no difference in the name between these two methods.


    In any case, to form a certain duration of the pulse supplied to the base of the transistor and opening the latter, reference and setting voltage sources, as well as a comparator, are used.
    Consider a simplified circuit in which the battery GB feeds the consumer Rn in a pulsed way through the transistor VT. I must say right away that in this circuit I did not specifically use such elements necessary for the operation of the circuit: a capacitor, a choke and a diode. This is done in order to simplify the understanding of the operation of the PWM, and not the entire converter.

    Simplified, the comparator has three outputs: two inputs and one output. The comparator works as follows. If the voltage value at the + input terminal (non-inverting input) is higher than at the - input terminal (inverting input), then the output of the comparator will be high. Otherwise, low level.

    In our case, it is the high-level signal that opens the transistor VT. Let us consider how the required duration of the pulse time ti is formed. To do this, we use the following chart.

    With SHIRT, a sawtooth signal of a given frequency is applied to one input of the comparator. It is also called the base. The second input is supplied with a reference voltage, which is compared with the reference. As a result of comparison, a pulse of the corresponding duration is formed at the output of the comparator.

    If there is a reference signal at the non-inverting input of the comparator, then there will be a pause first, and then a pulse. If a setting signal is applied to the non-inverting input, then first there will be a pulse, then a pause.

    Thus, by changing the value of the specified signal, it is possible to change the duty cycle, and, accordingly, the average voltage at the load.

    The frequency of the reference signal is sought to be maximized in order to reduce the parameters of inductors and capacitors (not shown in the diagram). The latter leads to a reduction in the weight and dimensions of the switching power supply.

    PWM - Pulse Width Modulation

    PWM is predominantly used to generate a sinusoidal signal. PWM is often used to control the operation of an inverter converter. The inverter is designed to convert DC energy into AC energy.

    Let's consider the simplest scheme.

    At one point in time, a pair of transistors VT1 and VT3 opens. A path is created for the current to flow from the GB battery through the active-inductive load RnLn. At the next moment, VT1 and VT3 are locked, and diagonally opposite transistors VT2 and VT4 are open. Now the current flows from the battery through RnLn in the opposite direction. Thus, the current on the load changes its direction, therefore it is variable. As you can see, the load current is not sinusoidal. Therefore, PWM is used to obtain a sinusoidal current waveform.

    There are several types of PWM: unipolar, bipolar, one-way, two-way. Here we will not dwell on each specific type, but consider a general approach.

    A sine wave is used as the modulating signal, and a triangular waveform is used as the reference signal. As a result of comparing these signals, the durations of pulses and pauses are formed (lower graph), which control the operation of transistors VT1 ... VT4.

    Note that the amplitude of the voltage across the load is always equal to the amplitude of the power supply. The pulse repetition period also remains unchanged. Only the width of the opening pulse changes. Therefore, when the load is connected, the current flowing through it will have a sinusoidal shape (shown by the dotted line in the lower graph).

    So, the main difference between PWM and PWM is that with pulse-width regulation, the pulse and pause times remain constant. And with pulse-width modulation, the durations of pulses and pauses change, which makes it possible to realize an output signal of a given shape.