Alternating current ac decoding. Difference between AC and DC. Direct electric current What does ac or dc marking mean?

Direct or DC current is a flow of electrical charges that does not change its direction and strength over time, which, according to the classical definition of this quantity, is measured in coulombs per second (or amperes).

When getting acquainted with electrical phenomena of a permanent nature, it is important to remember not only the direction in which physical processes occur, but also their intensity (strength). In actual operating conditions of electrical or electronic equipment, the DC value is rarely absolutely constant.

Causes of Impermanence

The fact is that at the output of any rectifier circuit that converts alternating current, there are always low-frequency harmonics of the original signal, called ripples.

Note! When operating batteries and galvanic cells, it is also not entirely correct to talk about its constancy, since this can only refer to the concept of “polarity”.

The strength of the electron flow in any load also changes (decreases) over time, which is associated with a decrease in the EMF of the power source.

From the above reasoning it follows that talking about the constancy of the current characteristics in these circuits is possible only with some degree of convention. It is acceptable only in situations where changes in its strength can be neglected.

Main characteristics of current

When considering the main parameters of this physical quantity, we will immediately make a reservation that the often used term “current strength” is considered by most experts to be not entirely correct. Much more suitable to denote its scalar characteristic is not the force, but the speed (sometimes called intensity) of the movement of free electric charges.

According to the classical concept, this speed is defined as the amount of charge moving through a given cross-section of a conductive material per unit time. It is this indicator, taken as a unit of current, that is called one Ampere.

Thus, a flow of one Ampere is the movement of a charge of one Coulomb through a given conducting section in a time equal to a second. Another characteristic of direct current associated with its flow through a load with resistance R is called voltage drop, which is measured in Volts. It is defined as the potential difference formed across a conductor when one Ampere flows through it.

The same definition can be presented in the following form. One Volt is a potential difference between points spaced apart in an electric field that is sufficient to perform one Joule of work (when transferring a charge of one Coulomb between them).

The practical characteristics of the current component obtained through rectifiers usually include the following parameters:

  • The amplitude of pulsations, defined as the difference between its limit values;
  • An indicator of ripple, presented as a ratio of two quantities, in which the numerator is AC current, and the denominator is DC.

Let's explore the latter in more detail.

DC component

When examining the shape of the load current at the output of a diode rectifier using an oscilloscope, it is possible to discern its ripples, which appear due to the limited capabilities of the filter components (capacitors).

In some cases, these components are so small that they may not be taken into account when calculating circuits in which filter capacitors should be installed. With this approach to the category, it is more convenient to consider the indicator under study as pulsed or pulsating and to distinguish its two components: DC and ac. Let's look at each of these components in more detail.

Constant DC

The indicated value is calculated as the average value of the current action during the period. It is fundamentally different from another characteristic of a pulsating flow, called the variable component ac.

Variable Component

Alternating current (more precisely, the component of the pulsating current) ac represents a periodic oscillation of its amplitude around the previously discussed average position. When calculating this value, it should be assumed that its value includes the following components:

  • Permanent part;
  • The value of the variable component (ac), defined as the root mean square value.

Both of them are components of the current signal under study and, like all electrical parameters, have a fixed power (that is, the ability to perform a certain work). The latter is calculated as:

where I is the root mean square constant component and current ripple.

That is, when calculating power, the components of the constant DC and variable ac are summed up as complex quantities.

Additional Information. They are represented in this case in the form of vector components of the original signal.

It is also important that all the definitions discussed, like the AC and DC symbols, are equally applicable to the “voltage” category.

In conclusion, let us once again draw attention to the fact that the idea of ​​a constant current is most often associated with the invariability of the direction of the flow of free electrons. However, in reality, this concept involves taking into account a number of scalar characteristics, one of which includes the intensity of the flow of charges in a passive load.

When the nominal value of this current component changes over time, it can be considered constant only conditionally, which is allowed within the framework of the problem being solved in each specific case.

Video

234 rebounds, 2 of them this month

Biography

AC/DC(abbreviated from the English alternating current/direct current alternating/direct current) Australian rock band formed in Sydney (Australia) in November 1973 by brothers Malcolm and Angus Young.

Together with bands such as Led Zeppelin, Black Sabbath and Deep Purple AC/DC often considered as pioneers of hard rock and heavy metal. The musicians themselves classified their music as rock and roll, since it is based on rhythm and blues with a highly distorted sound of rhythmic and solo guitars.

The band went through several line-up changes before the band's first album, High Voltage, was released in 1975. The band's line-up remained unchanged until bassist Mark Evans was replaced by Cliff Williams in 1977. On February 19, 1980, lead singer and songwriter Bon Scott (Ronald Belford "Bon" Scott) died after choking on his own vomit as a result of extreme alcohol intoxication. The group had every chance of breaking up, but soon a replacement for Scott was found in the person of former Geordie vocalist Brian Johnson. A year later, the group released their best-selling album, Back in Black.

The team has sold over 200 million albums worldwide, including 68 million albums in the United States. The most successful album, Back in Black, sold more than 22 million in the United States and more than 42 million abroad. Generally, AC/DC is the most successful and famous rock band from Australia. AC/DC They are ranked number four on VH1's 100 Greatest Artists of Hard Rock and number seven on MTV's "Greatest Heavy Metal Band Of All Time" list.

Name

Malcolm and Angus Young came up with the name for their band after seeing the acronym "AC/DC" on the back of their sister Margaret's sewing machine. "AC/DC" is an abbreviation for "alternating current/direct current", which indicates that the device can use the specified types of energy. The brothers felt the name symbolized the band's raw energy and live performance energy, and the name stuck.

In some cultures, "AC/DC" is slang for bisexuals; The musicians claimed that they were unaware of the existence of this meaning until a taxi driver drew attention to this fact early in their career. Some religious leaders argue that the group's name should be understood as "Anti-Christ/Devil's Child", "Anti-Christ/Death to Christ" ) or “After Christ/Devil Comes”.

"AC/DC" is spelled, but the band is also known as "Acca Dacca" in Australia. The name led to the emergence of tribute groups using similar names: BC/DC from the province of British Columbia (Canada); AC/DSHE, a women's group from San Francisco; Swedish AB/CD and some others.

It is known that the group performed several times for the Freeride Entertainment team in films about Mountain Bike, from the Disorder series (in parts 4 and 5, currently there are 9 of them)

Story

