Electronics > Microcontrollers

Microcontroller Controlled Switching Mode Power Supply

(1/2) > >>

gcp6ca:
A few months ago built a buck synchronous converter to learn about them using a PIC18F14K50 (USB controlled) - schematic attached. This was when I first started working with MOSFETs and was learning about switching mode power supplies so the parts I selected were based on what I had and experiments (no oscilloscope - multimeter only). After some experience I know that my high side MOSFET configuration is wrong and I was able to drive the MOSFETs by combining a charge pump and a MOSFET driver that accepts higher voltage. I have tried bootstrapping half-bridge drivers but I blew up a few with out much success (expensive). However it would work well with light loads - less than 1A - (as far as the multimeter let me know) since it stayed within a 10mV of my setpoint.

My logic was simply to increment the PWM duty by 0.1% if the output was less than the setpoint (with some tolerance) and vice-versa. Then a month ago I briefly learned about PID controllers in university and I found some code online that can be implemented in a microcontroller. I also got an oscilloscope and saw that my buck converter responds slowly (dependant on setpoint).

My question is how can I model the buck converter in Simulink so that I can try to tune a PID controller in a simulation? I also learned about Nyquist sampling theorem (atleast 2x of actual frequency) so if the PWM is at 100kHz, does the sampling have to be at least 200kHz? If you have any other suggestions on improving the project, then please let me know. I want to make it work at 1A then try it at 5A so one of my objectives was to use the smallest value inductor so it can pass higher currents and I have lots of those that I pulled from old power supplies and motherboards.

I may not some of the basic that you might assume since I am a mechanical engineering student (that loves electronics).

Edit:
I completed the power supply and posted the project here:
http://www.libstock.com/projects/view/247/dc-dc-pid-controlled-step-down-power-supply-with-usb-hid-interface-mikrobasic-mikroc-mplab-c18

IanB:
The 100 kHz frequency of the PWM is going to represent noise in the system relative to the output voltage you are trying to regulate. When you put a feedback controller in the loop like a PID controller you definitely don't want to sample the noise, you want to sample or measure the value you are trying to control. So sampling at 200 kHz would be a bad mistake. You will want to sample much more slowly than 100 kHz and also make sure there is some noise filtering on the measurement. Your objective is to get a good signal to noise ratio on the measured value you feed to the PID controller.

As to modelling, the pragmatic engineer might derive a simplified linear model of the system and use that to tune the control loop. One way to get a linear model is to place the converter in open loop mode and record the response to step changes on the input (for example by using a digital oscilloscope, or by using the circuit simulator equivalent). Once you know how the output responds to step changes on the input you can use mathematical techniques to fit a model to the system (for example second order plus dead time). With such a model you can now tune your PID controller and you will likely find that tuning works well on the real system.

Maybe this sounds a bit advanced for now, but if it doesn't immediately make sense keep it in mind because it will come together eventually.

The reason I am not addressing your Simulink question directly is that I am not familiar with that software. There is nothing wrong with tuning a PID controller interactively with a software model of the system you are controlling, as long as you understand any limitations of the model compared to real life.

gcp6ca:
Thanks for your explanation and I think I mostly understand what you said. Since the output should ideally be DC signal it would be 0Hz and anything above would be noise (theoretically). This means I need a low pass filter to the input to keep the signal as close to 0Hz as possible. I am measuring the output from the inductor so the large electrolytic capacitor (ripple control) also acts as a low-pass filter but would adding ceramic capacitor in parallel help the measured signal to noise ratio even further (there must be a reason why linear regulators use small ceramic capacitors in parallel)? If my output signal is very noisy but the MCU is getting a cleaner signal through a low-pass filter, does that mean the solutions lies hardware (increase capacitor, inductor or frequency) and not in software?

Would my sampling rate/PID cycle depend on my desired performance of the system? If want my converter to respond (like settling time) within 1ms (1kHz) then should my sampling frequency be between 2-10kHz?

