% v_r_d.m                                                   2-11-15

% Calculate the v-i pairs, for the voltage at which a diode
% in parallel with a resistor have a total current = i.

% Specify Conds:
r = 0.35;                                           	% fet Ron
temp = 75;                                            	% selected temp C

vc = zeros(2,630);                                      % combined voltage 
a = 1:630;                                           	% for i = 0.1 ... 
i = a/10;                                               %   63 amps
vc(1,:) = i;                                         	% current
% Assume diode characteristics are same as for STGWA19N60:
v125 = 0.87*log(1.13*i + 1) + 0.028*i;               	% at 125 C
v25 = 1.06*log(2.5*i + 1) + 0.015*i;                    % at 25 C
% v125 = 0.105*log(2e3*i + 1) + 0.0062*i;               	% at 125 C
% v25 = 0.118*log(4e3*i + 1) + 0.0062*i;                    % at 25 C
v = v125 + (v25 - v125)*(125 - temp)/100;              	% interpolate
figure(1)
plot (i, v25, '-k', i, v125, '-r', i, v, '--k');
title('Diode V/I for 25C, 125C and selected temperature')
xlabel('Forward Current');
ylabel('Forward Voltage');

for a = 1:630                                           % each current
    vi = v(630);  vpp = 0;  ipp = 0;      % default voltage; prev v,i
    for b = 1:630                                       % each voltage
        ip = v(b)/r + i(b);                             % total i @ point
        if ip > i(630) && b == 1
            vi = r*i(a);                                % diode current = 0
            break;
        else
            if ip > i(a)
                vi = vpp + (v(b) - vpp)*(i(a) - ipp)/(ip - ipp);
                break;
            end
        end
        vpp = v(b); ipp = ip;                       % update prev values
    end
    vc(2,a) = vi;                                 	% write interp value
end
coeff = polyfit(vc(1,:),vc(2,:),9);         	% 10 coefficients
f = polyval(coeff,vc(1,:));                     % voltage is fn of current
figure(2)                                       % combined chracteristic    
plot(vc(1,:),vc(2,:),'k',vc(1,:),f,'r');
xlabel('Forward Current');
ylabel('Forward Voltage');
title('Combined Diode/Resistor V/I');

vc(1,:) = [];                                   % leave v for 0.1 A steps

save('D:\Power_Elect\Matlab\Thermal\Volts_D_R.mat','vc');

% ------------------------------------------------------------------------