Brothers Angus (born March 31, 1955; at the request of Atlantic Records, Angus's official birth year was incorrectly stated as 1959), Malcolm (born January 6, 1953) and George Young (George Young) were born in Glasgow (Scotland) and as children along with their family went to Sydney. George started playing guitar first and became a member of the most successful Australian band of the 60s, The Easybeats. They were the first local rock band to have an international hit with "Friday on My Mind" in 1966. Malcolm soon followed in his brother's footsteps, becoming the guitarist for the Newcastle band The Velvet Underground (not to be confused with the New York band The Velvet Underground).

Early years

After gaining their first musical experience, Malcolm and Angus formed AC/DC, inviting vocalist Dave Evans, bass guitarist Larry Van Kniedt and drummer Colin Burgess into the group. The group debuted on December 31, 1973 at Sydney's Checkers bar.

The original line-up changed frequently; the band went through several drummers and bassists throughout 1974. In September 1974, AC/DC replaced Dave Evans with the charismatic Bon Scott (born July 9, 1946 in Kirrimer, Scotland), lead singer of The Spectors in 1966. The real success of the group began with this event. With Evans, AC/DC recorded a single consisting of three songs: "Rockin" in the Parlour", "Show Business" and "Can I Sit Next to You Girl". The latter two were also recorded with Scott.

Angus Young's sister encouraged him to wear the school uniform he wore at Ashfield Boys High School in Sydney to concerts. He later wore this uniform at all the band's concerts.

With regular appearances on the Australian popular music television show Countdown, between 1974 and 1978 the band became one of the country's best known and most popular bands. AC/DC During these years they released a number of successful albums and singles, including the timeless rock 'n' roll anthem "Its a Long Way to the Top (If You Wanna Rock "n" Roll)." -roll]).

World famous

The group signed an international contract with Atlantic Records and began to actively tour the UK and Europe, achieving fame and gaining experience performing in the wings of famous rock bands of the time, such as Alice Cooper, Black Sabbath, KISS, Cheap Trick, Nazareth, Foreigner, Thin Lizzy and The Who. AC/DC's third Australian album, Dirty Deeds Done Dirt Cheap, was released in 1976.

The invasion and wave of popularity of punk rock in 7678. The group survived well due to their crude and provocative lyrics and, in part, due to the fact that in the British music press of the time they were classified as punk bands. They achieved success on the British rock scene thanks to their powerful and controversial live shows, and Angus Young quickly became famous due to his provocative behavior on stage, which, among other things, led to the group being banned from performing at several British concert venues .

Produced by Mutt Lange, the 1979 album Highway to Hell catapulted the band to the top of the world's rock music charts of all time. The album undoubtedly became the most popular of the group's discography at the time of its release. Many of the album's songs are still frequently heard on the radio, and the title track has become one of the most famous songs in the history of rock music.

Death of Bon Scott

Bon Scott died on February 19, 1980. He left another party and stayed overnight in the car of his friend Allistair Kinnear. He found Bon dead the next day. The official cause of death was hypothermia, although the most common version to this day is that Bon Scott choked on his own vomit. These rumors are supported by many contradictions in the official story of his death, which also gives rise to many theories about conspiracy, the musician's murder and a heroin overdose.

The group members initially planned to stop their musical activities as part of AC/DC, but later decided that Bon Scott would like the group to continue. The musicians tried several candidates for the vocalist position, and in the end there were two candidates left: Terry Slesser and Brian Johnson. Johnson during this period tried to restore his group Geordie, but performing two songs in public AC/DC and Tina Turner ("Whole Lotta Rosie" (Let There Be Rock) and "Nutbush City Limits", respectively) impressed the participants AC/DC and a few days later they informed Johnson that he was the new singer of the group.

"Back in Black"

Together with Brian Johnson, the group completed the songs unfinished due to Bon's death, and recorded the album Back in Black, also produced by Lang. Back in Black, released in 1980, became the band's best-selling album and one of the most significant in hard rock history. Among all the hits on the album, the song of the same name, written in memory of Bon Scott, and "You Shook Me All Night Long", are considered by many to be the quintessence of music AC/DC and even hard rock in general.

The next album, For Those About to Rock (We Salute You), released in 1981, also sold very well and was well received by critics. The composition of the same name on the album, ending with the thunder of firing guns, became the culmination and final number of most subsequent concerts. AC/DC.

The band produced 1983's Flick of the Switch without Lang. Drummer Phil Rudd left the band due to personal differences with the rest of the band, reportedly caused by problems with alcohol. In his place, after an anonymous audition, they took Simon Wright, a former member of the group Tytan. In 1985, with a new lineup, the group recorded the less successful album Fly on the Wall, produced by the Young brothers. Along with this album, the band released a series of music videos of the band performing five of the album's ten songs in a bar, using various special effects, including an animated fly.

In 1986, AC/DC returned to the charts with the title track of Who Made Who, the soundtrack to the Stephen King film Maximum Overdrive. The album also contained two new instrumentals and hits from previous albums. In February 1986, the group was inducted into the Australian Record Industry Association Hall of Fame. The band released their 1988 album Blow Up Your Video with original producers Harry Vanda and George Young. This album sold better than the previous one and entered the UK top twenty singles chart with the song "Heatseeker".

After the release of Blow Up Your Video, Wright left the band and was replaced by session musician Chris Slade. Johnson was unable to participate in the band's work for several months, so the Young brothers wrote the songs for the next album themselves, as they did for all subsequent ones. In 1990, the album The Razor's Edge was released. It became very successful for the group and contained the hits "Thunderstruck" and "Money Talks". The album became multi-platinum, entered the top ten of the US charts (2nd place) and twenty singles in Great Britain.

In 1994, Phil Rudd returned to the group. Chris Slade's departure, in this regard, was amicable and was mainly due to the band members' strong desire to have Rudd back. According to Angus Young, Slade was the best musician in AC/DC, but the desire to see Phil in the group was stronger. As a member of 1980-1983, the group recorded the album Ballbreaker in 1995 with hip-hop and heavy metal producer Rick Rubin and Stiff Upper Lip in 2000.

After the release of these albums, the group signed a long-term contract for several albums with Sony BMG, which began to be released under the Epic Records label.

Recent years and recognition

In March 2003, AC/DC was inducted into the Rock and Roll Hall of Fame in New York City and performed their hits "Highway to Hell" and "You Shook Me All Night Long" with Aerosmith's Steve Tyler. In May 2003, Malcolm Young was awarded the Ted Albert Award for his "outstanding contribution to Australian music". That same year, the Recording Industry Association of America (RIAA) updated its album sales estimates from 46.5 million to 63 million, making AC/DC fifth group in US history to sell the most albums after The Beatles, Led Zeppelin, Pink Floyd and the Eagles. In addition, Back in Black was certified double diamond (20,000,000 copies sold), making it the sixth best-selling album in US history. In 2005, the album sold 21 million copies, which brought it to fifth position.

In July 2003, the band performed together with The Rolling Stones at Sarsfest, a concert dedicated to the fight against the SARS epidemic in Toronto, Canada.

On 1 October 2004, Corporation Lane in Melbourne was officially renamed ACDC Lane in honor of the group (street names in Melbourne cannot contain the "/" character). The street is next to Swanston Street, where the band recorded their video for the 1975 hit "Its a Long Way to the Top" in the back of a truck. There is also another street in the world named after the group AC/DC, in Spain, in the city of Legan (LeganГ©s), near Madrid “Calle de AC/DC”, not far from the streets named after the rock groups Iron Maiden and Rosendo (Spanish rock band).

In March 2005, a two-DVD set, "Family Jewels", was released, containing a music video and concert clips. The first disc was from the Bon Scott era (with concert footage filmed ten days before Scott's death), the second contained footage from the Brian Johnson era.

On August 28, 2008, the single "RocknRoll Train" was released. On October 20, 2008, AC/DC released their new album Black Ice, which a week after its release topped the charts in 29 countries. In its first week, the band sold 5 million copies of the album worldwide. There were 6 albums in the Australian Top 50 at the beginning of November AC/DC. Among those who spoke enthusiastically about the new album was Australian poet and writer John Kinsella, who noted the album's "smart, sharp, in its own way brilliant" lyrics.

At the end of October, the band went on a North American tour, inviting The Answer as support acts.

Influence on rock music

AC/DC is mentioned by many contemporaries and later musicians and bands of rock and metal music as an influence on their work. Among them: Anthrax, Bon Jovi, The Darkness, Def Leppard, Dio, Dokken, Dream Theater, Faster Pussycat, Iron Maiden, Great White, Guns N" Roses, Hanoi Rocks, Journey, Megadeth, Metallica, Nirvana, Mötley Crüe, Ozzy Osbourne, Poison, Ratt, Rhino Bucket, Saxon, Scorpions, Skid Row, Supagroup, Tool, Twisted Sister, UFO, Van Halen, Whitesnake, Wolfmother, Y&T.

Many punk rock, hardcore punk, grunge, garage rock and alternative rock artists and groups have also celebrated AC/DC how it influenced them. Although the group was initially criticized by British punk rockers of the late 70s, many musicians from this movement paid tribute to AC/DC for the high energy of the music, a thorough and anti-commercial (although many may argue with this) approach to rock music.

Influence AC/DC it's hard to overestimate Australian music. Relatively speaking, every Australian rock band that appeared in the mid-70s and later was influenced by AC/DC. To Australian bands who have cited influences on them AC/DC, include, for example, Airbourne, Blood Duster, Frenzal Rhomb, INXS, Jet, The Living End, Midnight Oil, Powderfinger, Silverchair, You Am I.

Electrical energy accompanies us at every step. Without it, the life of any person is unthinkable. Throughout our lives, we encounter manifestations of electricity to one degree or another. This happens more often, as a rule, when electrical appliances break down. And in order to understand their structure and circuits, it is useful to know that alternating and direct current are designated as AC and DC current.

Sources of electrical energy

Initially, the sources of electricity were only disposable chemical galvanic cells. Later, reusable batteries appeared. It is noteworthy that the polarity of chemical sources is not able to change on its own. In order to obtain constant voltage generators are used on an industrial scale, and sometimes solar panels.

Electronic equipment, in turn, is powered by an alternating voltage network, and power supplies are used to obtain constant voltage. The alternating current is reduced to the required values ​​using transformers and subsequently rectified. At the same time, the ripple frequency is reduced by smoothing filters, stabilizers and voltage regulators.

Switching power supplies are common in the modern world. In them, the pulsation frequency of the output electricity is smoothed out by integrating elements. They concentrate electrical energy and transfer it to the load. The result is the required constant voltage.

Electrolytic capacitors can also condense electrical energy. When such a capacitor is discharged, an alternating current appears in the external circuit. If it is discharged through a resistor, then a gradually decreasing (unidirectional) alternating current occurs. When using an induction coil, a bidirectional alternating current is generated in the circuit. Electrolytic capacitors can have enormous capacitance reaching hundreds of microfarads. When such capacitors are discharged through a large resistance, the electricity decreases more slowly and a constant voltage flows in the external circuit.

There are also combinations of capacitors and chemical sources - ionistors. They have the ability to accumulate and release significant amounts of electricity. A typical example is electric cars.

Designations on diagrams and devices

It is generally accepted that the direction of electricity goes from a contact with a plus sign to a contact with a minus sign.

Places with high potentials are called “positive pole” and are indicated by a + (plus) sign. Points with lower potentials, accordingly, are called “negative pole” and are designated by a - (minus) sign.

Initially, it was accepted that the electrical insulation of positive wires is red, while wires with a minus sign are painted blue or black.

Symbols on electrical appliances:- or =. Unidirectional electricity (including constant electricity) is denoted by the Latin alphabet DC, or the Unicode symbol is used - U+2393.

The abbreviations AC and DC are firmly rooted in everyday use and are used along with the usual names “variable” and “constant”:

  • designation of direct voltage (-) or DC (Direct Current);
  • alternating current sign (~) or AC (Alternating Current) - designation of alternating current.

Application areas of DC voltage

The use of constant voltage allows the electrical energy to be transferred to be increased and then transferred between power systems that use alternating current of different frequencies (for example, 50 and 60 hertz).

Direct current is also actively used in transport. Constantly excited electric motors are used in various mechanisms:

  • electric locomotives;
  • electric trains;
  • trams;
  • trolleybuses;
  • lifts, etc.

There was also constant tension in other areas of science and technology. It is widely used in this way:

Electricity accompanies us everywhere: at work and at home. It’s scary to even imagine for a minute what will happen to humanity if it suddenly loses electrical energy.

Pulse converters and power electronics in general have always remained something sacred for most amateurs and professionals in the field of electronics development. The article covers perhaps the most interesting topic among DIYers and fans of alternative energy - the formation of a sinusoidal voltage/current from a constant one.

I think many of you have probably seen advertisements or read articles containing the phrase “pure sine”. This is exactly what we will talk about, but not about the marketing component, but about exclusively technical implementation. I will try to explain as clearly as possible the operating principles themselves, standard (and not so standard) circuit solutions, and most importantly, we will write and analyze software for the STM32 microcontroller, which will generate the necessary signals for us.

Why STM32? Yes, because now this is the most popular MK in the CIS: there is a lot of educational information in Russian on them, there are a lot of examples, and most importantly, these MKs and debugging tools for them are very cheap. I’ll tell you straight - in a commercial project I would only install the TMS320F28035 or a similar DSP from the Piccolo series from TI, but that’s a completely different story.

One thing is important - STM32 allows you to stably control simple “household” power converters on which the fate of the world does not depend on the operation of any nuclear power plant or data center.

This is the picture of control signals that needs to be obtained in order to convert direct current into alternating current. And yes - this is exactly the sine! Like in that movie: “Do you see the gopher? - No. - And he is...”

Interested to know how a sinus is formed? Would you like to know how kilowatts of energy are pumped into oil? Then welcome to the cut!

1. Topologies for generating a sinusoidal signal

If you ask a crowd of electronics engineers: “How can you generate a sinusoidal signal?”, then proposals with a dozen different methods will pour in, but which one do we need? Let's start from the original task - we need to turn, for example, 380V 10A into an alternating voltage of 230V. In general, this is a “classic” case, we can see it in any good on-line UPS or inverter. It turns out that we need to convert about 4 kW of power, and with good efficiency at that, not bad, right? I think such a condition will reduce the number of options for “drawing” the sine. So what do we have left?

In power converters up to 6-10 kW, two main topologies are used: a full bridge and a “half bridge” with a through neutral. They look in the following way:

1) Topology with through neutral

This topology is most often found in budget UPSs with a sine wave output, although such authorities as APC and GE do not hesitate to use it even at fairly high powers. What motivates them to do this? Let's look at the advantages and disadvantages of this topology.

Pros:

  • The minimum possible number of power transistors, which means losses are 2 times less and the cost of the device is also lower
  • Through zero. This simplifies the certification process, especially CE and ATEX. This is due to the fact that a through zero allows input protection systems (for example, RCDs) to also operate if an accident occurs in the output circuits after the converter
  • Simple topology, which allows us to minimize the cost of the product with small
    and medium-scale production

Minuses:

  • The need for a bipolar power supply. As you can see, ±380V and another zero must be supplied to the inverter circuit
  • Double the number of high voltage capacitors. High-voltage capacitors of large capacity and with low ESR at powers from 3-4 kW begin to range from 20 to 40%
    component costs
  • The use of electrolytic capacitors in the “divider”. They dry out, it is almost impossible to select capacitors with the same parameters, and if you consider that the parameters of electrolytes change during operation, then it is pointless. You can replace it with film, but it’s expensive
The main pros and cons have been identified, so when is this topology needed? My subjective opinion: at powers up to 500-1000 W, when the fundamental requirement is cost, not reliability. An obvious representative of such consumer goods are stabilizers from A-Electronics: they’re cheap, they work somehow, and that’s okay. For 60% of consumers in our country this is sufficient and affordable. Let's draw conclusions.

2) Bridge topology

