use of timer for simulating voltage regulator

1 次查看(过去 30 天)
Hello everybody! I need to simulate a voltage regulator: in this system voltage has to be regulated if it's out of tolerance for more than 30 seconds. If voltage returns to the correct range the timer has to be stopped. I wrote this code
function simulation
% parameters
Vnom = 3850;
s = 0.01;
delay = 30;
g = 50;
n = 1000;
Vmin = Vnom*(1-s);
Vmax = Vnom*(1+s);
V = xlsread('data.xls', 1, 'C2:C1002'); %import data from Excel
t = timer('Period', delay, 'TimerFcn', calculate(V, g, n, Vmin, Vmax));
function calculate
for i=1:n
if V(i) < Vmin
start(t);
if "30 seconds are passed"
V(i) = V(i)+ g;
end
elseif V(i) > Vmax
start(t);
if "30 seconds are passed"
V(i) = V(i)- g;
end
elseif (V(i) >= Vmin && V(i) <= Vmax)
stop(t);
end
end
xlswrite('data.xls', V, 1, 'E2:E1002');
Problems:
1)Error message ("Too many input arguments") in this line t = timer('Period', delay, 'TimerFcn', calculate(V, g, n, Vmin, Vmax))
2)How can I express in matlab code the fact that "30 seconds are passed"?

回答(1 个)

Sabin
Sabin 2024-1-22

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by