MATLAB Answers

0

Simulink: Matlab function block for Charge controller of a solar home system.

Asked by Pratyush Das on 7 Aug 2019
Latest activity Answered by Fangjun Jiang on 7 Aug 2019
I am modelling a solar home system, with a battery protection system or charge controller, which controls 2 switches depending on the voltage of the battery.
% This is the code for the functional block, kindly read the comments
function [Sw_A, Sw_B] = fcn(v1,v2,v3,v4,v_bat,i_bat)% sw A is PV sw and SW_B is load switch
while i_bat < 0 % battery is discharging hence curent is negative
if v_bat < v1 % 1. if battery voltage is too low, load is cut off
Sw_B = 0;
elseif v_bat < v3 % 4. Battery is discharged into load and voltage is safely low, reconnect pv
Sw_A = 1;
end
while i_bat > 0 % Battery is charging
if v_bat > v2 % 2. if voltage is raised high enough, the load is reconnected
Sw_B = 1;
elseif v_bat > v4 % 3. Battery is being overcherged, cut off PV switch
Sw_A = 0;
end
end
This function is showing multiple errors, I can only assume I have done some silly rookie mistakes. Any help will be greartly appreciated. if you require any more data please ask.
jh.JPG

  0 Comments

Sign in to comment.

1 Answer

Answer by Fangjun Jiang on 7 Aug 2019
 Accepted Answer

Keep in mind that the MATLAB Function block executes once at every simulation step. So I don't think you should use the while-loop. It will cause the block thus the whole Simulink model runs for ever. Use if-else statement instead. Also, make sure "end" statement is provided to match the "if" statement.

  0 Comments

Sign in to comment.