Bridge topology... probably the most understandable and most common topology in power converters, and most importantly, accessible to developers even with little experience. After 10 kW you will not find anything else other than a single- or three-phase bridge. Why is he so loved?

Pros:

  • Very high reliability. It is mainly due to the quality of the power transistor control system and does not depend on component degradation
  • The input capacitance required is several times, or even an order of magnitude less. It is only necessary to provide the calculated ESR value. This allows the use of film capacitors while maintaining cost. Film capacitors - do not dry out, perform better in harsh temperatures, the working life is an order of magnitude higher than that of electrolytes
  • Minimum voltage ripple on transistors, which means you can use transistors with lower voltages
  • Simplicity and clarity of operating algorithms. This leads to a significant reduction in time for product development, as well as for its commissioning.

Minuses:

  • An increased number of power transistors means more serious cooling is required. An increase in the price of transistors, but due to the smaller number of capacitors this is rather a plus
  • Increased driver complexity, especially with galvanic isolation requirements
As you can see from the real disadvantages of the bridge topology, there is only an increased requirement for cooling the transistors. Many will think: “More heat is generated, which means the efficiency is lower!” Not quite so... Due to reduced EMF emissions and a more “tough” control system, the efficiency of the two topologies is approximately equal.

In 70% of cases I have to use a bridge circuit not only in DC/AC inverters, but also in other converters. This is due to the fact that I design mainly industrial solutions and increasingly for European customers, and there it is customary to provide a 5-15 year guarantee for expensive industrial devices. The classic requirement: “We want a piece of hardware that can be guaranteed for 10 years,” there is no choice anymore. Of course, when people want a device with the lowest price, then it is necessary to start from a specific task when choosing a topology.

