Simulink: Matlab function block for Charge controller of a solar home system.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pratyush Das
le 7 Août 2019
Réponse apportée : Fangjun Jiang
le 7 Août 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.
0 commentaires
Réponse acceptée
Fangjun Jiang
le 7 Août 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solar Power dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!