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

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 7 Aug. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Solar Power finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by