Clear Filters
Clear Filters

use of timer for simulating voltage regulator

1 view (last 30 days)
Umberto
Umberto on 27 Mar 2013
Answered: Sabin on 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"?

Answers (1)

Sabin
Sabin on 22 Jan 2024

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!