%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Half Bridge Controller Design Project %
% By Sonny Lloyd %
% Copyright 2007 %
% %
% Method derived from text: "Fundamentals of Power Electronics 2nd ed" %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
Vi=425; % VARIABLE: 200 <= Vi <= 650
Vo=28; % GIVEN: output voltage
fc=5e3; % GIVEN: cut-off frequency of controller
Po=300; % GIVEN: output power
phi=52; % target phase margin, 52 degrees
fsw=100e3; % switching frequency (Hz) set to 20 * fc
% From DC analysis of circuit
R=Vo^2/Po; % for 300W at 28V, R = 2.61
Ns=1; % step down transformer
Np=3; % step down transformer
D=0.1976 % for Vo = 28V at quiescent conditions
% and for informational purposes..
D_tf=Vo/Vi*Np/Ns; % Duty cycle value to maintain 28V output
Vo_tf=D_tf*Vi*(Ns/Np); % value should always work out to 28V
% From large ripple analysis
Lo=100e-6; % set greater than Lo_min to maintain CCM
Co=220e-6; % set greater than Co_min for Vo ripple voltage < 100mV
% From small signal analysis
Gi0=D*(Ns/Np); % Line-to-Output gain at DC
Gd0=Vo/D; % Control-to-Output gain at DC
wo=1/sqrt(Lo*Co);
fo=wo/(2*pi);
Q=R*sqrt(Co/Lo);
% s = TF('s') specifies the transfer function H(s) = s (Laplace variable)
s = tf('s'); % a useful function
% Begin constructing feedback controller system
Vref=5; % reference voltage
H=Vref/Vo; % sensor gain function
Vm=4; % modulation factor
Vc=D*Vm*(2); % quiescent value of the control voltage Vc
figure
Gvi=tf([Gi0],[1/(wo^2) 1/(Q*wo) 1]); % Line-to-Output transfer function
% computesthe gain margin Gm, the phase margin Pm, and the associated
% frequencies Wcg and Wcp, for the SISO open-loop model SYS
% (continuous or discrete)
[Gm,Pm,Wcg,Wcp]=margin(Gvi);
margin(Gvi) % Bode plot of function with phase & gain margins identified
title('Gvi(s)')
grid;
figure
Gvd=tf([Gd0],[1/(wo^2) 1/(Q*wo) 1]); % Control-to-Output transfer function
% computesthe gain margin Gm, the phase margin Pm, and the associated
% frequencies Wcg and Wcp, for the SISO open-loop model SYS
% (continuous or discrete)
[Gm,Pm,Wcg,Wcp]=margin(Gvd);
margin(Gvd) % Bode plot of function with phase & gain margins identified
title('Gvd(s)')
grid;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now we are ready to take a look at the transfer function of our system
% to see how it would respond if we "did nothing". To do this we
% plot the "uncompensated" transfer function Tu(s).
%
% set compensator gain to unity, i.e. Gc(s) = 1
Tu0=(1)*(1/Vm)*Gd0*H
figure
% Control-to-Output transfer function
Tu=tf([Tu0],[1/(wo^2) 1/(Q*wo) 1]);
%
% computes the gain margin Gm, the phase margin Pm, and the associated
% frequencies Wcg and Wcp, for the SISO open-loop model SYS (continuous or
% discrete)
[Gm,Pm,Wcg,Wcp]=margin(Tu);
margin(Tu); %Bode plot of function with phase & gain margins identified
title('Tu(s)')
grid;
% at fc = 5kHz, the uncompensated loop gain is:
Tu=Tu0*(fo/fc)^2; % this is the value that we are trying to compensate for
% Now look at the transfer function and deside which compensation type
% controller is best suited to achieve goal of crossover at fc,
% with 52deg phase margine, and Tu0 = 0db. What type of compensator would
% do this?
% PD? PI? PID? Also must look at the phase margine to check for
% stability at this location. Each compensator method has its own
% characteristics that will define HOW it operates on the feedback signal.
%
% To enable a certain type of compensator, simply remove the "%" character
% from the line with the equations. Three controller choices given below.
%%%%%%%%%%%%% PD (lead compensator) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% find the compensator pole/zero frequencies %
% convert degrees to radian: phi * pi / 180 %
% The zero at frequency fz adds phase lead in the vicinity of the crossover
% frequency.
%fz=fc*(sqrt((1-sin(phi*(pi/180))/(1+sin(phi*(pi/180)))))); %
%wz = 2*pi*fz; %
%fp=fc*(sqrt((1+sin(phi*(pi/180))/(1-sin(phi*(pi/180)))))); %
%wp = 2*pi*fp; %
% %
% to obatin a compensator gain such that Tu0 = 0dB at fc, the low %
% frequency compensator gain Gc0(s) must be: %
%Gc0=sqrt(fz/fp); % low frequency compensator gain %
%Gc=Gc0*(1+s/wz)/(1+s/wp) % Compensator transfer function for PD %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% PI (lag compensator) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This type of compensator is used to increase the %
% low-frequency loop gain, such that the output is better regulated at %
% DC and at frequencies well below the loop crossover frequency. %
% %
% An inverted ZERO is added to the loop gain, at requency fL. If fL is %
% sufficiently lower than the lopp crossover frequency fc, %
% then the phase margin is unchanged. %
%fL=0.1*fc; %
%wL=2*pi*fL; %
%Gc0=fc/(Tu0*fo) % low frequency compensator gain %
%Gc=Gc0*(1+wL/s) % Compensator transfer function for PD %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% PID (lead-lag compensator)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% A combination of the PI and PD methods given above. %
% An inverted ZERO is added to the loop gain, at requency fL. If fL is %
% sufficiently lower than the lopp crossover frequency fc, %
% then the phase margin is unchanged. %
fL=0.1*fc; %
wL=2*pi*fL; %
%Gc0=fc/(Tu0*fo) % low frequency compensator gain %
% %
% find the compensator pole/zero frequencies %
% convert degrees to radian: phi * pi / 180 %
fz=fc*(sqrt((1-sin(phi*(pi/180))/(1+sin(phi*(pi/180)))))); %
wz = 2*pi*fz; %
fp=fc*(sqrt((1+sin(phi*(pi/180))/(1-sin(phi*(pi/180)))))); %
wp = 2*pi*fp; %
Gc0=sqrt(fz/fp); % low frequency compensator gain
% %
% to obatin a compensator gain such that Tu0 = 0dB at fc, the low %
% frequency compensator gain Gc0(s) must be: %
Gcm=Gc0*(fc/fo)^2*1/Tu0 % midband gain %
Gc=Gcm*(1+s/wz)*(1+wL/s)/(1+s/wp) %PID Compensator
figure
[Gm,Pm,Wcg,Wcp]=margin(Gc); % computes the gain margin Gm, the phase margin Pm,
% and the associated frequencies Wcg and Wcp,
% for the SISO open-loop model SYS
% (continuous or discrete)
margin(Gc) % Bode plot of function with phase & gain margins identified
title('Gc(s)')
grid;
% The compensated close loop transfer function (eq. 9.53 from text)
T=Gc*(1/Vm)*Gvd*H;
figure
[Gm,Pm,Wcg,Wcp]=margin(T); % computes the gain margin Gm, the phase margin Pm,
% and the associated frequencies Wcg and Wcp,
% for the SISO open-loop model SYS
% (continuous or discrete)
margin(T) % Bode plot of function with phase & gain margins identified
title('T(s)')
grid;
%%%%%%%%%%%%%%%%%%%%%%
figure
[Gm,Pm,Wcg,Wcp]=margin(T/(1+T)); % computes the gain margin Gm, the phase margin Pm,
% and the associated frequencies Wcg and Wcp,
% for the SISO open-loop model SYS
% (continuous or discrete)
margin(T/(1+T)) % Bode plot of function with phase & gain margins identified
title('Ts/(1+Ts)')
grid;
figure
[Gm,Pm,Wcg,Wcp]=margin(1/(1+T)); % computes the gain margin Gm, the phase margin Pm,
% and the associated frequencies Wcg and Wcp,
% for the SISO open-loop model SYS
% (continuous or discrete)
margin(1/(1+T)) % Bode plot of function with phase & gain margins identified
title('1/(1+T(s))');
grid;
%close all;