use of timer for simulating voltage regulator

1 Ansicht (letzte 30 Tage)
Umberto
Umberto am 27 Mär. 2013
Beantwortet: Sabin am 22 Jan. 2024
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"?

Antworten (1)

Sabin
Sabin am 22 Jan. 2024

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by