-
Notifications
You must be signed in to change notification settings - Fork 1
/
GAratio2.m
52 lines (34 loc) · 2.42 KB
/
GAratio2.m
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
43
44
45
46
47
48
49
50
51
52
% GAtemp1 stands for 3stage single-ended CMOS Ring Oscillator for Rise/Fall Time Ratio in each inverter, 'b2.sp' , with
% GA
function ObjVal = GAratio2(BestPosition)
%% BestPositionrite into input .sp file
fidIn=fopen('D:\Users\Farshid\Documents\Matlab\b2.sp','r+');
ach=fread(fidIn);
pchar=char(ach');
pos=strfind(pchar,'+ps'); % Neveshte ke yaft mishavad ra avale khar biavaram
fseek(fidIn,pos(1)+22,'bof'); % Bedune shomaresh "=" or ghabl az "=" 23 ta shod +ps=65u nrd=.4 nrs=.4 w=0.972991
fprintf(fidIn,'%5f',BestPosition(1));
pos=strfind(pchar,'+ps');
fseek(fidIn,pos(2)+24,'bof'); % Ta ghabl az "=" 25 ta shod +ps=80u nrd=.85 nrs=.85 w= 17
fprintf(fidIn,'%5f',BestPosition(2));
fclose('all');
%% run hspice
!C:\synopsys\Hspice_A-2007.09\BIN\hspice.exe -i D:\Users\Farshid\Documents\Matlab\b2.sp -o D:\Users\Farshid\Documents\Matlab\b2
%% read data from .lis file
fidout=fopen('D:\Users\Farshid\Documents\Matlab\b2.lis','r+');
B=fread(fidout);
so = char(B');
pos=strfind(so,'risetime');
fseek(fidout,pos(2)+9,'bof'); % 1. Shoru az khode kalameye risetime. 2. Az shoru ta 2ta ghabl az shorue addad shomaresh anjam mishavad : risetime= 3.1008E-09 targ= 2.6804E-08 trig= 2.3703E-08
ObjVal1=fscanf(fidout,'%f')
fclose('all');
fidout=fopen('D:\Users\Farshid\Documents\Matlab\b2.lis','r+');
B=fread(fidout);
so = char(B');
pos=strfind(so,'falltime');
fseek(fidout,pos(2)+9,'bof'); % 1. Shoru az khode kalameye risetime. 2. Az shoru ta 2ta ghabl az shorue addad shomaresh anjam mishavad : falltime= 2.7514E-09 targ= 1.3548E-08 trig= 1.0796E-08
ObjVal2=fscanf(fidout,'%f')
fclose('all');
ObjVal = abs(1 - (ObjVal1/ObjVal2))
end
% End of function