A short summary: this article will provide software for the operation of a bridge converter (H-bridge or Full Bridge), but the principle of sine generation itself is the same for all topologies. The code can also be adapted for the 1st topology, but you are on your own.

2. Formation of alternating current using a bridge converter

First, let's look at how a bridge converter generally works. We look at the circuit and see transistors VT1-VT4. They allow us to apply one or another potential to our abstract load (a resistor, for example). If we open transistors VT1 and VT4, we get the following: VT4 connects one end of the load to negative (GND), and transistor VT1 connects to +380V, a potential difference “380V - 0V” appears across the load, which is not zero, which means through current will begin to flow to the load. I think everyone remembers that scientists agreed - the current flows “from plus to minus.” We get this picture:

What did we get by opening VT1 and VT4? We have connected our load to the network! If the resistor was replaced with a light bulb, it would simply light up. And we didn’t just turn on the load, but determined the direction of the current flowing through it. It is very important! What happened at that time with VT2 and VT3? They were closed... completely... tightly... What would happen if, after all, VT2 or VT3 were also open? Let's look:

Let's assume that transistors VT1, VT4 and VT2 have opened. Let's remember Ohm's law, look at the channel resistance of high-voltage transistors, for example, IPP60R099P7XKSA1 and see 0.1 Ohm, we have 2 of them in series - which means the resistance of the circuit VT1 and VT2 is about 0.2 Ohm. Now let's calculate the current that will flow through this circuit: 380V / 0.2 Ohm = 1900A. I think everyone understands that this is a short circuit? I also think everyone understands why VT2 and VT3 should be closed?

This “phenomenon” is called - through current. And it is with him that the big war is going on in power electronics. How to avoid it? Create a control system whose algorithm will strictly prohibit the simultaneous opening of an extra transistor.

Why then are transistors VT2 and VT3 needed? Remember I wrote that the direction of the current is very important? Let's remember what alternating current is. Actually this is a current that has something variable, in this case the direction of the current. We have a current flowing in our socket that changes its direction 100 times per second. Let's now close VT1 and VT4, and then open transistors VT2 and VT3 and get this picture:

As you can see, the direction of the current (indicated by arrows) has changed to the opposite. Using a bridge allowed us to change the direction of the current, what does this mean? Yes, we got AC!

Please note that the bridge has two diagonals: the first diagonal is formed by VT1+VT4, and the second diagonal is formed by VT2+VT3. These diagonals work in turn, switching the current first in one direction and then in the other.

So we got alternating current, you say, but not everything is so simple... We have a standard - mains voltage. It is standardized by two main parameters: voltage and frequency. Let's deal with frequency for now, because the voltage issue is simple and purely circuit-technical.

And so the frequency... what is known about it is that it is 50 Hz (sometimes 60 Hz in the States). The signal period is 20 ms. The sine wave is symmetrical in this case, which means our 2 half-waves (positive and negative) have the same duration, that is, 10 ms + 10 ms. I hope everything is clear here.

What does this mean in a physical sense? Yes, the fact is that we need to change the direction of the current in the load every 10 ms. We get that first the VT1+VT4 diagonal is open for 10 ms, and then it closes and the VT2+VT3 diagonal opens for the next 10 ms.

What does it mean to open a transistor and what signal to send to it?

Let's digress a little to the principle of transistor control. I am using insulated gate N-channel field effect transistors (Mosfet).

