Monday, December 30, 2013

Releasing version 0.2.2

Finally, releasing the next version 0.2.2. The example of the buck converter is there in testckt16.csv with the control code in And the description of the circuit parameters in testckt16_params.csv and the controls in control_desc.csv.

Well, well, well. It is the 31st of December 2013. I started this project a little more than a year ago and frankly I never thought I would get this far. So far everything has been coded to be automatic and without hardcoding any particular circuits which I feared I might have to. If all goes well, I will add other equipment like transformers, motors. But first I need to simulate power electronic converters of every type which just the library that I have. I suppose a lot of errors will creep up but I think the main concept is there and should work out.

And finally a big thank you to my blog readers. I see a lot of hits to the blog and also received some very nice comments. Thank you so much for reading my blog and I hope that soon I'll have a real simulator that every one of you can use on any OS. This has been a great year 2013 and I hope 2014 is just as good if not better.

Happy New Year to all of you and I wish you all the success for an awesome 2014!

I'll take a break for a few days and post again when I recover from my hangover :)

Diode freewheeling - nodal analysis

Where do I begin? Been coding continuously for the past three days and now have to find where I am.

As posted before, the only way to solve the problem of getting the diode to freewheel is by a nodal analysis. Essentially, the current through an inductor should not change instantaneously. If it does, it is bad design and I'll have to figure that out later. But in standard converter circuits, the inductor is expected to freewheel through a diode. As in the example of the buck converter.

So what I have coded is a function to perform nodal analysis take inductors as current sources. So I perform a dc analysis on a snapshot of the circuit at an instant and find out where the currents would flow if the inductor current were to remain constant.

Take the snapshot when the switch turns off with the inductor La having a non-zero current. So this current will flow through the switch and the diode almost equally since these are two high resistance paths.

With these currents calculated through nodal analysis, I try to figure out if any of the devices in the circuit has the capability to change its state. Since only nonlinear devices can do so, the remaining devices will have empty functions. The diode and switch will have the function called determine_state. Here is the code for the switch (click on "View Raw" at the bottom of the code box to see code in another window)

And here is the code for the nodal analysis (click on "View Raw" at the bottom of the code box to see code in another window)

Yes, it is a monster. Anyway, the basic concept is:

1. If a branch is not stiff and has an inductor, it becomes a current source.
2. If it has no impedance, the nodes on either end of the branch become super nodes.
3. If it only a resistance or is a stiff branch, it is expressed in KCL

4. Also if a branch has zero impedance, the current through it is treated as a current source.
5. Because of this, the only thing to be calculated are the resistive branches which is what needs to be done because that is where the non-linear devices will be.

6. The super node was a little tough to handle. When two nodes are connected by a branch with zero impedance, the current through that branch is tough to define. Therefore, the KCLs at the two nodes can be added up to form one KCL equation. And the second equation will be the voltage of the branch connecting these nodes.

7. In general, several nodes can be connected together to form a super node. Even worse, several groups of super nodes can exist.

8. Once the KCL equations are established, they need to reduced to upper triangular form and solved backwards. One node will become the reference node and will have zero voltage.

9. The branch currents will then be calculated from these node voltages. and there comes the next part of the story.

Because the nodal analysis could have changed the nature of the circuit by changing the state of nonlinear devices, it may so happen that the loop currents calculated before are not correct. So we need to recalculate the loop currents from the branch currents that the nodal analysis has given. The code for that is in compute_loop_currents (click on "View Raw" at the bottom of the code box to see code in another window)

This function looks to isolate branches to single loops and once that happens, the current of that branch becomes the loop current. If you are lucky, and in the case of the buck converter I was, the loops will be such that every non stiff loop will have a non stiff branch in that loop only and no other. Otherwise, a row operation is performed to isolate branches.

Anyway, long post but it is long overdue. The buck converter is now working. I am not sure if this will work in its present form for all power electronic converters. Need to test it thoroughly. But I'll release the next version soon.

Saturday, December 21, 2013

Getting the diode to freewheel - II

To begin with, today marks the completion of one year of blogging on this project. The project has come pretty far though not as far as I had hoped.

The problem with the approach that I have been using is that it is based exclusively on loop analysis. This breaks almost every time with every modification to the logic I try to make for every variation of the circuit. Nothing universal seems to be coming out. I have been spending the entire week drawing circuits, writing loops, scratching them out and repeating over and over again.

