OK, I have gotten the thing to compile, and seemed to have taken care of questions 2-4:
2) This is taken care of using the 'let, in' block
3) I used a workaround and just made a new variable 'Runit' with a unit magnitude and proper dimension.
4) See 2.
Unfortunately, the component is not behaving as desired. I set up a simple test circuit comprised of a 1 Ohm resistor in parallel to verify and I'm getting 0 V out. I think that it may have something to do with initial conditions. I am very new to Simulink/Simscape and still trying to get over this learning curve so any input helps. My updated code is attached.
Thanks,
Adam
component solar_panel
nodes
p = foundation.electrical.electrical; % +:right
n = foundation.electrical.electrical; % -:right
end
inputs
T = { 25.1, 'K' }; % T:left
G = { 1000, 'W/m^2' }; %G:left
end
variables
i = { 0, 'A' };
v = { 0, 'V' };
end
parameters
Ns = { 36, '1' }; % Number of cells
T_stc = { 298, 'K' }; % STC temperature, T
Voc_stc = { 21.2, 'V' }; % STC open circuit voltage, Voc
Isc_stc = { 1.93, 'A' }; % STC short circuit current, Isc
a = { 6.0e-4, 'K^-1' }; % Current temperature coefficient
b = { -3.97e-3, 'K^-1' } ; % Voltage temperature coefficient
N = { 1.7, '1' }; % Quality factor
G_stc = { 1000, 'W/m^2' }; % STC Irradiance, G
% Constants
k = { 1.38e-23, 'J/K' }; % Boltzman's constant, k
q = { 1.6e-19, 'c' }; % Charge of an electron, q
Eg = { 1.12, 'J' }; % Bandgap Voltage of Si, Eg
Runit = { 1, 'Ohm' };
end
function setup
across( v, p.v, n.v );
through( i, p.i, n.i );
% **** This is where error checking/messages go *****
% if R <= 0
% error( 'Resistance value must be greater than zero' );
% end
end
equations
let % *** Precursor calculations ***
Vt_stc = N*k*T_stc/q; % Thermal voltage
Io_stc = Isc_stc/(exp(Voc_stc/(Vt_stc))-1);% Saturation current
dVdI_Voc = -1/Ns;
Xv = Io_stc/(Vt_stc)*exp(Voc_stc/(Vt_stc));
Rs = -dVdI_Voc*Runit - 1/Xv; % Series resistance per cell
Iph = G/G_stc*Isc_stc*(1+a*(T-T_stc))
Vt = N*k*T/q;
Io = Io_stc*(T/T_stc)^(3/N)*exp(-q*Eg/(N*k)*(1/T+-1/(T_stc)));
in % Output
i == v/Vt_stc*Isc_stc;
end
end
end