“Open transistor” is a transistor, the gate (G) of which was supplied with a positive potential (+10..18V) relative to the source (S) and the transistor changed the resistance of the channel (S-D) from infinitely large (2-100 MOhm) to small (usually 0.1 - 1 Ohm). That is, the transistor began to conduct current.

A “closed transistor” is a transistor whose gate (G) is pulled towards the source (S) and its resistance changes from small to infinitely large. That is, the transistor has stopped conducting current.

To better familiarize yourself with the operating principle of a field-effect transistor or IGBT, I advise you to read a couple of chapters in Semenov’s book “Fundamentals of Power Electronics” or another source, maybe Wikipedia for starters.

For control, we supply a signal with Pulse Width Modulation or the more familiar abbreviation - PWM. The peculiarity of this signal is that it has 2 states: lower voltage (GND) and upper voltage (VCC), that is, by applying it to the gate of the transistor, we either open it or close it - nothing else is given. I also advise you to read more about PWM, because I described it to you superficially for the lazy.


And so, in order for our bridge to change the direction of the current every 10 ms, we need to apply a PWM signal to it, the period of which is 20 ms and the duty cycle is 50%. This means that out of 20 ms, our shoulder is open half the time (10 ms) and conducts current, and the other half is closed. We need to apply such PWM to all keys, but with one condition - we apply direct PWM to the VT1+VT4 diagonal, and inverse PWM to the VT2+VT3 diagonal. To put it more cleverly, the signal supplied on the diagonals should have a shift of 180 0. I think at this moment your head is racing trying to understand the text, so let’s look at its visual representation:

Now everything is clear? No? Then in more detail... As you can see, I specifically noted the moments of opening and closing of transistors: they open at “plus” and close at “minus”. Also, the signals are opposite, that is, inverse: when the blue signal is “plus”, then the green signal is “minus”. We apply a blue signal to one diagonal, and a green signal to the other - as can be seen on the oscillogram, our diagonals never open at the same time. Alternating current is ready!

Look at the period. I specifically showed an oscillogram from the controller outputs so that my words were not an abstraction. The signal period is 20 ms, one diagonal is open for 10 ms and creates a positive half-wave, the other diagonal is also open for 10 ms and creates a negative half-wave. Now I hope everyone understands, and if you still don’t understand, write to me in PM, I’ll give you an individual lesson on your fingers. To confirm my words, the oscillogram shows our treasured 50 Hz! It’s just too early to relax...

We received alternating current with a frequency of 50 Hz, but in the outlet we have a sine wave, and here a meander is not the case. Formally, you can apply a meander to the output and power most loads with it, for example, a switching power supply doesn’t care: sine or meander. That is, you already have enough to turn on laptops, phones, TVs, phones and other things, but if you connect an AC motor, then everything will be very bad - it will start to heat up and its efficiency will be noticeably less, and in the end it will most likely burn out. Do you think you don't have engines at home? What about the refrigerator compressor? What about a heating circulation pump? The latter generally burn as if they were made of wood. The situation is the same with deep-well pumps for wells, and with many other things in general. It turns out that the sinusoidal signal at the output of an inverter, stabilizer or UPS is still important. Well, we need to create it! Now a complete brain explosion will begin...

3. Generating a sinusoidal waveform using PWM

To be honest, I don’t know how to present this section in accessible language. In case someone doesn’t understand, I ask you to either google it further, or write in a comment or PM - I’ll try to explain it to you personally. The eyes are afraid, but the hands are doing...

Let's see what a regular sine graph looks like:

We see 2 axes: one axis with a period of pi, pi/2 and beyond, the second with an amplitude from -1 to +1. In our problem, the period is measured in seconds and is 20 ms or 10 ms for each half-wave. Everything is simple and clear here, but with amplitude it’s more fun - just take it as an axiom that our amplitude is from 0 to 1000. This is the duty cycle value that the microcontroller sets, that is, 100 is 10%, 500 is 50%, 900 is 90 %. I think the logic is clear. In the next chapter you will understand why from 0 to 1000, but for now let’s rebuild our graph to fit our values:

This is what the sine graph of a smoker looks like, which corresponds to our task. As you can see, I did not indicate the negative half-cycle, because In our case, it is implemented not using a sinusoidal signal, but by changing the direction of the current by switching the diagonals of the bridge.

On the X axis we have time, and on the Y axis we have the duty cycle of our PWM signal. We need to draw a sine using PWM. Do we remember geometry at school, how did we make graphs? That's right, point by point! How many points? Let's build a sine over several points O1(0,0) + O2(5,1000) + O3(10,0) + O4(15, -1000) + O5(20, 0) and get the following sine:

We built it and see that, in principle, this signal is more similar to a sine than a regular meander, but it’s still not a sine yet. Let's increase the number of points. This, by the way, is called “signal discreteness” or in this case “PWM discreteness”. How can I find out the coordinates of these points? With the extreme ones it was simple...

Calculation of values ​​for forming a sine

As I said above, our sine is quite symmetrical. If we build 1/4 of the period, that is, from 0 to 5 ms, then by duplicating this piece further, we can build the sine for an infinitely long time. And so the formula:


And so in order:
  • n - duty cycle value at a given discrete point
  • A is the signal amplitude, that is, the maximum duty cycle value. For us it's 1000
  • pi/2 - 1/4 of the sine period falls into pi/2, if we count 1/2 of the period, then pi
  • x - step number
  • N - number of points
For example, let’s make it convenient to use the condition that we have 5 points. It turns out we have 1 step = 1 ms, this will make it easy to build a graph. The sampling step is calculated simply: the period in which we build the graph (5 ms) is divided by the number of points. Let's bring the formula to human form:


We get a sampling step of 1 ms. Let’s write out the formula for calculating the duty cycle, for example, in Excel and get the following table:

Now we will return to our sine graph and plot it again, but for a larger number of points and see how it changes:

As we can see, the signal is much more like a sine, even taking into account my skill in drawing, or rather the level of laziness)) I think the result does not require explanation? Based on the construction results, we derive the axiom:

The more points, the higher the signal sampling, the more ideal the sinusoidal signal shape


And so, how many points will we use... It is clear that the more, the better. How to count:
  1. For this article I’m using an old STM32F100RBT6 microcontroller (STM32VL-Discovery debugging), its frequency is 24 MHz.
  2. We count how many ticks a period of 20 ms will last: 24,000,000 Hz / 50 Hz = 480,000 ticks
  3. This means that half of the period lasts 240,000 ticks, which corresponds to a frequency of 24 kHz. If you want to increase the carrier frequency, take a faster stone. Our ears will still hear 24 kHz, but for tests or a piece of hardware standing in the basement it will do. A little later I plan to transfer to F103C8T6, and there it is already 72 MHz.
  4. 240,000 ticks... It logically suggests 240 points for half the period. The timer will update the duty cycle value every 1000 ticks or every 41.6 µs