So need to change my approach. How about I mix in some nodal analysis as well? The loop analysis gives me all the loop currents for any one iteration. The control changes the circuit. Now, to determine how the currents will be rearranged, nodal analysis seems to be the only solution.

I am thinking about it this way:

1. At the end of an iteration, mark which loops were non-stiff and therefore may have had inductors carrying a non-negligible current.

2. When an event occurs, we need to rearrange the circuit, the loops, the loop currents and also decide any freewheeling effects.

3. At this point, the one circuit law that should be obeyed is - the current through an inductor cannot change instantaneously. Using this as a starting point, apply nodal analysis to calculate the current through all the branches.

4. Based on the preliminary calculations, check if the branch currents result in any changes in circuit topology - diodes freewheeling or IGBTs conducting. This seems a bit complicated - will need to expand on this.

5. Now that circuit topology is updated, another nodal analysis will update the branch currents. Using these updated branch currents, the loop currents will need to be calculated for the next round of loop analysis.

Only worry is that these tasks seem computationally heavy. Even if they are executed only when events occur, every effort will need to be made to make them simpler.

Monday, December 16, 2013

Getting the diode to freewheel

The diode must freewheel when:

1. An inductor (for now, but in general an energy storage element) contains non-negligible current because a negligible current could simply mean it is in a loop that is stiff but finds itself only in stiff loops.

2. For this current to break would be either bad design which means undue voltage stress on devices as stored energy has nowhere to go or the current freewheels through a diode (or any other device such as an IGBT with an anti-parallel diode).

And this is essentially how the algorithm develops:

1. After one iteration is over, suppose the ideal switch in the buck converter turns off.

2. The next iteration will throw up an event. So new loop manipulations will be done, an effort will be made to remove stiffness, and this effort will fail because there are two parallel stiff branches.

3. The check to be done - is there any inductor in all the loops which has a non-negligible current but now finds itself only in stiff loops? Right now I will restrict the search to inductors but I will expand the criteria later if needed.

4. If so, check if it can freewheel through a device capable of freewheeling. Now this is the tough part.

5. Start with the loop that contains the inductor but has a non-negligible current. This is because the inductor could have been in multiple loops to begin with and some of them may have been stiff in the first place.

6. Check if any of the devices in the loop are capable of freewheeling. This will be done by running a function within all devices but will be empty for all devices that can't freewheel and will contain code for those than can freewheel. The function will check if the loop current and direction are such that the device will start conducting if the current were to flow through it. If so, the device state changes.

7. Now check again if loop containing the inductor is stiff. Why? Because there may be two diodes connected in series. So repeat the above procedure.

8. There could be another possibility. Suppose there are two diodes connected in series in the buck converter and they have high resistance snubbers connected in parallel with them. So now we won't know how the loops are formed. It could be that the inductor appears in a loop with the snubbers and not the diodes. The diodes appear in a loop with the snubbers. So the above algorithm will give up because the inductor loop never encounters a diode.

9. So if upon encountering a stiff branch, it so turns out that the stiff branch does not contain an element that can freewheel, check if that branch exists in other loops. If so, perform a loop manipulation and bring those other loops into the inductor loop. Now repeat the above process.

10. When will the algorithm give up? Not sure how this will work. I will have to run different cases and check. There may be times when it goes into an infinite loop.

Now I will code this. Not sure if I can finish it tonight. Probably will post again tomorrow.

Ideal switch

It is winter again and I am buried in snow in Toronto. I am not much into winter activities and this means only coding can stop me for going crazy. So I am back again to this project. After weeks of dithering, pretending to review code and thinking of future strategies, I finally gotten around to taking this project further.

Like I said before, the diode model is not complete because the diode doesn't know when and where to freewheel. To highlight this, I made the ideal switch model and tried to simulate a buck converter. Here's the code for the ideal switch (click on view raw below the code box to see the code in another window):

This is the circuit for the buck converter.

And this is the control code - actually just an open loop with a constant 50% duty ratio  (click on view raw below the code box to see the code in another window):

And on execution, the current (measured by Ammeter_La) through the inductor La is:

And as can be seen, the diode does not free wheel at all. The current rises when the switch turns on and drops to zero when it is turned off.

The strategy to overcome this will be my next blog entry as it is a fairly detailed algorithm.