Post Reply 
Smith Chart program
06-09-2017, 04:52 PM
Post: #1
Smith Chart program
I still have not really figured out how to create a source file, and I currently do not have a computer with the simulator running on it, so I typed this into Word. There may be typos and some odd characters.

Anyway, this program displays a Smith chart and if you tap a point will display many of the relevant data about that point, I.e., Z, X, Gamma, Return Loss, VSWR and Q.

Code:

DISPSMITH(F);

EXPORT SMITH()
BEGIN

LOCAL pp,r,p2,cw,cb,x1,y1,m1;
LOCAL ff,cc,vv,ll,x2,y2;
LOCAL cr,lc,qq,zz,xx;

STARTAPP("Function");

x2:=1.2;
y2:=0,0;
cw:=RGB(255,255,255);
cb:=RGB(0,0,0);
cr:=RGB(255,0,0);
Xmin:=-1.4521;
Xmax:= 1.4521;
Ymin:=-1.0;
Ymax:=1.0;
ff = 1.0; // GHz

DISPSMITH(ff);

WHILE 1 DO // forever

L1:= WAIT(-1);
m1:= B→R(L1(1)); //Note: May need editing!

IF m1=3 THEN

x1:= B→R(L1(2)); //Note: May need editing!
y1:= B→R(L1(3)); //Note: May need editing!

L2 := PX→C(x1,y1); //Note: May need editing!

IF L2(1) > -1.4 AND L2(1) < -0.4 THEN
IF L2(2) < 1 AND L2(2) > 0.6 THEN
BREAK;  // Tapped "QUIT"
END;
END;

IF L2(1) > 0.7 AND L2(1) < 1.4 THEN
IF L2(2) < 1 AND L2(2) > 0.6 THEN
INPUT(ff, "ENTER FREQUENCY", "FREQUENCY", "IN GHZ");
DISPSMITH(ff);
END;
END;

Z1:= L2(1)+i*L2(2); // Reflection Coef.
Z2:= 50*((1+Z1)/(1-Z1)); // Impedance

IF ABS(Z1) ≥ 1 THEN // May need Editing
CONTINUE; // Make sure we are inside the positive Z Chart
END;

// Undraw, then draw the cursor
LINE(x2+0.05,y2,x2-.05,y2,cw);
LINE(x2,y2+.05,x2,y2-.05,cw);
x2:=L2(1);
y2:=L2(2);
LINE(x2+0.05,y2,x2-.05,y2,cr);
LINE(x2,y2+.05,x2,y2-.05,cr);

vv:= (1+ABS(Z1))/(1-ABS(Z1)); //VSWR
qq:= ABS(IM(Z2)/RE(Z2)); // Q

zz:= ABS(RE(Z2));

// Autoscale May need editing
CASE
IF zz≥1000 THEN L2(3):=STRING(zz,2,0); END;
IF zz≥100 THEN L2(3):=STRING(zz,2,1); END;
IF zz≥10 THEN L2(3):=STRING(zz,2,1); END;
IF zz≥1 THEN L2(3):=STRING(zz,2,2); END;
DEFAULT L2(3):=STRING(zz,2,2); 
END;

RECT(-1.4,-0.55,-0.75,-0.67);
TEXTOUT("R="+L2(3)+" Ω ", -1.4,-0.55,0,cb,100,cw); // 'Ω' is unicode 2126

IF ABS(Z1) ≠ 0.0 THEN // needs editing for not equal
ll:= 10*LOG(ABS(Z1)^2); // return loss
ELSE
ll:= -99;
END;

L2(3):= STRING(ll,2,2);
RECT(-1.4,-0.85,-0.60, -0.97);
TEXTOUT("RL="+L2(3)+ " dB",-1.4,-0.85,0,cb,100,cw);

xx:= ABS(IM(Z2));

// Autoscale May need editing
CASE
IF xx≥1000 THEN L2(3):=STRING(xx,2,0); END;
IF xx≥100 THEN L2(3):=STRING(xx,2,1); END;
IF xx≥10 THEN L2(3):=STRING(xx,2,1); END;
IF xx≥1 THEN L2(3):=STRING(xx,2,2); END;
DEFAULT L2(3):=STRING(xx,2,2); 
END;

RECT(-1.4,-0.70,-0.70,-0.82);
IF(IM(Z2) ≥ 0) THEN // Needs to be edited to greater than or equal
L2(4):= " j";
ELSE
L2(4):= "-j";
END