We decided on the discreteness of the PWM; 240 points per half period is enough with a margin to get a signal shape at least no worse than in the network. Now we calculate the table, also in Excel, as the simplest option. We get the following graph:

The source of the table and values ​​can be found at the link - .

4. Control of a bridge converter to generate a sine wave

We received a sine table and what to do with it? We need to transmit these values ​​with a certain sampling step, which is known to us. It all starts with the timer being initialized - time 0, duty cycle zero. Next, we count the sampling step of 41.66 μs and write the PWM value from Table 13 (0.13%) into the timer, count another 41.66 μs and record 26 (0.26%), and so on for all 240 values. Why 240? We have 120 steps for 1/4 period, but we need to draw 1/2 period. The duty cycle values ​​are the same, only after they have reached 1000 we write it in reverse order and get the sine decay. At the output we will have the following oscillogram:

As you can see, we received a bunch of PWM values ​​in a clearly defined period and its duration is: 240 steps x 41.66(!) μs = 9998.4 μs = 9.9984 ms ~ 10 ms. We obtained half a period for a network frequency of 50 Hz. As you can see, there are again two signals and they are in antiphase, which is exactly what is needed to control the diagonals of the bridge. But excuse me, where is the sine, you ask? The moment of truth has come! Let's now feed the signal from the output of the microcontroller to a low-pass filter. I made a simple low-pass filter using RC circuits with nominal values ​​of 1.5 kOhm and 0.33 μF (I just had them on hand) and got the following result:

Voila! Here it is our long-awaited sine! The red beam of the oscilloscope is the signal before the low-pass filter, and the yellow beam is the signal after filtering. The low-pass filter cut off all frequencies above 321 Hz. We still have the main signal of 50 Hz, and of course its harmonics with a small amplitude. If you want to perfectly clean the signal, then make a low-pass filter with a cutoff frequency of about 55-60 Hz, but for now this is not important, we just needed to check whether we got a sine or not. By the way... my oscilloscope synchronization is turned on for the yellow beam (arrow on the right of the screen) and we see its frequency at the bottom of the screen - ideal 50 Hz. What more could you ask for? That's it, all that remains is to decide what signal and where to send it. Let's look at this picture:

If you look at the very first oscillogram in the article, you will see that the signal in yellow and blue better have the same phase, that is, they become positive at the same time and open the transistors. These 2 signals open the VT1+VT4 diagonal. Accordingly, 2 other signals also have the same phase and open a different diagonal. Now we not only change the direction of the current, but also set the amplitude using PWM so that it changes according to a sinusoidal law. Now let's look at the same circuit, but with currents:

As you can see, the current through the load flows in the opposite direction, changing direction with a frequency of 50 Hz, and the modulated PWM supplied to transistors VT1 and VT2 allows you to draw a sinusoidal signal shape in half waves.

The LPF (low frequency filter) is made on inductance L1 and capacitor C2. I advise you to consider the cutoff frequency for this filter to be less than 100 Hz, this will minimize voltage ripple across the output.

For dessert, I’ll show you part of the circuit diagram of a real device with a similar topology and filter, it’s large, so download the PDF.

5. Fighting through currents

I don’t think it’s a secret to anyone that nothing is perfect? It’s the same with Mosfets, they have a number of disadvantages and we will look at one of them - large gate capacitance. That is, in order to open the transistor we need to not only apply voltage, but also charge the capacitor with this same voltage, so the rise and fall of the signal is delayed. This leads to the fact that a moment in time may arise at the signal boundary when one transistor has not yet completely closed, and the other has already begun to open.

I advise you to read more about this phenomenon, for example, in this article. I'll just tell you how to deal with it. So that the transistors have time to close normally before the next arm opens, dead-time is introduced between the control signals, or, more simply put, a time delay. In our case, such a delay will be introduced between the control signals on transistors VT3 and VT4, because They are the ones who provide half-wave switching. Transistors with modulated PWM (VT1 and VT2) already have such delays - the sine starts with a duty cycle of 0% and also ends at 0%. This delay is 1 sampling step long, that is, 41.6 µs.

And so - we need to implement the dead time between the blue and green beam/signal. On any controller, such a delay can be done programmatically, but this is not good - the program will freeze or be delayed, and blah blah blah, your device and apartment are already on fire. Therefore, only hardware should be used in power electronics. On all specialized motor controls, hardware deadtime is provided on all PWM outputs and channels, but the STM32 is still a general-purpose MK, so everything is simpler here, but it will perform our function.

We will need the TIM1 timer, only it can insert a hardware delay between signals, in the section on writing software I will tell you how to do this, but now let’s look at the result and what should be there:

To see the delay, we “stretch” the signal on an oscilloscope, because it has a short duration of about 300 ns. The required deadtime must be calculated for each specific task in order to protect the transistors from through currents. The delay duration is configured when initializing (setting) the TIM1 timer. This delay is present at both the leading and falling ends of the signal.

6. Writing firmware for the STM32 microcontroller

Here we come to probably the most important and interesting part. We have analyzed the physics of the process, the principle of operation seems to be clear, the required minimum of protection has also been determined - all that remains is to implement all this in real hardware. For this I use the STM32VL-Discovery board, by the way, I received it back in 2011 at a time when ST gave out debugs for free at their conferences and since then it has been packed - I opened the package just a couple of months ago, it seems that the expiration date has not passed))) My “stand” for writing code looks like this:

Now let's go through the connection. Since I need to generate two signals with different frequencies, I had to use the PWM outputs on different timers. TIM1 generates a signal that sets the fundamental frequency of 50 Hz and supplies it to transistors VT3 and VT4. PWM channel No. 3 + its complementary output is used. Yes, yes, in STM32 hardware deadtime can only be configured between the normal and complementary output of one channel, which I really didn’t like. The process of sine formation itself is transferred to the TIM2 timer, there is no need for a delay (I wrote earlier why) and it is quite suitable for generating a modulated signal on VT1 and VT2.

Outputs used:

  • PA10 is a regular PWM output, channel No. 3 of the TIM1 timer, which generates 50 Hz to transistor VT3
  • PB15 - complementary output of channel No. 3 of the TIM1 timer, which is supplied to transistor VT4
  • PA0 is the output of PWM channel No. 1 of the TIM2 timer. Provides a modulated signal to VT1
  • PA1 is the output of PWM channel No. 2 of the TIM2 timer. Provides a modulated signal to VT2
The project was implemented in the Keil 5 environment; it will be attached to the archive at the end of the article. I hope it’s not worth telling how to create a project and similar obvious things; if such questions arise, then I advise you to look at how to do it on Google or on YouTube. All code is written in CMSIS (registers), because... It is simply a sin to use any additional levels of abstraction in the converter control system! For ST, these are SPL libraries and more relevant HALs. For fun, I worked with both of them, the conclusion is complete rubbish. HAL is generally incredibly slow and is simply not suitable for applications with hard real-time. In some critical moments, the registers were many times faster; by the way, I found more than one article on this on the Internet.

