Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help in writing matlab function

Status
Not open for further replies.

tompham

Full Member level 2
Joined
May 29, 2010
Messages
133
Helped
29
Reputation
60
Reaction score
29
Trophy points
1,308
Location
usa
Activity points
2,066
Hi all
I am writing matlab code for PLL component. Below is my code:

function [C2,C1,R1] = PLLcom(ipump,vco_gain,fref,fout,bandwidth,phase_margin)

Kpd = ipump/2/pi; % phase detector gain
Kvco = vco_gain*2*pi; % vco gain
omega = 2*pi* bandwidth; % open loop bandwidth in radians/sec
N = fout/fref; % division ratio
pm = phase_margin*pi/180; %phase margin in radians/sec
%% Find T1 and T2
T1 = (sec(pm)-tan(pm))/omega;
T2 = 1/(omega*(sec(pm)-tan(pm)));
%% Solving for Loop Components
C2 = Kpd*Kvco/(N*omega^2)*T1/T2*sqrt((1+(omega*T2)^2)/(1+(omega*T1)^2));
C1 = C2*(T2/T1-1);
R1 = T2/C1;


The compile function shows no error. Why I can not get value of C1, R1?
I need someone to help me.
Thanks a lot
 

Hi all
I am writing matlab code for PLL component. Below is my code:

function [C2,C1,R1] = PLLcom(ipump,vco_gain,fref,fout,bandwidth,phase_margin)

Kpd = ipump/2/pi; % phase detector gain
Kvco = vco_gain*2*pi; % vco gain
omega = 2*pi* bandwidth; % open loop bandwidth in radians/sec
N = fout/fref; % division ratio
pm = phase_margin*pi/180; %phase margin in radians/sec
%% Find T1 and T2
T1 = (sec(pm)-tan(pm))/omega;
T2 = 1/(omega*(sec(pm)-tan(pm)));
%% Solving for Loop Components
C2 = Kpd*Kvco/(N*omega^2)*T1/T2*sqrt((1+(omega*T2)^2)/(1+(omega*T1)^2));
C1 = C2*(T2/T1-1);
R1 = T2/C1;


The compile function shows no error. Why I can not get value of C1, R1?
I need someone to help me.
Thanks a lot
Hii....

Can you able to get value C2 at least...... Can you please also tell us what are the input parameters that you are passing to the function.......

Some coments on your coding -

First of all use the backets in your code like based on the forumla that you use-

Kpd = ipump/2/pi; % phase detector gain -> Kpd = ipump/(2/pi); % phase detector gain
or

C1 = C2*(T2/T1-1); -> should be either C1 = C2*((T2/T1)-1); or C1 = C2*(T2/(T1-1)); based on your formula....


Good luck
 

Hi kulkarni

Thanks for reply me and adding some comments.
This is some my input parameter:

%%ipump = 80e-6;
%%vco_gain = 510e6;
%%fref = 50e6;
%%fout = 800e6;
%%bandwidth = 5e6;
%%phase_margin = 56;

Thanks
 

It's working for me, I get:
C2 = 7.899133602898353e-013
C1 = 7.660956439733713e-012
R1 = 1.359027078281924e+004

You have to call the function like this:
[C2,C1,R1] = PLLcom(ipump,vco_gain,fref,fout,bandwidth,phase_margin)
 

Yes I do agree with dave9000

[C2,C1,R1] = PLLcom(ipump,vco_gain,fref,fout,bandwidth,phase_margin);
>> C2

C2 =

7.8991e-013

>> C1

C1 =

7.6610e-012

>> R1

R1 =

1.3590e+004
I am also getting the same output....

Good Luck
 

Hi kulkarni

Thanks for reply me and adding some comments.
This is some my input parameter:

%%ipump = 80e-6;
%%vco_gain = 510e6;
%%fref = 50e6;
%%fout = 800e6;
%%bandwidth = 5e6;
%%phase_margin = 56;

Thanks

---------- Post added at 15:56 ---------- Previous post was at 15:56 ----------

Thanks both of you
 

Hi
I need help to design vco,if you have some information please help me,i want to write a matlab code and i dont khnow how it work.
best.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top