logo elektroda
logo elektroda
X
logo elektroda

Inverter in half-bridge topology on STM32G474 controlled from a PC

_lazor_ 10032 6
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Inverter in half-bridge topology on STM32G474 controlled from a PC
    The project aimed to create control board for half-bridge topology with the possibility of setting the frequency using a computer program. Additionally, control board has synchronous sampling of the current waveform for accurate phase and amplitude measurements and plotting the graph of these parameters on a PC. This type of circuit is useful for measuring SMPS transformers (in this case used in half-bridge or full-bridge topology) in an open loop. We can thus determine the maximum gain of our transformer and with the appropriate modification of the software plot a Bode chart. At the same time, the project is a development of the previous software on which I made, among others, such "toys":















    Of course, these are not the only possibilities of such a system, it is even possible to generate a sine at the output using SPWM (https://www.sciencedirect.com/topics/engineering/full-bridge-inverter fig 1.18), to power tesla coils or other devices where AC voltage waveform is required.
    Having a ready platform, you can focus on creating your own software or using ready-made software to examine your work, so you can limit the space where you can make a mistake and thus developing your ideas will be much easier. If anyone is curious whether his idea would be possible to implement on this type of device then feel free to ask a question.

    How to download and run the code.

    The code can be downloaded from the github repositories:
    https://github.com/marcinszajner/Half-bridge-driver-MCU
    https://github.com/marcinszajner/Half-bridge-driver-python
    1. Install cygwin with make
    2. Add cygwin bin folder to environment variables
    2. download gnu toolchain
    https://developer.arm.com/tools-and-software/...software/developer-tools/gnu-toolchain/gnu-rm
    3. Add gnu toolchain to environment variables
    4. Install openOCD
    5. Add openOCD bin to environment variables
    6. Install the st-link drivers
    7. Clone the Half-bridge-driver-MCU repository
    8. Call make in the project folder
    9. To make uC flash, make make flash.

    1. Install python 3.8
    2. Install pyCharm and configure it for python 3.8
    3. Install Qt designer
    4. Clone the Half-bridge-driver-python repository, download the project to pyCharm
    5. Install requirements.txt (python -m pip install -r requirements.txt) or do it via pyCharm
    6. Run main in pycharm

    To edit the graphic interface I recommend using Qt designer. All you have to do is open the gui.main.ui file, edit it and then use the toPyCode.sh script to convert it to a .py file

    And how does it work in practice? Here is a recording presenting the operation of the control board (with RLC load):




    Hardware

    Unfortunately, some time ego I lost schematics to this prototype version, but I attach the schematic diagram and a description of the elements used.

    Inverter in half-bridge topology on STM32G474 controlled from a PC


    I use a current transformer (CS1050L) to measure the current. The signal from the transformer passes through the rectifier bridge and then to a 15Ohm measuring resistor. Using the fact that the current transformer output is a current source, the diodes in the rectifier bridge do not introduce too much error in the measurement. I measure the voltage across the measuring resistor via ADC with uC. Although I don't have any low-pass filter at the input to the ADC, the first harmonic resonance measurement results are very good and comparable to the I-prober 520. However, the signal on the resistor is strongly distorted which requires improvement in the newer PCB version.


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    I'm using l6384 as the half-bridge driver. However, this is not the best driver for frequencies above 100kHz. 500ns dead time is definitely noticeable.

    Inverter in half-bridge topology on STM32G474 controlled from a PC

    A - delay caused by signal propagation in the circuit. B - Dead time driver.
    The delay associated with the propagation of the control signal does not cause any problem, however, a dead time of 500ns which is 1/20 of the whole signal seriously affects the entire system.


    In new version of PCB I planing use driver similar to tlp250 and set dead time on control board.
    400 mA source and 650 mA sink current are not very suitable for mosfets with a large gate load. When the half bridge is powered from 30V it does not matter, but at 325V it will be of great importance and cause large losses on commutation of keys.


    MCU
    For power electronics purposes, only two relatively affordable families are available on the market - C2000 from TI and a series of dedicated SoCs from ST with cortex-m4. I decided on the ST company and their NUCLEO64 board with the stm32g474 chip. It is the successor of the stm32f334 system. The main feature of this system is HRTIM, which in the case of actual software operates at a equivalent frequency of... 2.72GHz which provides a resolution of 368ps. This gives the possibility of very precise control of the output frequency of the half bridge.
    Side extras that we find on this SoC include:
    - Adaptive real-time accelerator
    - FPU, DSP instructions
    - CORDIC for trigonometric functions acceleration
    - FMAC: filter mathematical accelerator
    - CCM SRAM
    - amplifiers, ADC, DAC, comparators


    GUI PC

    To make some of the software on the PC side I used the PYTHON script language with the PyQt library. Why? I wanted to gain some experience in this language and its use in this type of projects. The use of Qt designer makes GUI creation and modification quite easy, and the python itself surprisingly proved itself as a language for this type of application, although there were surprises like strange behavior of threads or methods not working as described, but fortunately sporadically.
    Overall, I'm satisfied to use Qt with python.

    Program at uC

    In general, not much is happening here. In the main function we initialize GPIO, ADC, crc, hrtim, USART from DMA. Then start hrtim and switch to blinking LED to check that the microcontroller is not too expropriated by interrupts.
    Communication with a PC consists of receiving a message with a request, properly processing it and sending a reply if necessary. The code on the PC side ensures that only one message is sent that requires a response. There are currently only two types of messages:

    protocol_change - A message that does not require a response to change the state of the system (currently the frequency)
    protocol_data_req - A message requesting data. The answer is protocol_data_resp

    Sampling is done by interrupting ADC in inject mode. ADC is triggered by compare unit hrtimera, which ensures sampling at the right point in the timeline (in the right phase). Unfortunately, this solution is bad because it allows me to achieve about 2.5MHz sampling frequency, which is a bit too low and will require rewriting the functionality of collecting samples.

    USART from DMA works almost maintenance-free, all you have to do is enter the pointer to the beginning of the buffer and the number of bytes to send, so it doesn't consume too much core resources.


    Theory of signal processing

    Fast fourier transformate is an algorithm for discrete fourier transfoemate, which is a transform for a discrete (not continuous) space, and the fourier transform is contained in the Laplace transform.
    This is best illustrated by the graphic representation.

    Inverter in half-bridge topology on STM32G474 controlled from a PC


    This is a special case of the Laplace transform. The number s can be represented as the pair σ + jω, and the fourier transform is the case when σ (sigma) is equal to zero. What is sigma at all? It is attenuation constant or dumping factor. We can see it nice on LLC converter characteristic, when we draw fourier plot for few loads:
    Inverter in half-bridge topology on STM32G474 controlled from a PC


    So, using the Fourier transform, we actually operate on a segment of the Laplace transform for sigma = 0. Unfortunately, in this case we lose information resulting from transient states, as for example the signal decay time for the low-pass RC filter.
    However, if we are not interested in transient states and want to focus on periodic waveforms, we can replace s with jω value or perform Fourier transform at once.

    Take for example the transfer function:


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    With digital technology, however, we do not analyze a continuous signal (neither in time nor in values), but individual points in space - a discrete signal.
    In this case, I don't want to delve into the Z and DFT transform anymore, just go to the level of FFT abstraction (the numpy module uses the Cooley-Tukey algorithm).

    Below I present very basic information that is useful, but it is worth being aware that this is not all that fft and DSP offer.
    We make FFT on an N elemental sample vector (window). The algorithm itself knows nothing about frequency, this information is provided by the user when analyzing the obtained complex vector. Exactly so, the result in the Laplace transform is the complex vector of numbers. These numbers carry for us all relevant information - the length of the vector and the slope of the vector to the positive axis of real numbers for the corresponding frequency. I think for most the concept of magnitude is not foreign and is quite well understood, but with the phase it is a bit worse.
    What is the phase? The phase is nothing but... time, and more precisely the time of delay between one signal and another. How is it between two signals? After all, in the vector we only have the signal we sample. Here we have to mention the sample window. To get the best accuracy for the fft algorithm, integer number of periods of signal should be in the sampling window and it should be an even function to get zero phase shift. If we examine the course of cos (50 * 2 * pi * t), we will get a beautiful amplitude and zero phase shift. However, when we try to draw something (50 * 2 * pi * (t + 0.0025)) or something (50 * 2 * pi * t + 0.785375) it gives us a phase shift of 45 degrees.


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    However, what if the samples do not contain the integer number of periods of the tested signal. Unfortunately, then the quality of the result decreases significantly and a spectrum leak occurs:


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    To counteract this, we can impose window functions that allow you to reduce the problems arising from the incomplete multiplicity of the signal being tested and thus the spectrum leakage.

    For the above reason, the assumption of my software was synchronous sampling in order to obtain the integer number of periods of the tested signal. Thanks to this procedure, we can get a very accurate signal phase and amplitude using a very small number of samples. In addition, the signal does not require additional processing in the form of overlapping window functions or interpolation, so the digital processing of such a signal is very fast, either on uC or on the PC. The current program, unfortunately, does not allow obtaining too high sampling frequency (8 samples per period), which does not allow to get a view for the higher harmonics of the tested signal, however I will try to improve the program to get 16 or even 64 samples per period (for a certain frequency range).

    I take the signal from a current transformer with a rectifier bridge, which introduces two significant distortions:
    1. The signal is no longer a sine / cosine
    2. Deletes the constant component

    Sine restoration is very simple, based on fourier sequence for the upright signal:


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    Adding further harmonics and a constant component, we reproduce the sine/cosine waveform with phase shift and double frequency. However, these distortions are constant and we can remove them in the process of subsequent analysis of the fft result.
    The bigger problem starts when the tested system has a constant component. If we have an AC signal containing an additional DC component, I suspect that we can analytically reproduce it, but when the DC component is dominant (the signal is DC), I do not see the possibility of reproducing it. That's why I'm thinking about adding a measuring resistor to measure the DC component of the signal and add it to the obtained signal from fft.


    sources
    (1)
    https://books.google.pl/books?id=866PDwAAQBAJ...&q=plot%20laplace%20transform%20phase&f=false

    (2)
    https://books.google.pl/books?id=wnpTDwAAQBAJ...QAQ#v=onepage&q=plot%20laplace%20transform&f= false

    (3)
    https://download.ni.com/evaluation/pxi/Understanding%20FFTs%20and%20Windowing.pdf

    (4)
    https://books.google.pl/books?id=GV5mDwAAQBAJ...HcfrA6UQ6AEwCnoECAkQAQ#v=onepage&q=rectified% 20sine% 20reconstruct% 20to% 20sine & f = false

    As I will soon be modernizing the whole control board, including wireless communication with a PC, more inputs (4 + 1 transformer), improved the quality of measuring paths and a half bridge control system, I have a question for you, what would you like to see in such a system? Maybe the system will be useful to a larger number of users due to additional functionalities?

    Cool? Ranking DIY
    About Author
    _lazor_
    Moderator of Designing
    Offline 
    _lazor_ wrote 3795 posts with rating 1127, helped 259 times. Live in city Wrocław. Been with us since 2016 year.
  • ADVERTISEMENT
  • #2 18800169
    TechEkspert
    Editor
    Very interesting tests, but I do not understand everything.

    "I use a current transformer (CS1050L) to measure the current. The signal from the transformer passes through a rectifier bridge and then to a 15 Ohm measuring resistor. Using the fact that the current transformer output is a current source, the diodes in the rectifier bridge do not introduce an error of measurement."

    1. Is it about the fact that the current source forces a certain current and this eliminates the non-linearity of the diodes?


    "The main feature of this system is HRTIM, which in the case of current software operates at a frequency of ... 2.72GHz which provides a resolution of 368ps. This gives the ability to very accurately control the output frequency of the half-bridge."

    2. The high clock frequency of the timer is high resolution, but also accuracy? I assume that there is PLL and some pattern, will the resulting accuracy depend on its stability and loop work?


    "Program at uC
    In general, not much is happening here. In the main function we initialize GPIO, ADC, crc, hrtim, USART from DMA. Then start hrtim and switch to blinking LED to check that the microcontroller is not too expropriated by interrupts.
    Communication with the PC consists of receiving a message with a request, appropriate processing and, if necessary, sending a response "


    3. Is FFT doing an MCU now or are the post-acquisition samples transferred to a PC and the FFT calculated in python?


    "Fast fourier transformate is an algorithm for discrete fourier transfoemate, which is a transform for a discrete (not continuous) space, and the fourier transform is contained in the Laplace transform."

    4. DFT (FFT) as I understand it, it would be useful to explain Laplac transform one day ;)


    "I think for most the notion of magnitude is not foreign and is quite well understood, but with the phase it is a bit worse.
    What is the phase? The phase is nothing but ... time, and more precisely the time of delay between one signal and another. How is it between two signals? After all, in the vector we only have the signal we sample. Here we have to mention the sample window. To get the best accuracy for the fft algorithm, the full fold of the signal period should be in the sampling window and it should be an even function to get zero phase shift. If we examine the course of cos (50 * 2 * pi * t), we will get a beautiful amplitude and zero phase shift. However, when we try to draw something (50 * 2 * pi * (t + 0.0025)) or something (50 * 2 * pi * t + 0.785375) it gives us a phase shift of 45 degrees. "


    5. So the phase in FFT makes sense for periodic signals that we control (e.g. generate) and we can synchronize with sampling and choose its length, or synchronize as in an oscilloscope by triggering a specific voltage of repetitive waveform?

    So, e.g. for audio or noise, phase information will not give us meaningful information because we cannot synchronize with the waveform? ew. makes sense when we do FFT for measurements of an unpredictable signal at two points, e.g. in front of the amplifier and at its output, and then we will see how the frequency response, but also the phase change look like?


    "To counteract this, we can impose window functions that allow us to reduce the problems arising from the incomplete multiplicity of the tested signal and thus the spectrum leakage.

    For the above reason, the assumption of my software was synchronous sampling in order to obtain the full multiplicity of the tested signal period. Thanks to this procedure, we can get a very accurate signal phase and amplitude using a very small number of samples. In addition, the signal does not require additional processing in the form of overlapping window functions or interpolation, so the digital processing of such a signal is very fast, either on uC or on the PC. "


    6. So the windows (they are different, I still don't know how to choose them sensibly) we use for standard unpredictable signals, but if we strictly control the sampling time and synchronization with periodic waveform, should we even skip window functions?


    "The bigger problem starts when the tested system has a DC component. If we have an AC signal containing an additional DC component, I suspect that we are able to play it analytically, but when the DC component is dominant (the signal is DC), I do not see the possibility of reproducing it. Therefore, I think about adding a measuring resistor to measure the DC component of it and add it to the obtained signal from fft. "

    7. So you want to add such an additional "voltmeter" channel that adds information to the data acquisition system?


    "As I will soon modernize the whole system, including wireless communication with a PC, more inputs (3 + 1 transformer), it improved the quality of measuring tracks and the half bridge control system"

    8. Currently, the MCU board is isolated from the power control and measurement board, which gives you a wireless connection, convenience?

    What type of wireless connection do you plan to use?

    Will a greater number of measurement inputs cause a problem with simultaneous measurements (time shift between measurements on subsequent channels)?
  • ADVERTISEMENT
  • #3 18800665
    _lazor_
    Moderator of Designing
    I will answer the questions here, but it will take me a while, so I will modify this post by answering the next questions.

    Question 1
    Yes, the current flowing in the transformer is proportional to the current flowing in the tested circuit, to some extent independent of the load. To some extent, because we give too much load, part of the current will flow to the magnetizing circuit of the core and thus we will lose the linear character and thus introduce an error in the transformer.

    Question 2
    Here, in my opinion, ST tried very hard and the HRTIM calibration is properly done and the circuit itself holds the frequency accurately even with a change in temperature (HRTIM has temperature compensation circuits). So jitter is not noticeable in this case ;)

    Question 3
    I am currently doing fft on the PC side, but if I want to do feedback then uC will do it most. ST provides a library with a ready implementation of fft and a trigonometry coprocessor, so there is hardware phase counting support (Atan2).

    Question 4
    It would be useful to bring the Laplace and Z transforms closer, but time is in this case a very strong limiting factor.

    Question 5

    At a low sampling frequency, it won't give us meaningful information, because everything will spill and will be of little use. I will give some illustrative examples here. First wave containing 2 periods of cos 50 Hz with a 45 degree offset in the window with a sampling frequency of 1600 Hz


    Inverter in half-bridge topology on STM32G474 controlled from a PC

    Well, this chart is also not completely in the window and you can already see a small leak, but roughly ok (the phase is a bit too big, but it's the fault of numerical accuracy, I don't really want it and it's time to fight it to be perfect)


    The next chart will be more serious if you don't fit in the window

    Inverter in half-bridge topology on STM32G474 controlled from a PC


    As you can see, an additional 15 samples and phase chart is completely useless.


    Now let's significantly increase the sample rate, say to 12800 Hz


    Inverter in half-bridge topology on STM32G474 controlled from a PC


    As we can see, the larger the sampling, the more accurate the result, but you have to sample many times faster, which is why synchronization is so important in my project, because you can get very high accuracy with a sampling frequency of only 8 times the base signal.

    Below is the python code:
    Code: Python
    Log in, to see the code


    question 6.
    The function of the window could be said that we can not ignore because the basic window is a rectangular window. Is it worth choosing another window, it is more complex, because such an action affects the input signal (time windows are filters in total) and the situation will depend on which window is appropriate.

    Question 7 and 8
    He wants to add some additional channels (ADC on SoC is 5) and leave their application to the user whether he wants to measure the resistor or additional transformer winding (bias winding) or output voltage or all at once.
    As there are 5 independent ADCs, there is no problem with running them at the same time, so there will be no errors in phase.
    First of all, a wireless connection will give you comfort and security. Tinkering a near-working device is sometimes quite an unpleasant experience (mosfets get damaged ... effectively). Therefore, control on the PC side will provide greater security and (mental) comfort when starting and analyzing circuits.

    When designing a power circuit for full and half-bridge, such an adjustable inverter is a must have in the workshop. By connecting the transformer to the reference board, we are able to determine whether our calculations are consistent with reality.
    Starting your own inverter + transformer are two potential problems and if something goes wrong, you never know what the cause was, and so we can eliminate one of them at the very beginning.
  • ADVERTISEMENT
  • #4 18801831
    Sareph
    Level 24  
    TechEkspert wrote:
    2. The high clock frequency of the timer is high resolution, but also accuracy? I assume that there is PLL and some pattern, will the resulting accuracy depend on its stability and loop work?
    HRTIM does not work with such a high frequency, but with such an "equivalent frequency", there is a Delay-Locked Loop (DLL).
  • #5 18813511
    _lazor_
    Moderator of Designing
    I have prepared idea schematic for new half bridge control board:

    Inverter in half-bridge topology on STM32G474 controlled from a PC


    I planned these features for this revision
    - Synchronized sampling of all ADC inputs
    - Plot ADC inputs amplitude and phase
    - Variable frequency controlled from PC
    - Wireless communication
    - programable dead time, but protected from open two switches by isolated driver on diode.
    - Fast turn off mosfet by PNP transistor near gate.
    - default soft for measure and processing all 5 ADC
    - overcurrent protection (programable)
    - 5 ADC inputs.
    - Half-bridge externally power supplied.

    What is idea for this half bridge control board?
    Idea is for boost time and simplified process of design SMPS transformers design. I saw many people have problem with creating own half bridge, make many mistakes, and fail at last :( We could remove one area where we could make mistake, that make much easier create own SMPS.
    Additionally current probes are expensive, but there are invaluable in when we testing and measure characteristic of our transformer. I plan add possibility to measure current by resistor in series with half-bridge output or by current transformer. STM32G474 have a bit slow ADC (only max 4Msps) that is not bad for analyze signal but not nice for human eye, that why I plan tests points to connect oscilloscope with much performance. I have I-prober 520, but most of time I use (in prototype board) current transformer that is enough for testing new transformer and is much comfortable to use.

    I planned that the half bridge voltage would be external. There will be upper limit for voltage (probably 600V) but anyone could use their voltage source. Current limit will be depend on topology and frequency. Hard switch topology with high frequency will have much lower current capability that soft switch topology. I will add some program to calculate if control board could withstand with designed transformer and load.

    Because program for control board will be open source any one could modify it for own purpose. Of course I will make some examples for easy start. Like on concept proof software – example with measure and analyse for ADC inputs in sweep mode or manual. All will be developed over time.

    Now is question to you, You see any posibility to improve this idea? Maybe some functionality that will help you in develop your project? Or something that nice to have in this kind of device?
    All comments are welcome!
  • #6 18815456
    TechEkspert
    Editor
    The design is so thoughtful that it is still difficult to add something, but I thought about additional configurable trigger outputs for the oscilloscope, e.g. you can trigger the oscilloscope before opening the key or other action and observe in a stable way what is happening.
    I don't know if it applies and whether it is done that way.

    When I did simple experiments with switching transformers in zero or max. sine wave:
    https://www.elektroda.pl/rtvforum/topic3672449.html
    such "digital" triggering was very useful.
  • ADVERTISEMENT
  • #7 18815508
    _lazor_
    Moderator of Designing
    Usually, I used the bridge control signal (pin on uC) to trigger the oscilloscope. Even when I used burst mode, there was no trigger problem:




    With digital oscilloscopes, there is also no problem with suspecting what happened some time before the trigger.


    In general, the project has evolved again (and probably will continue). I thought that designing an analog circuit with not the worst parameters without the possibility of disconnecting it from the entire inverter is a bit of a waste of resources, so I'm thinking about the version where there will be a separate PCB for the measuring part, and it will be added as a shield to the inverter.
    It is slowly transformed into a form of an active probe, with the ability to analyze the signal on a PC, wireless communication and the ability to generate a rectangular signal to control switching power supplies of different topology (in this case, you can connect the "card" to the converters).

Topic summary

The discussion revolves around the development of a control board for a half-bridge inverter topology using the STM32G474 microcontroller, which allows frequency adjustments via a PC interface. The project includes synchronous sampling of current waveforms for precise phase and amplitude measurements, facilitating the analysis of SMPS transformers. Key features discussed include the use of a current transformer (CS1050L) for current measurement, high-resolution HRTIM for accurate frequency control, and the potential for generating sine waves using SPWM. Additional enhancements proposed include wireless communication, programmable dead time, overcurrent protection, and a separate PCB for measurement components. The design aims to simplify the creation of SMPS transformers and reduce common design errors.
Summary generated by the language model.
ADVERTISEMENT