Some will probably ask: “Why not use DMA?” This can and should be done, but this article is more of an informational nature, and the MK itself does not do anything complicated in terms of calculations, so there’s definitely no limit to the performance of the kernel. DMA is good, but you can do without DMA without any potential problems. Let's clarify what we need to do in the program:

  1. Create an array with our 240 sine points
  2. Configure the clock circuits to a frequency of 24 MHz by selecting an external quartz crystal source
  3. Set the TIM1 timer to generate 50 Hz PWM with deadtime enabled
  4. Configure TIM2 to generate PWM with a carrier frequency of 24 kHz
  5. Set up a TIM6 timer that generates interrupts at 24 kHz. In it we will send the next duty cycle value from the table to the TIM2 timer, and also alternate the generation of half-waves
Nothing complicated, right? Then let's go...

6.1. Creating a sine table

Everything is simple here, a regular array. The only thing worth remembering is that we have 120 points from 0 to 1000. We need to add another 120 points to the table, but in the reverse order:

Uint16_t sin_data = (13,26,39,52,65,78,91,104,117,130,143,156,169,182,195,207,220,233,246,258, 2,394,406,418,430,442,453,465,477,488,500, 511,522,533,544,555,566,577,587,598,608,619,629,639,649,659,669,678,688,697,707, 716,725,734,743,751,760,768,777,785,793,801,809,816,824,831,838,845,852,859,866, 872,878,884,891,896,902,908,913,918,923,92 8,933,938,942,946,951,955,958,962,965, 969,972,975,978,980,983,985,987,989,991,993,994,995,996,997,998,999,999,999,1000, 9,999,999,998,997,996,995,994,993,991,989,987,985,983,980,978,975,972,969,965,962,958,955,951,946,942,938,933,928,923,918,9 13,908,902,896,891,884,878,872,866, 859,852,845,838,831,824,816,809,801,793,785,777,768,760,751,743,734,725,716,707, 8,678,669,659,649,639,629,619,608,598,587,577,566,555,544,533,522,511,500, 488,477,465,453,442,430,418,406,394,382,370,358,3 46,333,321,309,296,284,271,258, 246,233,220,207,195,182,169,156,143,130,117,104,91,78,65,52, 39,26,13);

6.2. Setting up the clock system

The clock setting in STM32 is very flexible and convenient, but there are several nuances. The sequence itself looks like this:

1) Switch to clocking from the built-in RC chain (HSI) to external quartz (HSE), then wait for the readiness flag

RCC->CR |= ((uint32_t)RCC_CR_HSEON); // Enable HSE while (!(RCC->CR & RCC_CR_HSERDY)); // Ready start HSE
2) The controller's Flash memory works somewhat slower than the kernel; for this purpose, we adjust the flash clocking. If this is not done, the program will start, but will periodically crash: a couple of kW and unstable software are incompatible things.

FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; // Clock Flash memory
3) We set dividers for the system clock bus (AHB) and for the peripheral buses, of which there are two: APB1 and APB2. We need the maximum frequency, so we don’t divide anything and make the division coefficients equal to 1.

RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // AHB = SYSCLK/1 RCC->CFGR |= RCC_CFGR_PPRE1_DIV1; // APB1 = HCLK/1 RCC->CFGR |= RCC_CFGR_PPRE2_DIV1; // APB2 = HCLK/1
4) We adjust the frequency multiplier (PLL) prescaler, which stands in front of it and divides the quartz frequency by 2. We get that 8 MHz is divided by 2 and we get 4 MHz. Now we need to multiply them by 6 so that the output is 24 MHz. Before writing registers, let's first erase their contents just in case.

RCC->CFGR &= ~RCC_CFGR_PLLMULL; // clear PLLMULL bits RCC->CFGR &= ~RCC_CFGR_PLLSRC; // clearn PLLSRC bits RCC->CFGR &= ~RCC_CFGR_PLLXTPRE; // clearn PLLXTPRE bits RCC->CFGR |= RCC_CFGR_PLLSRC_PREDIV1; // source HSE RCC->CFGR |= RCC_CFGR_PLLXTPRE_PREDIV1_Div2; // source HSE/2 = 4 MHz RCC->CFGR |= RCC_CFGR_PLLMULL6; // PLL x6: clock = 4 MHz * 6 = 24 MHz
5) Now you need to turn on the frequency multiplier (PLL) and wait for the readiness flag:

RCC->CR |= RCC_CR_PLLON; // enable PLL while((RCC->CR & RCC_CR_PLLRDY) == 0) () // wait till PLL is ready
6) And finally, we configure the clock source for the system bus (AHB) - the output of our frequency multiplier, which has the coveted 24 MHz. First we clear the contents of the register, set the required bit and wait for the ready flag:

RCC->CFGR &= ~RCC_CFGR_SW; // clear SW bits RCC->CFGR |= RCC_CFGR_SW_PLL; // select source SYSCLK = PLL while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1) () // wait till PLL is used
As a result, we get the following clock setting function:

