 Hi, my name is Ali Sher-Savar and welcome to this Breacher Digital ST Step-by-Step Digital Power Supply Design webinar using STM32. Over the next hour or so we're going to have a quick introduction to digital power then we're going to delve into a step-by-step design of digital power supplies including control loop design and coefficient calculations and after that we are going to introduce a software which does all the calculations for you and gives you all the coefficients and so on. This software is available freely from our link up here and then we're going to have some really nice demonstrations based on what we talk about to show in real life what happens when you design your power supply. We're going to make some loop measurements also we're going to show you some step responses and intrap timings and things like that. So first of all let's have a quick introduction to digital power. We start with an analog power supply. Now in the analog power supply everything is designed in continuous time. You get your power supply which is this power stage over here. You get your output voltage and you usually divide that down with a potential divider and that goes into an op-amp which is your compensator or your controller. It is typically represented by a transfer function. Please don't worry about that in this short webinar because the software that we use will actually help you to design your power supply without needing to know the details of the transfer function. However if you look at this op-amp you will see that you solder some capacitors and resistors and of course that shapes the frequency response of the entire power supply in order to meet the stability criteria. We're going to talk about that a little bit later. The output of this goes to the PWM which in an analog power supply is generated using a sawtooth waveform usually and a comparator and that width will change depending on your error. Like we've studied in control theory it goes and drives the plant. It drives this fed and therefore you've got a closed loop system. So in a digital power supply things are extremely similar. Your plant is still exactly the same however the real difference is that instead of just having a potential divider and an op-amp to create your compensator we do this digitally. Now this will give you some advantages. This has been very well documented so we won't go through all the advantages and disadvantages of analog versus digital. The objective is to learn how to design a digital power supply. So you get your output voltage this is in continuous time and then it goes into an ADC. So you sample with the ADC the output voltage inside of the microprocessor you have got a demand or reference voltage. So you compare the ADC real measured voltage with what you want. So this number coming out of here is what you're getting. This number in your code is what you want. The difference between these two is the error signal just like the op-amp and then the main difference is that that goes into a digital controller and you'll find that that is just one linear difference equation that in most cases which you calculate. The good news is that first of all the library functions for these linear different equations are already written for you and the software tools that we will provide for you is going to calculate all the coefficients for this. So effectively you get here a digital equivalent of the op-amp compensator you had just like analog the output goes into a PWM. In the analog world that was a sawtooth and a comparator. Here it's the PWM part of the silicon of the microprocessor which will output a PWM signal that goes to the plant which again is your analog part it drives the MOSFET and again you've got a closed loop system. So the trick is how do we design this controller in digital domain and that is what we're going to talk about in this webinar. Before we can do that we're going to have to talk about the power supply stability criteria. Now in our workshops we go through this in a great detail for this short webinar it's we're just going to have to concentrate on the main important points that you need to look at. When you consider the open loop frequency response of a power supply I'm going to show you a few of these and the software also shows you this open loop frequency response. At crossover frequency you'll want your phase margin to be better than 45 degrees. I usually aim for 55 to 60 degrees and the crossover frequency is the frequency at which the gain plot crosses the zero dB axis and the phase margin is how much at crossover frequency the phase plot is above the 180 degrees. Again you don't have to worry about these too much because the software will calculate crossover frequency and phase margin and it will display it for you so you don't even have to look at the body plot. Then at crossover frequency which is again the frequency at which the gain plot crosses the zero dB axis you want your gain uh you want the slope to be around 20 dB per decade and what I mean by that is that you want the slope to be shallow instead of sharp. That is again part of the stability criteria you can see it on the body plot but again if you don't want to look at the body plot the software will give you the slope it determines the slope and it prints it on the top corner as you will see so you will immediately see whether you get your 20 dBs or not. Now 20 dB is theoretical in practice you rarely get 20 dBs and anything around 25 dB is usually safe. Now finally gain margin again we discuss this in detail in various workshops and webinars there's lots of information on the internet the gain margin should be at least 10 dB and the gain margin is defined as when the phase hits minus 180 degrees how much the gain is below zero dB. You can see this on the body plot and again the software will just print it for you so you can quickly look at crossover frequency, phase margin, slope and gain margin just as numbers and and and we will know that whether the pass supply is going to be stable or not. There we go this is the body plot here. Now the green trace is what WDS has calculated this design absolutely everything and the black trace is the real measurement which I have measured with the BODY 100 network analyzer. Now this software is full version of it there's no there's no hidden locked features is available for download from this link here and you can look at the body plot you can work out your crossover frequency phase margin gain margin and slope however you can see right here that the software actually calculated for you so in my particular case I have got a crossover frequency of 10 kilohertz this is the green trace which is the calculated one as you can see because it's calculated is ideal you can see that it's almost perfect. I designed for 10 kilohertz I'm getting 10 kilohertz I wanted a phase margin of 50 I've got a good gain margin I've got nice slope now on my measured real measurement and again we will do this later on in this webinar I've got near perfect match I have got almost 10 kilohertz I've got almost 50 degrees and if you remember in the previous slide I said that the minimum was 45 degrees I usually aim for around 50 to 60 degrees but but this is all good 9 dBs of gain margin and slope of minus 24 anything above 25 I would start to become a little bit uncomfortable but this is a nice and stable power supply okay so here is the example of the analog power supply again as I showed you you have got your controller compensator this is the op-amp now you see this potential divider right here so output voltage gets through potential divider goes through the op-amp PWM generator and it drives the effect this is a digital power supply we've got our V out here and then you can see that I've got my ADC and I've got a digital controller which is inside of the microprocessor so again I start with a continuous time signal let's say that's my output voltage with ripple on it then I go to my ADC and the ADC will go sample sample sample sample sample sample right and that is this signal sampled through the ADC you can you can see just the contour of that signal over here and then these are now in discrete time so instead of the axis being time it's an n so that's your first sample or zero f sample first sample second sample and so on then your demand value in analog world was a reference attached to one leg of the op-amp in digital it is a number inside of the microprocessor so let's say you want 3.3 volts and what you're doing then at every sampling interval you compare this with that five microseconds later let's say you're switching at 200 kilohertz so your sampling interval is 1 over 200 kilohertz that'd be five microseconds so five microsecond later you compare this with that through this block five microseconds later you compare this with that and so on and you get a bunch of errors which looks like this so the green signal here you see is the difference between what you want here and what you're really getting here right then just like analog it goes through a controller analog it's an op-amp in our case is a linear difference equation which the software will calculate all the coefficients for now for simplicity let's say that the output of this controller is a number between zero to 100 in reality it's not in reality is actually much bigger and that number between zero to 100 goes into the PWM block which expects to get a number between zero to 100 and that gives you a duty between zero to 100 percent which will then drives the MOSFET and you have closed the loop okay so the digital equation here that's the important part is called a linear difference equation and it can perform almost exactly the same mathematical operation as our op-amp to give you an example here i've got a simple integrator so so this this you find this often as as just an integrator as a compensator you can see that the transfer function is minus one over src please don't worry about Laplace transforms and so on for this webinar i'm just going to try to show you that i can create a mathematical equation that gives me the same gain plot as this particular op-amp the equivalent linear difference equation for this is for this circuit is this again in our workshop we go through how you derive these equations we can don't have time to do it in this short webinar but have a look r and c you know if you know the analog circuit and ts is the sampling interval five microseconds for a 200 kHz power supply and everything else is in a library function so all you need is to to pass in these numbers right at the beginning right and these values come from either the adc or previous inputs and this is the output that the computer will calculate the microprocessor will calculate or within the library functions that are available and here are the results this is the gain plot the green trace is the one of the op-amp and the blue trace is of the linear difference equation and you can see that it is almost an exact match now what i have done on purpose i have reduced the sampling frequency of the digital one so that you can see a difference otherwise they are so perfect that the two would be completely superimposed on top of each other it's just to show you that it's an approximation and in order to design a good digital power supply you must make sure that the sampling frequency or switching frequency is going to be much higher than the crossover frequency okay now how do we create this controller in digital domain in analog we have something like this which is a type 3 compensator in our case it has got a transfer function like that in digital there's already a library function called 3pol30 which is the digital equivalent of the analog circuit okay and here is the equation for it all you have to do is pass in the coefficients and so on and the software will calculate all of these values for you and then it gives you the output okay now here the coefficient a a coefficients coefficients there there and there and then here are your outputs previous output previous previous output previous previous previous output and here are your inputs previous input and so on again please don't worry too much about this for this short webinar because the library function is written for you and here are the b coefficients you see that these are extremely cumbersome but there is nothing here that the software cannot calculate so they're big and cumbersome and that's why we get the software to calculate these first we paste this into our code the library function is written and your compensator digital compensator design is complete another thing that we have to consider is various scaling factors now if you imagine let us for simplicity say that you have got here a power supply with an output voltage of 3.3 volts okay for simplicity ignore these values let us let us assume that the potential divided that goes to the ADC is just a divide by two okay so one kilo ohm one kilo ohm right just a divide by two that means that everything that we calculated that is being sampled by the ADC is off by a factor of because you have added an extra divide by two here which you did not take into account in the linear difference equation in order to fix that you have got a scaling factor right on the output of your controller which takes into account all the various scaling factors you've got the scaling factor of the of the pot you've got the scaling factor of the ADC you've got the scaling factor of the PWM block again in the workshops we calculate our workshop we show how to work out the various gays that you may encounter in digital design but for the case of a voltage mode power supply this is the equation that you need but again the software will calculate all of this for you and gives you the k and that makes sure that your crossover frequency is where you expect it to be and you can again download it free from here okay so to give you a design example let's say we've got a 3.0 design example for our lab this is the one that we run in our workshop this are the the specifications and the coefficients that we get from WDS I will demo that very quickly very shortly and of course we will give you some real demos in a moment the coefficients will be these k has been calculated to be around 28 and the reference also has been calculated by the software there we go these are the results that I got I got 10 kilohertz again the green trace is what WDS calculated the black trace is what I measured with my Bode 100 and we can see that we have got 10 kilohertz of crossover frequency just like we designed we have got better than 10 dBs of gain margin just like we wanted and we have got around 46 degrees of of phase margin now if you design this in analog we would expect around 75 degrees now there is a certain amount of phase deterioration in digital which we're going to talk we also need to take into account the way we measured the frequency response bias while using a Bode 100 I get it we put an injection resistor there and what happens is that the Bode 100 will inject 10 hertz 20 hertz 30 hertz 40 hertz into our power supply and then you put two probes here and there and it will compare automatically the height i.e the gain of the sine wave that goes in compared to the to the height and and phase shift of the sine wave that comes out basically across this injection resistor and then it will plot the Bode plot for you which was the one that you saw earlier on and then you can compare the gain and the phase this is the setup in the lab again this is a type of setup we have in the workshop when in order to measure this is the board that we use in the workshop it's a bug converted that we design in the workshop and then this is your STM32 microprocessor card that plugs in and you make all of your measurements with with this instrument and of course with some oscilloscopes so you will find that compared to analog there is a phase erosion in digital world and that is because of two processes one of them is because of sampling and reconstruction and the other one is because of the time delay from the time you sample your voltage to the time that you update the PWM both of these introduce a pure time delay into the transfer function and a pure time delay translates into a phase loss and of course that means that we get more phase lag in a digital power supply compared to the analog power supply in the demos that we do we actually show that if you sample later in the cycle i.e this part of the phase lag time delay if you sample a little bit later then because you've got shorter time delay actually your phase margin improves we will show that a little bit later but the important thing to note is that there is this phase lag here and again you can calculate this by hand or you can use the software which will take it into account automatically without actually you knowing as long as you provide in the right information the software will calculate this and compensates for it so if you need if you want to have a 50 degree phase margin at the end it will already work out that oh i'm going to lose 20 degrees of phase margin because it's a digital power supply and designs it for 70 degrees in analog so by the time that you've lost 20 degrees you still get the correct phase margin that you expect so we've talked about this software quite a bit i'm going to demo it for you shortly so quick introduction to it it's we've designed this software over the last 10 years now it has become extremely sophisticated it is designed just to stabilize analog and digital power supplies the free version that you have for sd is only for digital power supplies automatically calculates the poles and zeros as well as the controller coefficients it stabilizes the loop it calculates all the gain and the phase lags that i talk about it even works out the component distresses from many of the components and you can download an unlimited version for sd microprocessors from this link link over here so these are the specification of the power supply that i'm about to design i'm going to design it using wds and then we're going to show you the real measurements and the real demonstration okay so here i am running wds this is the software that we talked about you can actually download it from our website if you go to the bridge.com folder slash sd and then or st-wds you can download it for free first thing that you have to do is is obviously provide the software with some data with regard to the specifications of your power supply here you've got the maximum nominal and minimum input voltages you can type in maximum nominal and let's say minimum and at that point wds not only calculates everything based on these worst case scenarios it actually draws lines on the on the body plot there there and there in order to show you what is the worst case scenarios with regard to your stability crossover frequency and so on i'm going to return these back to 12 volts because this is just a demo and now i know that the three point the output voltage is 3.3 volts and the output current is two amps this is the one of the many power supplies that we design in the workshop that actually we tested and my colleague dr michael hallworth is actually going to show you the real experimental results of this very very shortly as soon as this presentation is finished the ripple and overshoot requirement actually determines the size of the capacitor and let us leave this as they are but if you change them wds will calculate everything then you have got your switching frequency and sampling frequency now for the majority of the cases the switching frequency and the sampling frequency is the same but if for example you run out of bandwidth and you decide to sample every other uh switching cycle so you're sampling at 100 kilohertz if you remember i said this will introduce a big time delay which will manifest itself as phase loss you can immediately see that i lose my phase and wds gives you a warning saying that you have got a problem with your phase let's return that back to 200 kilohertz and if you remember i also said there was a second mechanism that caused phase lag and that was the time delay from the time you sampled to the time that you updated the pwm now here we are assuming that we are sampling the output voltage in the middle of the cycle now if i change that to the beginning of the cycle so if i were to sample right at the beginning then i'd expect to have more phase loss and you can see that the software again shows that you have got a problem because you've got too much phase loss but that's okay we're going to leave it at that because that is where we are going to sample with this particular power supply and actually michael will demo for you live uh on the oscilloscope and with the body measurement how by changing the sampling point of the of the adc you lose or gain phase we're going to do a real demo of this a little bit later on so i'm going to leave it at one this i will fix this warning a little bit later crossover frequency 10 kilohertz and 55 no let's say 50 degrees of phase margin then the transformer tab is for all the transformer isolated topologies of the wds and of course buck the buck converter is not um uh transformer isolated so this is all grayed out then we go to the semiconductor now we use a very nice uh set of semiconductor switches pair of semiconductor switches from st and here are the parameters from this device that is soldered on the workshop board uh let's see it was 240 picofarads and only a 0.1 volt drop okay then we go to output filter the output filter of the buck converter i.e here now the inductor is determined the size of inductor is determined by the amount of ripple current so we're allowing 25 percent of ripple current and that means that wds has calculated the size of this inductor as 24 microhenrys but i know that i soldered at 22 microhenry 22 microhenry inductor you can see on the body plot that this is still not good i'm still having a warning but i also know that my inductor has got 90 milliohms of um dc resistance now when i type that wds recalculates everything the controller parameters and now does manage to get it to stable you can see that i have now got a stable power supply but we can do much better again based on the ripple voltage ripple requirements or the overshoot or undershoot requirements wds has calculated this output capacitor to be 230 microfarads but i know that we have soldered 440 microfarads with 55 milliohms of esr so again you can see that it's it's calculated the gain has actually gone up a little bit uh and you have to take into consideration that just as soon as i change these wds recalculates the controller parameters so it's constantly adjusting in order to give you the best performance based on your specification then we go to the control design controller design here wds has opted for a type 3 compensator and it has placed the poles and zeros taking into account all the time delays you can place the poles manually but we don't recommend you do so unless you are very good at control theory and you know how to place these in order to get the requirements but if you put automatic it will give you these now these will then get transformed using bilinear z transform into the digital coefficients at the moment this is the digital coefficients that i have but these are not correct i've got a pwm clock master frequency which in my case is 4096 and that gives me a total pwm count of 2480 that is a specification from the st part that we are using i have got a 12 volt sorry 12 bit 3.3 volt adc and the potential divider that is dividing down these 3.3 volts in order to get the right voltage to adc the resistor values gives you a a division factor or multiplication factor of 0.785 now that is now this scaling factor again if you remember i said that wds will calculate all the scaling factors and gives you just the right value of k right here for the for the compensator to to to actually make sure that your scaling is not off depending on whatever the scaling factors you have got so then finally i have got the coefficients here these are the coefficients that we have calculated all i have to do is say copy to clipboard and then you go to your code and then you paste them in the appropriate place uh within the code and the design is actually complete if i look at the frequency response you will see here that at the moment this is this is absolutely ideal i've got 10 kHz crossover frequency 50 degrees of phase margin nine dbs of gain margin and 21 a slow path crossover frequency of minus 21 and uh if you remember from the stability criteria this is actually a very nice and stable power supply but this is all simulations so what i'm going to do now is go i'm going to pass you to my colleague and friend dr michael hallworth who was going to demonstrate for you a real power supply and we're going to show you some real measurements and we're going to import the real measurement into this and superimpose the two on top of each other to show that it's actually working very well based on this stm32 device this is my part of the presentation thank you for much for thank you very much for listening and i'll pass you over to michael okay thank you ali so during this half of the webinar we're going to look at how we set up the device using stm32 cuber max how we program run and debug using your ide and then we're going to do some measurements on our closed loop digital power supply so we're using stm32 cuber max to set up our device which is the stm32g 474 cuber max is very good because it allows us to configure the peripherals on board the device using a GUI rather than having to look at the hsheet and finding out which bitfield does what to set up the required functionality so for our digital power supply we need several peripherals we need the high-res timer to generate our PWM output and we need the ADC to sample our output voltage so that can be used by our controller so let's set up some peripherals you can see on our device that we've already configured the high-res timer outputs here PA8 and PA9 by clicking on the pin and then selecting the high-res timer output again click on the pin high-res timer output there are two outputs because we're using a synchronous buck converter today so we need a high side and a low side PWM we then configure the high-res timer itself by clicking on the timers tab high-res timer one you can see we have TA1 TA2 outputs active for timer A these are TA1 and TA2 we then click on the timer A tab here and there are several things to configure we've set the clock to be the fastest possible clock speed so 5.44 GHz for our high-res clock this means to achieve our 200 kHz switching frequency we need a period value of 27200 we then configure various things in our timing unit we're not going to go through them all now there isn't time but we will look at the dead time so here you can see we've added dead time between output 1 and output 2 this ensures that output 1 and output 2 are never on at the same time which is obviously you don't want them to be on at the same time for synchronous buck or any half bridge type topology so dead time is inserted we then configure various compare units so we have compare unit 1 here enabled with a compare value of 5000 this is just an initial value it will be updated by our controller every switching cycle so this is what is going to be used to determine our effective duty cycle we have another compare unit enabled with an initial value of 500 ticks and this will be used to trigger our ADC we'll see the setup of that shortly you can then configure external events if you wish and these are often used for things like overcurrent events so you could use the onboard comparator to trip the high res timer module and effectively shut down the outputs in the case of an overcurrent via the external event configuration here we then have the dead time module so the dead time has been configured for 136 rising ticks and 136 falling ticks we will see what that is in terms of nanoseconds on the scope shortly and then finally we configure the outputs so ta1 is configured that's our high side switch the output is active high we have one set source selection so this is what the event that sets our output high in this case our timer period event forces the output to its active state so if you imagine our time is counting up from zero to the period value when it reaches the period value it will then set the output high so that's effectively the beginning of our next switching period then we have one reset source selected and the reset source is set to the timer compare one event so that's the compare unit we just configured so when the counter hits our compare unit value initially 5000 it will set the output low so that gives us our PWM we then can configure what happens to the output in the event of a fault or burst mode and then there's the output to configuration so this will be our low side switch again that's active high there's nothing else to configure here because this is handled by our dead time module the dead time module will ensure the output two is always the complementary of output one with dead time inserted between the switching so then we can look at our ADC triggers tab we're going to use our hybrids timer to trigger the ADC conversion so enable ADC trigger one trigger source is time at a and the trigger source has been selected as timer a compare three so that's not compare unit three configuration that we just saw on the timer a tab that will start ADC conversion so every switching cycle every 200 kilohertz ADC will be triggered by compare unit three so let's take a look at the ADC the ADC input pin is configured over here you can see ADC one in one PA0 so we just click on that pin and we clicked ADC one in one then ADC itself if we collapse this expand analog ADC one here you can see in one is set to single ended conversion and under the parameter settings we've got a 12 ADC we are doing regular conversions and we have one conversion enabled so rank one so the first conversion and the only conversion is channel one so ADC one in one is channel one we sample it for 2.5 cycles and then we do the conversion at the end of conversion we have enabled interrupts so there will be an interrupt triggered when the conversion is complete and that is where we will run our 3.0 controller the last thing to look at here is the GPIO which is general purpose input output so under system core here we have GPIO and we've configured a GPIO for a timing measurement so PC2 here we click on this we click GPIO underscore output so it's an output pin we've given it a user label by right clicking enter user label so GP01 and this is an output that we will use to measure the duration of our interrupt service routine so then you would configure the project under project manager tab in our case we're using embedded workbench from IAR as our IDE then all we need to do is click generate code and that will generate the project files and the source code and then copy everything and open the IDE so let's do that now click generate code and then there we go successfully generated just click open project it will open the IDE so this is the IDE embedded workbench from IAR there is also an IDE available from ST called stm32 cube IDE which is free of charge this IDE is what we use in our workshops at the moment this project is in fact an example from one of our workshops example 3b so if you came to the the workshop then we would run through this in great detail so we've opened the main.c file and the first function we see in the main.c file is this main function this is where the microcontroller jumps to when it starts and when it boots up effectively so this is where our execution will begin you can see there are some green lines here these are comments so we have user code begin one user code end one you'll see this repeated throughout our code for example here user code begin user code end and here any code that we write needs to be within these tags within these comments the reason being is that we're using stm32 cuba max to generate our code and our project files so if we go back and change something for example set up a new GPIO or sample a new channel then we press generate code if any of our code is outside of these then it will be deleted by cuba max so we need to make sure that all our user code is in between these tags so it persists when we when we regenerate the project so here we can see some functions that have been inserted by cuba max so howl in it sets up our hardware abstraction layer we have our system clock config configuring our GPIO configuring our ADC and configuring our high-res timer so that's our chip set up by the stm32 cuba max and the howl libraries as well so now we have some user code so here you see user code begin two and this function here is our three-pole three zero initialization function so we're using a three-pole three zero controller for our closed loop voltage mode synchronous buck converter so we have this function which is part of our digital power library functions we pass it a structure of type three-pole three zero data float this is a structure that holds all the parameters required by our controller so our controller coefficients our previous outputs our previous inputs in max duty and we initialize that structure with those controller coefficients reference k scaling factor min max duty using this one line of code then we configure our soft start so we've got a soft start on this converter so using control ramp float config we pass that another structure which is a structure for our holding all the the information about our soft start so that will be our final soft start value the duration and the update rate of our soft start then we perform an ADC self calibration and then we start our ADC we start our high-res timer outputs and our high-res timer counter and then all we do is sit inside our while loop so while one here means we just go continue around this while loop and inside the while loop we have some code we're delaying for one millisecond using the how delay function and then we're updating our soft start duration uh direction sorry so we could do a soft start or a soft stop using this variable b power up then we update the value of our soft start so that will be the reference value and then we store the reference value into our controller structure this code doesn't have to be here it could be inside some slow low priority timer function it's not time critical we just put it here for ease of teaching so there's no controller uh there's no three ball three zero controller in here because that is within our ADC interrupt service routine remember we configured the ADC interrupts to occur when the ADC conversion is complete so let's find our ADC interrupt service routine here it is ADC one IOQ handler so this is the function that our micro controller jumps to when an ADC conversion is complete the first thing we do when we get into the ISR is set a pin high so that we can measure the duration of ISR on the scope then we clear our ADC interrupt flag and then we read the conversion value from our ADC and store it into our controller structure so the m feedback element of our controller structure then using this one line of code we execute our three ball three zero controller so this three ball three zero controller is implements the equation that Ali just showed so the seven multiplies now adds effectively using the AMD coefficients and our previous outputs previous inputs and our current input subtracted from our reference current error value then we update our duty cycle so set compare so the compare unit time at a compare unit one with the output of our controller and then finally we set the pin low so that allows us to measure the duration of this bit of code here okay so the last thing to look at is our controller coefficients Ali showed you how to generate those using stws so effectively you would paste them in the code here so i have the project open here that Ali configured press copy to clipboard and then just paste your controller coefficients here like so i've already got k ref in max duty to find down here so i've written that and these are our controller coefficients from stws okay so now we need to build our project program the flash run and run our code to do that we just press this button here download and debug if there are any changes then it will rebuild the project and you can see it's doing now and then once it's rebuilt the project it will program the flash like so and then get ready for debug so now i'm ready for debug the program is halted at the beginning of the main function and when we press go here it will begin execution so before i do that i'm going to bring the scope on the screen so we can watch the soft start so i'm going to press go bring back this you can see that the soft start ramps up to 3.3 volts nice slow ramp up there and then we can see on our scope various things we have channel one is the high side pwm high side switch pwm channel two is the low side switch pwm channel three is the isr duration so that output pin that we set high when we enter the isr and low when we leave and then channel four is our output voltage so that is set to that we can measure that at about 3.3 volts which is what we want let's take a look at our dead time so you can see we have a dead time of about 100 nanoseconds which is good and the duration of our isr is approximately it should be about 650 700 nanoseconds so that blue trace there is the duration of our isr okay so that's pretty quick for a 3.3 or 3.0 controller now let's take a look at what happens when we change the load so let's check if we have good load regulation so channel four there is our output voltage and you can see the load switch is here if i change the load the output voltage should remain constant uh yes it does the duty changes a little bit but not too much we have synchronous converter here so we don't go into dcm always in dcm uh yeah so the closed loop appears to be working we have a regulated output voltage that's good let's look in a bit more detail now let's try and see our transient response so to do that i need to just turn off some channels and let's change this channel to or output voltage to ac coupling on that one sorry ac coupling uh let's change our trigger to the output voltage let's try and catch the undershoot this is all good so if i look at say it's 50 millivolts per division and we look at the time base as 50 microseconds per division let's say so we're on full load at the moment um let's look change this to normal and try and catch a there we go undershoot so going from 50 to full load you can see we have the undershoot there of the output voltage so how long our output voltage takes to recover the recovery time is we can see roughly about 50 microseconds one division there and the undershoot again is roughly about 50 millivolts so fast recovery small undershoot but importantly there's no ringing in the output voltage we don't see any oscillations so that is indicative of a good phase margin there is sufficient phase in the system so that's our undershoot looks pretty good now if we change this back to auto we can measure the loop and see what the loop looks like so if i bring up bode analyzer suite here so this is bode analyzer suites which we're going to use to inject sinusoid into our feedback path and measure the result as it passes through our system and see what happens on the output voltage measure the gain phase of this so i've already connected the bode 100 to our buck converter so i just need to press single here to do a single measurement you can see on the scope the signal that's being injected and this looks like a voltage mode buck converter that's good the crossover is 9.5 kilohertz with 44 45 degrees of phase margin not too bad now what we can do is save this to memory so save this to memory like so and import this into stws and see how well it compares to our theoretical result so there's the green trace is the simulated loop and the black trace is the measured loop that we just measured now you can see we designed for 10 kilohertz 50 degrees and we're measuring 9.2 kilohertz 46 degrees so we're pretty close change the discrepancies are probably due to discrepancies in the plant using ideal values for our plant as in reality things are a little bit different the good news is with digital it's very easy to retune your loop just change a few parameters here get your new controller coefficients copy and paste into your code so we noted that the phase margin is a little bit low we designed for 50 we've got 46 now what can we do to improve this well as Ali mentioned that one of the main sources of the phase erosion in our digital system is is due to the time delays now when we set up our ADC we configured it such that the ADC conversion starts when our compare three value is net by our high-res timer compare unit so what we can do is change that so we're we're running now our program is running we can go view live watch and enter high res timer what capitals higher as timer one so this is a high res timer structure we are using timer a so here is timer a and bring this across you can see compare three here remember compare three was set to 500 in stm cube mx and that gave us the sampling point for ADC so i turned the other channels back on on our scope bring this in change our trigger back to channel one let's bring this back to DC so on our scope here we're triggering that towards the beginning of our cycle 500 high res timer ticks in what we can do is delay that trigger we don't need to trigger here because we're we're triggering our ADC we're jumping into our interrupt we're reading our ADC value we're executing our controller we're updating our duty cycle but because we have effectively shadow registers enabled the the shadow registers are copied to the active registers at the beginning of the next cycle so our new duty cycle does not take effect until the following cycle so we've introduced a whole switching period or sampling periods worth of delay into our system and therefore introduce some phase erosion we don't need to take our measurement here we could take it later we have all this spare time in our period so let's try doing that by shifting the point at which we take our cycle sample so instead of sampling at 500 let's try sampling at say 15 000 ticks our period is 27 200 so this is roughly halfway through our period so you can see now that the blue trace here the isr has been shifted towards the end of our cycle or later in our cycle so we're no longer taking our sample towards the beginning or taking it towards the middle let's see what effect that has on our bode plot so we go back to bode analyzer suite i've saved this existing trace to memory and you'll see that as a dashed trace when i take a new measurement so let's take a new measurement now so the solid traces are new measurement the dash traces are old measurement and you can see the difference in phase now the phase does not roll off as as quickly because we've reduced the delay in our digital system and what's happened to our phase margin well now we have nine kilohertz not changed too much in terms of crossover but we have 54 degrees of phase rather than 44 so we gained an extra 10 degrees of phase margin just by changing our sampling point so when you're designing a digital power supply it's very important to consider all of the additional delays in the digital system and set your sampling points such that you minimize any delays and therefore minimize the phase erosion with an stws that feature is implemented here so where we say pure time delay what we mean here is the point at which you take your sample if this is one that means we take our sample at the beginning of our period if this is 0.5 it means we take our sample halfway through our period and there we go that's how we configure our digital power supply using stm32 cuba max using stws to get our controller coefficients and we measure the loop using our v100 vector network analyzer and we've seen using our signal oscilloscope here the transient response a nice stable transient response with no ringing and good load regulation and that is a very nice digital power supply that's all from us thank you very much for watching we have we hope you join us on our future st webinars and we hope to see you at one of our workshops very soon thank you very much from me and Ali goodbye