TEXTOUT("X="+L2(4)+L2(3)+" Ω", -1.4,-0.70,0,cb,100,cw); // 'Ω' is unicode 2126

RECT(-1.4,-1.0,-0.63,-1.12);
IF y2 ≥ 0.0 THEN
lc:=y2/(2*π*ff);
L2(3) :=STRING(lc,2,3);
TEXTOUT(“L=”+L2(3)+”nH”,-1.4,-1.0,0,cb,100,cw);
ELSE
Lc:=ABS(y2)*2* π*ff;
L2(3) :=STRING(lc,2,3);
TEXTOUT(“C=”+L2(3)+”pF”,-1.4,-1.0,0,cb,100,cw);
END;

RECT(0.8, -0.70,1.4,-0,82);
L2(3):=STRING(qq,2,2);
TEXTOUT(“Q=”+L2(3),0.8,-0.7,0,cb,100,cw);

RECT(0.8,-0.85,1.4,-0.97);
L2(3):=STRING(ABS(Z1),2,2);
TEXTOUT(“Γ=”+L2(3), 0.8,-0.85,0,cb,100,cw); // may need editing “Γ” is Unicode 0393

RECT(0.6,-1.0,1.4,-1.12);
L2(3):=STRING(vv,2,2);
TEXTOUT(“VSWR=”+L2(3)+”:1”,0.6,-1.0,0,cb,100,cw);
END;
END; // IF m1
END; // WHILE 1
END; // SMITH

DISPSMITH(f)
BEGIN
LOCAL pp, r, cl;
RECT();
L9:=C→PX(0,0);
pp:=320/(Xmax-Xmin);

LINE_P(L9(1)-pp,L9(2),L9(1)+pp,L9(2));
ARC_P(L9(1),L9(2),pp);
r:=pp/(1+50/50);
ARC_P(L9(1)+pp-r,L9(2),r);

r:=pp/(1+100/50);
ARC_P(L9(1)+pp-r,L9(2),r);

r:=pp/(1+25/50);
ARC_P(L9(1)+pp-r,L9(2),r);

r:=pp/(1+12.5/50);
ARC_P(L9(1)+pp-r,L9(2),r);

r:=pp/(50/50);
ARC_P(L9(1)+pp,L9(2)-r,r,π,3*π/2);
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π);

r:=pp/(25/50);
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-0.95,3*π/2);
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+.95);

r:=pp/(75/50);
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-2,3*π/2);
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+2);

r:=pp/(12.5/50);
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-0.5,3*π/2);
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+.5);

Cl:=RGB(0,0,255);
TEXTOUT(“50”,0,0,1,cl);
TEXTOUT(“25”,-0.33333,0,1,cl);
TEXTOUT(“12.5”,-0.80,0,1,cl);
TEXTOUT(“100”,0.33333,0,1,cl);

TEXTOUT(“50”,-0.9,1,1,cl);
TEXTOUT(“25”,-0.55,-0.75,1,cl);
TEXTOUT(“12.5”,-0.90,-0.30,1,cl);
TEXTOUT(“75”,0.4,-0.85,1,cl);

TEXTOUT(“QUIT”,-1.4,0.9);
L2(3) = STRING(f,2,3);
TEXTOUT(L2(3)+” GHz”,0.8,0.9);

END; // DISPSMITH
Find all posts by this user
Quote this message in a reply
06-09-2017, 05:10 PM (This post was last modified: 06-09-2017 05:20 PM by Freire.)
Post: #2
RE: Smith Chart program
A source file is just a plain text(.txt) file with your code inside.
The reason for that is HP programs or apps(.hpprgm or .hpappdir) they cannot be edited outside of HP connectivity Kit.
The way you posted inside a code tag is just as effective as a source file.
Find all posts by this user
Quote this message in a reply
06-10-2017, 11:21 AM
Post: #3
RE: Smith Chart program
HP Prime code files can be edited with any text editor. It's simply a case of copy/pasting them into/out from the code editor of the CK.
Find all posts by this user
Quote this message in a reply
06-12-2017, 06:57 PM
Post: #4
RE: Smith Chart program
(06-10-2017 11:21 AM)grsbanks Wrote:  HP Prime code files can be edited with any text editor. It's simply a case of copy/pasting them into/out from the code editor of the CK.