For the model when I said Simulink, I was thinking about a block diagram. At university I learned to create a block diagram for a motor then add a PD and PI controller for position and velocity control. I thought that method may help but your suggestion is to treat the relation controller input/output as a black box and try to get a mathematical relationship between them and I like it. I am bit confused to what I would input and what I would measure. You said step inputs (that's all I need it to do), but did you mean to set a PWM duty and treat it as a step input? To actually measure the output, do you mean to make a model by using natural frequency and damping ratio that I would calculate from settling time and maximum overshoot? After I select the final frequency, inductor and capacitor would I be measuring the response to different amplitude steps or different loads? It would be great if you can provide some examples.

Can you provide some examples of limitations of the simulation? All I can think of are that there is a minimum and maximum voltage possible, PWM duty can can only be set up 0.1%, the model is not perfect but it would still be close which is good enough for me. Is their anything else major that I have not considered?

alm:
Limiting the bandwidth of the control loop will also make the transient response worse, so you probably need to find a good balance. Damping the hell out of it will reduce your response to input and load transients, eg. a 1kHz 10% to 100% load square wave. Designing a filter that specifically rejects the PWM frequency and its harmonics sounds like the best solution to me.

IanB:

--- Quote from: gcp6ca on November 27, 2011, 02:01:09 am ---Thanks for your explanation and I think I mostly understand what you said. Since the output should ideally be DC signal it would be 0Hz and anything above would be noise (theoretically). This means I need a low pass filter to the input to keep the signal as close to 0Hz as possible. I am measuring the output from the inductor so the large electrolytic capacitor (ripple control) also acts as a low-pass filter but would adding ceramic capacitor in parallel help the measured signal to noise ratio even further (there must be a reason why linear regulators use small ceramic capacitors in parallel)? If my output signal is very noisy but the MCU is getting a cleaner signal through a low-pass filter, does that mean the solutions lies hardware (increase capacitor, inductor or frequency) and not in software?
--- End quote ---

It's actually possible to use a software filter on the measured value of a PID controller. In fact many industrial controllers do this as a matter of course. (This simplest software filter is a first order lag, and this is what you will typically find. The nice thing about a first order lag is it only has one tuning parameter, the time constant. If you make a more complex filter it will have more parameters to tune and the average user will quickly give up on it.)

The reason for ceramic capacitors is different. They are used because large electrolytic capacitors don't work well at high frequencies. (I think the reason is the big roll of coiled up metal foil inside them. At higher frequencies the inductance of this coil starts to cancel out the capacitance.) Many practical circuits automatically parallel up a large electrolytic for low frequencies and a small ceramic for high frequencies.


--- Quote ---Would my sampling rate/PID cycle depend on my desired performance of the system? If want my converter to respond (like settling time) within 1ms (1kHz) then should my sampling frequency be between 2-10kHz?
--- End quote ---

Yes, absolutely. Here I have no idea what kind of response a typical power supply is expected to have. I don't know whether the response to load changes (or supply voltage changes) is supposed to settle out in 1 ms, 10 ms or 100 ms in typical bench supplies. Maybe someone could educate me (please)?


--- Quote ---For the model when I said Simulink, I was thinking about a block diagram. At university I learned to create a block diagram for a motor then add a PD and PI controller for position and velocity control. I thought that method may help but your suggestion is to treat the relation controller input/output as a black box and try to get a mathematical relationship between them and I like it. I am bit confused to what I would input and what I would measure. You said step inputs (that's all I need it to do), but did you mean to set a PWM duty and treat it as a step input? To actually measure the output, do you mean to make a model by using natural frequency and damping ratio that I would calculate from settling time and maximum overshoot? After I select the final frequency, inductor and capacitor would I be measuring the response to different amplitude steps or different loads? It would be great if you can provide some examples.
--- End quote ---

Your control system needs to respond to changes in load and also to changes in supply voltage. So one step change you could make is a step change in the supply voltage. You could for example apply a low frequency square wave to the input and record the output voltage in response. You would do this with no feedback control at a fixed PWM frequency, so the output voltage would go up and down in response to the input voltage. Another test would be to make step changes in load current while keeping the supply voltage fixed. Once again the output voltage will go up and down in response and you can record this waveform.

In every case where you do such a test you will have a step change input (up or down) and a curvy response on the output. The most pleasing and simplest response will look like a first order lag, but complex systems might not behave that way. Once you have your step response you can for example load it into Excel and fit model parameters to best fit an idealized simple model. (In order of complexity, simple models are: 1. pure first order; 2. first order plus dead time; 3. second order plus dead time.) If you have model parameters for a simple open loop response you can often find PID tuning guidelines in books. It's much more fun, however, to adjust the parameters by hand and watch what happens using a simulation.


--- Quote ---Can you provide some examples of limitations of the simulation? All I can think of are that there is a minimum and maximum voltage possible, PWM duty can can only be set up 0.1%, the model is not perfect but it would still be close which is good enough for me. Is their anything else major that I have not considered?

--- End quote ---

Simulations always make assumptions, and always are only an approximation of real life. Old and wise electrical engineers know the only way to test whether a circuit is really going to work as expected is to build it and see. All sorts of things can get in the way, from components having non-ideal behaviours to parasitic inductances and capacitances to unplanned feedback loops and oscillation.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod