In the previous lecture, based on the geometry of the waveforms in the peak current mode controller, we have derived a relationship for the average inductor current as a function of the control current i sub c, the duty-cycle d and the slopes m1 and m2 of the inductor current during dTs interval and d prime Ts interval, respectively, and the slope ma or the artificial ramp added in the peak current mode controller. We will now construct a Spice sub-circuit that is based on this relationship. Based on that Spice sub-circuit, we will be able to construct Spice models for CPM controlled converters. Those are average circuit models that can be then used for design verification in DC, Transient and AC simulations. So, we will start from this expression right here and here is the derivation of the average CPM sub-circuit. The relationship shown first is the one we have derived earlier. We then solved that relationship partially for the duty-cycle d. That duty-cycle d is a ratio of the difference between the control current and the average current, notice that in the average circuit model, the average current is going to be equal to the current through the inductor, over a factor that depends on the slopes, those slopes being determined by the voltages applied to the inductor in the two sub-intervals, the duty-cycle and the slope of the artificial ramp ma. If we multiply the numerator and denominator by R sub f, Rf representing the equivalent current sensing resistance in the CPM controller. Then we see that for example the product of Rf and i sub c is equal to the controller voltage input v sub c. Similarly the product of Rf and i sub L is going to be equal to the average value of the sensed switch or inductor current. And similarly in the denominator, we have now an expression in terms of the voltages applied in the two sub-intervals for the inductor, the duty-cycle and the peak value of the artificial ramp in the controller. This expression right here can be implemented in the sub-circuit in exactly that manner. You can see this line right here that defines Eduty inside a sub-circuit that is called CPM-CCM is actually based directly on the expression that we have just derived. Notice that this is not directly a closed form expression for the duty-cycle. The duty-cycle is present on both the left hand side and the right hand side of the expression. That doesn't matter, we can let the simulator solve this implicit relationship here by itself, and it can do so in a large-signal manner which means that we can obtain correct steady state solution as well as large-signal transient, and finally the linearized model for AC simulations. The sub-ciruit has four inputs and one output. In the symbol, the inputs are shown as v sub c. That's the control voltage, v sub s is the sensed inductor current. vs is proportional to the inductor current with a factor of proportionality equal to R sub f, and the voltages vm1 and vm2 are the voltages across the inductor in the sub-intervals d prime Ts for vm2, and d Ts for vm1. The symbol of the subcircuit is shown right here. The only output of the subcircuit is the duty-cycle d. The subcircuit has four parameters. The equivalent current sense resistance Rf, the amplitude of the artificial ramp Va, the value of the inductance, and the value of the switching frequency. So let's see the application of this model in an example. Here is an example of a CPM controlled boost converter that we have seen earlier. That boost converter has, in a switching model, a CPM modulator, with vc and vs inputs, and a control signal c as the output, that through a gate driver, controls the main switch M1. To construct an average model, we'll replace the switching CPM modulator with the average CPM model. We define the parameters of that model to correspond to the parameters of the actual power stage. We also replace the two switches with the average switch model, in this case here we choose CCM-DCM1 model for the implementation. In the average circuit model, the input v sub c is the value that sets the control input for the modulator, Hsense, a current control voltage source is used to sense the average value of the inductor current. And the constant of proportionality is the parameter R sub f defined here as 0.1 ohms. Now let's take a look at how the two voltages are actually determined from the power stage. So remember, voltage vm1, or v1, is the voltage across the inductor during the DTs subinterval. Now this is an average circuit model. There is no switching here at all. There is no state of the switch when this point right here is close to zero. But we can imagine that if the switching actually occurred, which it does in the actual circuit model, the switching circuit model of the boost converter, the voltage applied across the inductor L1 during that dTs interval would be equal to the voltage Vg on the left-hand side minus the voltage across the switch and the series resistance R sub L on the right-hand side. Neglecting these voltage drops, neglecting small voltage drops across the resistance of the switch and the small voltage drop across RL, the voltage across L1 during dTs is approximately equal to Vg. And so our E1, a voltage control voltage source, is controlled by the voltage at the input node, in, right here. We do that simply by labeling the input node of the E1 source as in. We assigned a gain of 1 to that controlled voltage source and that becomes the vm1 input to the CPM modulator, the average model of the CPM controller. In the second sub-interval, in the d prime Ts sub interval, the voltage applied across the inductor is equal to output voltage minus the input voltage. Again, approximately neglecting small voltage drops across the inductor resistance and the diode voltage drop. And so E2, voltage controlled voltage source, is controlled by the difference between the output node and the input node with a gain of 1, and that becomes the second input as input vm2 to the CPM modulator. This model can then be simulated in transients or in AC simulations. Let's see a transient example. Here is the comparison of the boost switching model and the boost average model. What is shown is the output voltage ramping up from the input voltage in a startup transient to finally around 60 volts in the switching model. And you see very similar transient observed in the average model for the inductor current, we have that inductor current following the current command, and of course, with the ripple, that current goes around the current of about 8 amps. In the average model there is no ripple but dynamic behavior of the inductor current is reproducing the dynamic behavior of the average inductor current that we can visualize in the switching model as well. Now what is even more interesting of course is that we can perform AC simulations on this model. So in this case here, we request AC simulation with 300 points per decade between 10 hertz and 100 kilohertz. We assign AC1 input to the Vc source, which means we are interested in the control to whatever, let's say the output frequency response. So control to output frequency response is the one that we are going to plot in the simulation. The same model applies as in the case of performing transient simulation. We simply choose AC small signal simulation in this case. And the result is shown right here. So this is the CPM controlled boost control to output frequency response. The magnitude response is shown right here and the phase response is shown on the same plot. The scale for the magnitude response in on the left-hand side, the scale for the phase response in on the right-hand side. Notice that the magnitude response does, as you would expect from the simple model, exhibit a low frequency pole around here. And that corresponds to a phase lag associated with that pole which is rolling off right here and you see about minus 45 degrees of phase lag at the frequency of the first low-frequency pole. But there is further dynamics in the model. There is a zero right here that happens to be a right-half plane 0, and after that there is yet another pole apparently which brings up another phase lag to a total of -270 degrees in the CPM controlled boost converter. In a follow-up lecture we will derive an analytical model for the same example, and we will see exactly where these high frequency dynamics are actually coming from. To include a DCM operation, we can again rely on the geometry of the current waveforms shown right here. The left hand side is what we have already examined in continues conduction mode. Notice that in this case here the d2 interval, the second interval, is equal simply to 1-d, d being the duty-cycle of the switch. In the DCM, the inductor current wave form is different, because it falls down to zero before the end of the switching period. And so we have the d2 can now be determined from the value of the peak current, i sub p, and the slope of the inductor current during that second sub-interval. Taking this into account, it is possible to actually combine the relationships for the DCM or the CCM operation in one single sub-circuit that's called CPM, and it's also contained in the average.lib library. The decision between the CCM versus DCM operation is performed by this line right here, which evaluates the minimum of the two expressions, 1-d or ipk over m2 Ts. That makes an immediate and automatic decision on whether the converter is operating in continuous conduction mode or discontinuous conduction mode. The expression for the duty-cycle as a function of control input and the d2 and the slopes is shown right here and it follows a very similar pattern as what we have already derived earlier for CCM operation only. The symbol for the CPM sub-circuit is the same as what we had for the continuous conduction mode operation, same inputs and the same duty-cycle output with the same set of parameters. In conclusion, we have now derived Average Spice CPM Model, implemented as sub-circuit netlists in the library. There are actually two models, CPM-CCM can be used if we up front know that the converter operates in continuous conduction mode, or it is designed with specification, for example, to always operate in continuous conduction mode. There is also a CPM model, which applies to CCM or DCM operation, with automatically switching inside the model itself. That sub-circuit can be combined with averaged-switch sub-circuit models to construct complete average Spice circuit models of peak current mode controlled converters. And then those models can be used to perform DC, Transient or small-signal AC simulations. And we will see examples of that in the coming lectures.