And figuring out the Unicode numbers for all the darn special keys. In this case, I currently don't have a CK available.
Find all posts by this user
Quote this message in a reply
06-15-2017, 02:51 PM
Post: #5
RE: Smith Chart program
Now that we have that out of the way, any comments on the program? Other than it is badly written?

Any questions about Smith Charts?
Find all posts by this user
Quote this message in a reply
06-18-2017, 12:13 PM
Post: #6
RE: Smith Chart program
Tabulating the code with the PrimePAD you can see that there is an end of more,

PHP Code:
DISPSMITH(F);

EXPORT SMITH()
BEGIN
    
    LOCAL pp
,r,p2,cw,cb,x1,y1,m1;
    
LOCAL ff,cc,vv,ll,x2,y2;
    
LOCAL cr,lc,qq,zz,xx;
    
    
STARTAPP("Function");
    
    
x2:=1.2;
    
y2:=0.0;
    
cw:=RGB(255,255,255);
    
cb:=RGB(0,0,0);
    
cr:=RGB(255,0,0);
    
Xmin:=-1.4521;
    
Xmax:= 1.4521;
    
Ymin:=-1.0;
    
Ymax:=1.0;
    
ff 1.0// GHz
    
    
DISPSMITH(ff);
    
    WHILE 
DO // forever
        
        
L1:= WAIT(-1);
        
m1:= B→R(L1(1)); //Note: May need editing!
        
        
IF m1=3 THEN
            
            x1
:= B→R(L1(2)); //Note: May need editing!
            
y1:= B→R(L1(3)); //Note: May need editing!
            
            
L2 := PX→C(x1,y1); //Note: May need editing!
            
            
IF L2(1) > -1.4 AND L2(1) < -0.4 THEN
                
IF L2(2) < AND L2(2) > 0.6 THEN
                    
BREAK;  // Tapped "QUIT"
                
END;
            
END;
            
            IF 
L2(1) > 0.7 AND L2(1) < 1.4 THEN
                
IF L2(2) < AND L2(2) > 0.6 THEN
                    INPUT
(ff"ENTER FREQUENCY""FREQUENCY""IN GHZ");
                    
DISPSMITH(ff);
                
END;
            
END;
            
            
Z1:= L2(1)+i*L2(2); // Reflection Coef.
            
