-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode
More file actions
43 lines (37 loc) · 681 Bytes
/
code
File metadata and controls
43 lines (37 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function Vref = RefGen(V,I)
Vrefmax=363;
Vrefmin = 0;
Vrefinit=300;
deltaVref =1;
persistent Vold Pold Vrefold;
dataType ='double';
if isempty(Vold)
Vold=0;
Pold=0;
Vrefold= Vrefinit;
end
P =V*I;
dV = V-Vold;
dP = P-Pold;
if dP ~= 0
if dP<0
if dV<0
Vref = Vrefold + deltaVref;
else
Vref = Vrefold - deltavref;
end
else
if dV<0
Vref = Vrefold - deltaVref;
else
Vref = Vrefold + deltaVref;
end
end
else Vref=Vrefold;
end
if Vref >=Vrefmax | Vref<=Vrefmin
Vref = Vrefold;
end
vrefold =Vref;
Vold = V;
Pold = P;