//SOLOOPFILTER_f Scicos Second order Loop Filter for PLL type 2 block //Classical interface function ver1.0 - scilab-2.7 //5 février 2004 Author : - IRCOM GROUP - A.Layec function [x,y,typ]=SOLOOPFILTER_f(job,arg1,arg2) x=[];y=[];typ=[] select job case 'plot' then standard_draw(arg1) case 'getinputs' then [x,y,typ]=standard_inputs(arg1) case 'getoutputs' then [x,y,typ]=standard_outputs(arg1) case 'getorigin' then [x,y]=standard_origin(arg1) case 'set' then x=arg1; graphics=arg1.graphics;exprs=graphics.exprs model=arg1.model; x0=model.state rpar=model.rpar ns=prod(size(x0));nin=1;nout=1 s=poly(0,'s');z=poly(0,'s') while %t do [ok,fn,phi,kv,Icp,N,plot_open,plot_close,plot_fm,exprs]=getvalue('Set Linear Third Order Loop parameters',.. ['Natural loop frequency (Hz)';'Phase Margin (rad)';... 'Linear VCO gain (Hz/V)';'Charge pump current (A)';... 'Nominal divider value (integer)';'Plot open loop transfert function (0=No) ?';... 'Plot closed loop transfert function (0=No) ?';... 'Plot fm response transfert function (0=No) ?'],.. list('vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1),exprs); if ~ok then break,end kv=kv*2*%pi [tau1,tau,tau2]=calcul_3eme_ordre(fn,phi,kv,Icp,N); num=1+tau1*s; den=tau*s*(1+tau2*s); if degree(num)>degree(den) then message('Transfer must be proper or strictly proper') ok=%f end if ok then tau1=tau1/(2*%pi);tau=tau/(2*%pi);tau2=tau2/(2*%pi); if plot_open<>0 then win=xget("window") xset("window",int(plot_open)) xset("wdim",300,200) xbasc() affiche_bode(int(plot_open),10e3,100e6,kv*Icp/(2*%pi)*num,N*s*den); xset("window",win); end if plot_close<>0 then win=xget("window") xset("window",int(plot_close)) xset("wdim",300,200) xbasc() G=kv*Icp/(2*%pi)*num/(s*den); GH=kv*Icp/(2*%pi)*num/(N*s*den) affiche_bode(int(plot_close),10e3,100e6,G,1+GH); xset("window",win); end if plot_fm<>0 then win=xget("window") xset("window",int(plot_fm)) xset("wdim",300,200) xbasc() GH=kv*Icp/(2*%pi)*num/(N*s*den) affiche_bode(int(plot_fm),10e3,100e6,1,1+GH); xset("window",win); end H=cont_frm(num,den) [A,B,C,D]=H(2:5); graphics.exprs=exprs; [ns1,ns1]=size(A) rpar=[matrix(A,ns1*ns1,1); matrix(B,ns1,1); matrix(C,ns1,1); D] if norm(D,1)<>0 then mmm=[%t %t]; else mmm=[%f %t]; end if or(model.dep_ut<>mmm) then model.dep_ut=mmm,end if ns1<=ns then x0=x0(1:ns1) else x0(ns1,1)=0 end model.state=x0 model.rpar=rpar x.graphics=graphics;x.model=model break end end case 'define' then fn=180e3; phi=%pi/4; Icp = 5e-3; kv = 87.25e6; N=50 plot_open=0 plot_close=0 plot_fm=0 kv=kv*2*%pi [tau1,tau,tau2]=calcul_3eme_ordre(fn,phi,kv,Icp,N); s=poly(0,'s'); num=1+tau1*s; den=tau*s*(1+tau2*s); H=cont_frm(num,den) [A,B,C,D]=H(2:5); [ns1,ns1]=size(A) rpar=[matrix(A,ns1*ns1,1); matrix(B,ns1,1); matrix(C,ns1,1); D] x0(ns1,1)=0 model=scicos_model() model.sim=list('csslti',1) model.in=1 model.out=1 model.state=x0 model.rpar=rpar model.blocktype='c' model.dep_ut=[%f %t] exprs=['180e3';'%pi/4';'87.25e6';'5e3';string(N);.. string(plot_open);string(plot_close);string(plot_fm)] gr_i=['xstringb(orig(1),orig(2),[''Sec Order'';'' Loop'';'' Filter''],sz(1),sz(2),''fill'')'] x=standard_define([2.5 2.5],model,exprs,gr_i) end endfunction