Z2:= 50*((1+Z1)/(1-Z1)); // Impedance
            
            
IF ABS(Z1≥ 1 THEN // May need Editing
                
CONTINUE; // Make sure we are inside the positive Z Chart
            
END;
            
            
// Undraw, then draw the cursor
            
LINE(x2+0.05,y2,x2-.05,y2,cw);
            
LINE(x2,y2+.05,x2,y2-.05,cw);
            
x2:=L2(1);
            
y2:=L2(2);
            
LINE(x2+0.05,y2,x2-.05,y2,cr);
            
LINE(x2,y2+.05,x2,y2-.05,cr);
            
            
vv:= (1+ABS(Z1))/(1-ABS(Z1)); //VSWR
            
qq:= ABS(IM(Z2)/RE(Z2)); // Q
            
            
zz:= ABS(RE(Z2));
            
            
// Autoscale May need editing
            
CASE
                IF 
zz≥1000 THEN L2(3):=STRING(zz,2,0); END;
                IF 
zz≥100 THEN L2(3):=STRING(zz,2,1); END;
                IF 
zz≥10 THEN L2(3):=STRING(zz,2,1); END;
                IF 
zz≥1 THEN L2(3):=STRING(zz,2,2); END;
                DEFAULT 
L2(3):=STRING(zz,2,2);
            
END;
            
            
RECT(-1.4,-0.55,-0.75,-0.67);
            
TEXTOUT("R="+L2(3)+" Ω ", -1.4,-0.55,0,cb,100,cw); // 'Ω' is unicode 2126
            
            
IF ABS(Z1≠ 0.0 THEN // needs editing for not equal
                
ll:= 10*LOG(ABS(Z1)^2); // return loss
            
ELSE
                
ll:= -99;
            
END;
            
            
L2(3):= STRING(ll,2,2);
            
RECT(-1.4,-0.85,-0.60, -0.97);
            
TEXTOUT("RL="+L2(3)+ " dB",-1.4,-0.85,0,cb,100,cw);
            
            
xx:= ABS(IM(Z2));
            
            
// Autoscale May need editing
            
CASE
                IF 
xx≥1000 THEN L2(3):=STRING(xx,2,0); END;
                IF 
xx≥100 THEN L2(3):=STRING(xx,2,1); END;
                IF 
xx≥10 THEN L2(3):=STRING(xx,2,1); END;
                IF 
xx≥1 THEN L2(3):=STRING(xx,2,2); END;
                DEFAULT 
L2(3):=STRING(xx,2,2);
            
END;
            
            
RECT(-1.4,-0.70,-0.70,-0.82);
            IF(
IM(Z2≥ 0THEN // Needs to be edited to greater than or equal
                
L2(4):= " j";
            ELSE
                
L2(4):= "-j";
            
END
            
            TEXTOUT
("X="+L2(4)+L2(3)+" Ω", -1.4,-0.70,0,cb,100,cw); // 'Ω' is unicode 2126
            
            
RECT(-1.4,-1.0,-0.63,-1.12);
            IF 
y2 ≥ 0.0 THEN
                lc
:=y2/(2*π*ff);
                
L2(3) :=STRING(lc,2,3);
                
TEXTOUT(“L=+L2(3)+”nH”,-1.4,-1.0,0,cb,100,cw);
            ELSE
                
Lc:=ABS(y2)*2π*ff;
                
L2(3) :=STRING(lc,2,3);
                
TEXTOUT(“C=+L2(3)+”pF”,-1.4,-1.0,0,cb,100,cw);
            
END;
            
            
RECT(0.8, -0.70,1.4,-0,82);
            
L2(3):=STRING(qq,2,2);
            
TEXTOUT(“Q=+L2(3),0.8,-0.7,0,cb,100,cw);
            
            
RECT(0.8,-0.85,1.4,-0.97);
            
L2(3):=STRING(ABS(Z1),2,2);
            
TEXTOUT(“Γ=+L2(3), 0.8,-0.85,0,cb,100,cw); // may need editing “Γ” is Unicode 0393
            
            
RECT(0.6,-1.0,1.4,-1.12);
            
L2(3):=STRING(vv,2,2);
            
TEXTOUT(“VSWR=+L2(3)+:1”,0.6,-1.0,0,cb,100,cw);
        
END;
    
END// IF m1
    
END// WHILE 1
END// SMITH

DISPSMITH(f)
BEGIN
    LOCAL pp
rcl;
    
RECT();
    
L9:=C→PX(0,0);
    
pp:=320/(Xmax-Xmin);
    
    
LINE_P(L9(1)-pp,L9(2),L9(1)+pp,L9(2));
    
ARC_P(L9(1),L9(2),pp);
    
r:=pp/(1+50/50);
    
ARC_P(L9(1)+pp-r,L9(2),r);
    
    
r:=pp/(1+100/50);
    
ARC_P(L9(1)+pp-r,L9(2),r);
    
    
r:=pp/(1+25/50);
    
ARC_P(L9(1)+pp-r,L9(2),r);
    
    
r:=pp/(1+12.5/50);
    
ARC_P(L9(1)+pp-r,L9(2),r);
    
    
r:=pp/(50/50);
    
ARC_P(L9(1)+pp,L9(2)-r,r,π,3*π/2);
    
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π);
    
    
r:=pp/(25/50);
    
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-0.95,3*π/2);
    
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+.95);
    
    
r:=pp/(75/50);
    
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-2,3*π/2);
    
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+2);
    
    
r:=pp/(12.5/50);
    
ARC_P(L9(1)+pp,L9(2)-r,r,3*π/2-0.5,3*π/2);
    
ARC_P(L9(1)+pp,L9(2)+r,r,π/2,π/2+.5);
    
    
Cl:=RGB(0,0,255);
    
TEXTOUT(“50”,0,0,1,cl);
    
TEXTOUT(“25”,-0.33333,0,1,cl);
    
TEXTOUT(“12.5”,-0.80,0,1,cl);
    
TEXTOUT(“100”,0.33333,0,1,cl);
    
    
TEXTOUT(“50”,-0.9,1,1,cl);
    
TEXTOUT(“25”,-0.55,-0.75,1,cl);
    
TEXTOUT(“12.5”,-0.90,-0.30,1,cl);
    
TEXTOUT(“75”,0.4,-0.85,1,cl);
    
    
TEXTOUT(“QUIT”,-1.4,0.9);
    
L2(3) = STRING(f,2,3);
    
TEXTOUT(L2(3)+” GHz”,0.8,0.9);
    
END// DISPSMITH 

http://www.hpcalc.org 20 years online
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)