Void RCC_Init (void)( RCC->CR |= ((uint32_t)RCC_CR_HSEON); // Enable HSE while (!(RCC->CR & RCC_CR_HSERDY)); // Ready start HSE FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; // Cloclk Flash memory RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // AHB = SYSCLK/1 RCC->CFGR |= RCC_CFGR_PPRE1_DIV1; // APB1 = HCLK/1 RCC->CFGR |= RCC_CFGR_PPRE2_DIV1; RCC->CFGR &= ~RCC_CFGR_PLLMULL; // clear PLLMULL bits RCC->CFGR &= ~RCC_CFGR_PLLSRC; // clearn PLLSRC bits RCC->CFGR &= ~RCC_CFGR_PLLXTPRE; // clearn PLLXTPRE bits RCC->CFGR |= RCC_CFGR_PLLSRC_PREDIV1; // source HSE RCC->CFGR |= RCC_CFGR_PLLXTPRE_PREDIV1_Div2; // source HSE/2 = 4 MHz RCC->CFGR |= RCC_CFGR_PLLMULL6; // PLL x6: clock = 4 MHz * 6 = 24 MHz RCC->CR |= RCC_CR_PLLON ; // enable PLL while((RCC->CR & RCC_CR_PLLRDY) == 0) () // wait till PLL is ready RCC->CFGR &= ~RCC_CFGR_SW; // clear SW bits RCC->CFGR |= RCC_CFGR_SW_PLL; // select source SYSCLK = PLL while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1) () // wait till PLL is used )

6.3. Setting the TIM1 timer and “dead time”

I will give the general setting of the timer, it is described in detail in the reference manual - I advise you to read the purpose of each register. Yes, and there are basic articles on working with PWM on the Internet. My code itself is quite well commented, so I’ll just give you the code for the TIM1 timer initialization function, and let’s look at the most interesting points:

Void PWM_50Hz_Init (void)( RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // enable clock for TIM1 RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for port A RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // enable clock for port B RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for alternative gpio /**************************** Setting PA10 ** ************************************/ GPIOA->CRH &= ~GPIO_CRH_CNF10 // setting out alternative push-pull for PWM GPIOA->CRH |= GPIO_CRH_CNF10_1; GPIOA->CRH &= ~GPIO_CRH_MODE10; GPIOA->CRH |= GPIO_CRH_MODE10; // gpio speed 50 MHz /************ ***************** Setting PB15 ************************************** ********/ GPIOB->CRH &= ~GPIO_CRH_CNF15; // setting complementary for CH3N GPIOB->CRH |= GPIO_CRH_CNF15_1; /gpio speed 50 MHz /******************************** Config PWM channel *************** ********************************/ TIM1->PSC = 480-1; // div for clock: F = SYSCLK / TIM1->ARR = 1000; count to 1000 TIM1->CR1 &= ~TIM_CR1_CKD; // div for dead-time: Tdts = 1/Fosc = 41.6 ns TIM1->CCR3 = 500; // duty cycle 50% TIM1->CCER |= TIM_CCER_CC3E | TIM_CCER_CC3NE; // enable PWM complementary out TIM1->CCER &= ~TIM_CCER_CC3NP; // active high level: 0 - high, 1 - low TIM1->CCMR2 &= ~TIM_CCMR2_OC3M; TIM1->CCMR2 |= TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1; // positiv PWM TIM1->BDTR &= ~TIM_BDTR_DTG; // clear register TIM1->BDTR |= TIM_BDTR_DTG_2 | TIM_BDTR_DTG_1 | TIM_BDTR_DTG_0; // value dead-time TIM1->BDTR |= TIM_BDTR_MOE | TIM_BDTR_AOE; // enable generation output /************************************************ **********************************/ TIM1->CR1 &= ~TIM_CR1_DIR; // count up: 0 - up, 1 - down TIM1->CR1 &= ~TIM_CR1_CMS; // aligned on the front signal TIM1->
Our duty cycle is fixed and never changes, just like the frequency. It is this timer that sets the time and sequence of operation of the diagonals:

TIM1->CCR3 = 500; // duty cycle 50%
The duration of the “dead time” pause depends heavily on the TDTS time parameter, which is configured here:

TIM1->CR1 &= ~TIM_CR1_CKD; // div for dead-time: Tdts = 1/Fosc = 41.6 ns
Its duration is 1 clock tick. If you look in the reference manual, you can see that CKD bits can, for example, make Tdts equal to 2, 8 ticks, etc.

The pause time itself is set here:

TIM1->BDTR |= TIM_BDTR_DTG_2 | TIM_BDTR_DTG_1 | TIM_BDTR_DTG_0;
If you open reference manual RM0041, you will see these formulas for calculating DT. As you can see, the Tdts parameter is fundamental there:

6.4. Setting the TIM2 timer, generating a sine

Here everything is even simpler; there is probably no point in explaining something in the settings, because the comments are already redundant. If you have any questions, I’m waiting for them in the comments.

Void PWM_Sinus_Init (void)( RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // enable clock for TIM2 RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for port A RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // enable clock for alternative gpio /*********************************** Setting PA0 ***************** **********************/ GPIOA->CRL &= ~GPIO_CRL_CNF0; // setting out alternative push-pull for PWM1_CH1 GPIOA->CRL |= GPIO_CRL_CNF0_1; GPIOA->CRL &= ~GPIO_CRL_MODE0; GPIOA->CRL |= GPIO_CRL_MODE0; // gpio speed 50 MHz /************************** **** Setting PA1 *************************************************/ GPIOA->CRL &= ~GPIO_CRL_CNF1; // setting out alternative push-pull for PWM1_CH1 GPIOA->CRL |= GPIO_CRL_CNF1_1; GPIOA->CRL &= ~GPIO_CRL_MODE1; ************************ Config PWM channel *********************** ************/ TIM2->PSC = 0; // div for clock: F = SYSCLK / TIM2->ARR = 1000; // count to 1000 TIM2->CCR1 = 0; / duty cycle 0% TIM2->CCR2 = 0; // duty cycle 0% TIM2->CCER |= TIM_CCER_CC1E; // enable PWM out to PA8 TIM2->CCER &= ~TIM_CCER_CC1P; // active high level: 0 - high, 1 - low TIM2->CCER |= TIM_CCER_CC2E; // enable PWM complementary out to PA9 TIM2->CCER &= ~TIM_CCER_CC1P; // active high level: 0 - high, 1 - low TIM2->CCMR1 &= ~(TIM_CCMR1_OC1M | TIM_CCMR1_OC2M); TIM2->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1; // positive PWM1_CH1 and PWM1_CH2 /*************************************************** ************************************/ TIM2->CR1 &= ~TIM_CR1_DIR; // count up: 0 - up, 1 - down TIM2->CR1 &= ~TIM_CR1_CMS; // aligned on the front signal: 00 - front; 01, 10, 11 - center TIM2->CR1 |= TIM_CR1_CEN; // start count )

6.5. Configuring TIM6 timer interrupts

We set the timer itself to a frequency of 24 kHz:

Void TIM6_step_init (void)( RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; // enable clock for basic TIM6 TIM6->PSC = 1-1; // div, frequency 24 kHz TIM6->ARR = 1000; // count to 1000 TIM6 ->DIER |= TIM_DIER_UIE; // enable interrupt for timer TIM6->CR1 |= TIM_CR1_CEN; // start count NVIC_EnableIRQ(TIM6_DAC_IRQn); // enable interrupt TIM6_DAC_IRQn)

6.6. Implementation of the main control algorithm

The main events occur in the interrupt generated by the TIM6 timer. An interrupt is generated every 41.66 µs, if you remember this is our sampling step. Accordingly, the interrupt writes the duty cycle value from the table to the register CCRx. This interrupt also determines which diagonal is currently being drawn by inverting the flag sin_status after each half cycle. We display 240 points, invert the flag, which causes control to pass to another channel, when it has already drawn, the flag is inverted again and everything repeats. Main algorithm code:

Void TIM6_DAC_IRQHandler(void)( TIM6->SR &= ~TIM_SR_UIF; if(sin_status == 0)(TIM2->CCR1 = sin_data;) if(sin_status == 1)(TIM2->CCR2 = sin_data;) sin_step++; if (sin_step >= 240)( sin_step=0; sin_status = sin_status ? 0: 1; ) )

Results

Download the project, compile it and upload it to your microcontroller and get a working inverter. All you have to do is make a bridge and send signals to it:

I posted one of my bridge diagrams a little earlier in PDF, you can use it as much as you like, I hope it will help you in mastering power electronics.

I hope you liked the article. If you have any questions about using this code in real hardware, I will be glad to answer them. Also, please do not take this code as something ready-made; this is the core of the converter, which implements the main function. You can add all the bells and whistles yourself. The bare core of the project will allow you to understand how it works and not spend a lot of time disassembling the code.