May 07, 2024, 10:25:16 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Transformer Calc

Started by aurelCB, September 28, 2008, 07:19:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

Hi...
Here is small utility program wich calculate basic components of transformer.
It is not quiet finished...

'calculate main transformer by Zlatko Vidlanovic/2008
'program written in Creative Basic
DEF w1:window
DEF U1,U2,N1,N2,run,check:int
DEF fx,P,SFe,f,I1,I2:float
DEF N1$,N2$,I1$,I2$:string

CONST B=1:'B=1:' magnetic induction(T)
'open window ----------------------------------------------
WINDOW w1,0,0,500,400,@minbox,0,"Calc Trafo",<class>
Setwindowcolor w1,rgb(210,210,216)
'----------------------------------------------------------
Enabletabs w1,1                                                                                         
'----------------------------------------------------------
SetPrecision 4 :'set decimal places for floating variables                                     
'----------------------------------------------------------
'display --------------------------------------------------------
Drawmode w1,@transparent
'frame
RECT w1,20,20,200,220,rgb(0,0,0),rgb(200,200,206)
RECT w1,22,22,196,216,rgb(239,239,247)
LINE w1,22,237,217,237,rgb(140,140,166)
LINE w1,217,237,217,22,rgb(140,140,156)

RECT w1,30,30,180,200,rgb(0,0,0),rgb(239,239,247)
PSET w1,20,20,rgb(210,210,216):PSET w1,219,20,rgb(210,210,216)
PSET w1,20,239,rgb(210,210,216):PSET w1,219,239,rgb(210,210,216)

SETFONT w1,"Small Fonts",7, 400,0
move w1,140,216:print w1,"---EXAMPLE---"
SETFONT w1,"Courier New",10, 400,0
'EXAMPLE ---------------------------------------------------------
U2=12 :'secondary voltage(V)
move w1,40,140:print w1,"U2 = ",U2," V"
f=50:' frequency(50 or 60 Hz)
P=10:'power(W)-Watt
U1=220:'primary voltage(110 or 220V)
move w1,40,120:print w1,"U1 = ",U1," V"
'SFe=iron core surface in cm2
'1 inch = 2.45 cm
SFe=1.2*(sqrt(P))
move w1,40,40:print w1,"Sf =",SFe," cm2"
fx=B*SFe
move w1,40,60:print w1,"fx =",fx," Wb"
fx=fx*10^-4 : 'measure must be in meters
N1=U1/(4.44*fx*f):' primary coil
move w1,40,80:print w1,"N1 = ",N1," turns"
N2=N1*(U2/U1):'secondary coil
move w1,40,100:print w1,"N2 = ",N2," turns"
I1=P/U1
move w1,40,160:print w1,"I1 =",I1," A"
I2=P/U2
move w1,40,180:print w1,"I2 =",I2," A"
'Power in Watts
move w1,40,200:print w1,"Pw = ",P," W"

'controls panel---------------------------------------------------
'frame -----------------------------------------------------------
RECT w1,240,64,245,260,rgb(0,0,0),rgb(110,110,136)
PSET w1,240,64,rgb(210,210,216):PSET w1,484,64,rgb(210,210,216)
PSET w1,240,323,rgb(210,210,216):PSET w1,484,323,rgb(210,210,216)
'-----------------------------------------------------------------
'edit controls----------------------------------------------------
CONTROL w1,"E,power,390,80,70,22,@TABSTOP|@cteditnumber,1"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,1
SETCONTROLCOLOR w1,1,rgb(200,220,240),rgb(50,50,50)

CONTROL w1,"E,u1,390,106,70,22,@TABSTOP|@cteditnumber,2"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,2
SETCONTROLCOLOR w1,2,rgb(200,220,240),rgb(50,50,50)

CONTROL w1,"E,u2,390,132,70,22,@TABSTOP|@cteditnumber,3"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,3
SETCONTROLCOLOR w1,3,rgb(200,220,240),rgb(50,50,50)
'-----------------------------------------------------------------
RECT w1,250,164,220,120,rgb(245,245,255)
PSET w1,250,164,rgb(110,110,126):PSET w1,469,164,rgb(110,110,126)
'-----------------------------------------------------------------
CONTROL w1,"E,prim-coil,390,172,70,22,@CTEDITRO,4"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,4
SETCONTROLCOLOR w1,4,rgb(200,220,240),rgb(50,50,50)

CONTROL w1,"E,sec-coil,390,200,70,22,@CTEDITRO,5"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,5
SETCONTROLCOLOR w1,5,rgb(200,220,240),rgb(50,50,50)

CONTROL w1,"E,prim-current,390,228,70,22,@CTEDITRO,6"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,6
SETCONTROLCOLOR w1,6,rgb(200,220,240),rgb(50,50,50)

CONTROL w1,"E,sec-current,390,256,70,22,@CTEDITRO,7"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,7
SETCONTROLCOLOR w1,7,rgb(200,220,240),rgb(50,50,50)

'button panel ----------------------------------------------------
'frame -----------------------------------------------------------
RECT w1,240,20,244,34,rgb(50,50,70),rgb(148,140,160)
PSET w1,240,20,rgb(210,210,216):PSET w1,483,20,rgb(210,210,216)
'buttons ---------------------------------------------------------
CONTROL w1,"B,New,256,28,50,20,@border|0x50000000,8"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,8
SETCONTROLCOLOR w1,8,rgb(200,220,240),rgb(105,105,131)

CONTROL w1,"B,Open,310,28,50,20,@border|0x50000000,9"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,9
SETCONTROLCOLOR w1,9,rgb(200,220,240),rgb(110,110,136)

CONTROL w1,"B,Save,364,28,50,20,@border|0x50000000,10"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,10
SETCONTROLCOLOR w1,10,rgb(200,220,240),rgb(110,110,136)

CONTROL w1,"B,About,418,28,50,20,@border|0x50000000,11"
SETFONT w1,"Microsoft Sans Serif",8, 400,0,11
SETCONTROLCOLOR w1,11,rgb(200,220,240),rgb(110,110,136)

'button CALCULATE -----------------------------------------------
CONTROL w1,"B,CALCULATE,320,290,90,26,@border|0x50000000,20"
SETFONT w1,"Tahoma",10, 700,0,20
SETCONTROLCOLOR w1,20,rgb(225,255,255),rgb(110,110,136)
'----------------------------------------------------------------
'right panel ----------------------------------------------------
Frontpen w1,rgb(245,245,255)
SETFONT w1,"MS Sans Serif",9, 400,0
move w1,260,82:print w1,"Transformer Power ( W )"
move w1,260,110:print w1,"Primary Voltage ( V )"
move w1,260,136:print w1,"Secondary Voltage ( V )"
move w1,260,176:print w1,"Primary Coil ( turns )"
move w1,260,204:print w1,"Secondary Coil ( turns )"
move w1,260,230:print w1,"Primary Current ( A )"
move w1,260,258:print w1,"Secondary Current ( A )"
SETFONT w1,"Small Fonts",7, 400,0
move w1,390,67:print w1,"> USE TAB KEY <"
'cables ------------------------------------------------------------------------
RECT w1,440,53,10,12,rgb(0,0,0):RECT w1,445,54,4,10,rgb(50,50,50),rgb(70,70,70)
RECT w1,220,180,21,20,rgb(0,0,0):RECT w1,220,190,21,10,rgb(0,0,0),rgb(70,70,70)
'-------------------------------------------------------------------------------

run=1
Waituntil run=0
Closewindow w1
End
'---------------------------
SUB <class>

SELECT @class
Case @idclosewindow
run=0
'---------------------------
Case @idcreate
Centerwindow w1
'-----------------------
Case @idcontrol
SELECT @controlid

Case 8
cleardisplay()
clearcontrols()
clearvalues()
setfocus w1

Case 20
cleardisplay()
check=0
clearvalues()
clearcontrols2()
getvalues()
calctrafo()
setout()
setdisplay()
setfocus w1

case 11
aboutT()

ENDSELECT
'-----------------------
ENDSELECT
RETURN
'-----------------------------------------
SUB cleardisplay()
RECT w1,30,30,180,200,rgb(0,0,0),rgb(239,239,247)
RETURN

SUB clearcontrols()
For c=1 to 7
SETCONTROLTEXT w1,c,""
Next c
RETURN

SUB clearcontrols2()
For cn=4 to 7
SETCONTROLTEXT w1,cn,""
Next cn
RETURN

SUB clearvalues()
U1=0:U2=0:N1=0:N2=0
fx=0:P=0:SFe=0:I1=0:I2=0
RETURN

SUB getvalues()
P = val(GETCONTROLTEXT (w1, 1))
IF P=0:messagebox w1,"Power not entered !","Error":return:Endif
U1 = val(GETCONTROLTEXT (w1, 2))
IF U1=0:messagebox w1,"Primary voltage not entered !","Error":return:Endif
U2 = val(GETCONTROLTEXT (w1, 3))
IF U2=0:messagebox w1,"Secondary voltage not entered !","Error":return:Endif
IF (P>0)&(U1>0)&(U2>0) then check=1
RETURN

SUB calctrafo()
IF check=0
Return
Endif
f=50
SFe=1.2*sqrt(P)
fx=B*SFe
fx=fx*(10^-4)
N1=U1/(6.28*fx*f)
N2=N1*(U2/U1)
I1=P/U1
I2=P/U2
RETURN

SUB setout()
IF check=0
Return
Endif
SETCONTROLTEXT w1,4,str$(N1)
SETCONTROLTEXT w1,5,str$(N2)
SETCONTROLTEXT w1,6,str$(I1)
SETCONTROLTEXT w1,7,str$(I2)
RETURN

SUB setdisplay()
IF check=0
cleardisplay()
Return
Endif
Drawmode w1,@transparent
Frontpen w1,rgb(0,0,150)
SETFONT w1,"Courier New",10, 400,0
move w1,40,140:print w1,"U2 = ",U2," V"
move w1,40,120:print w1,"U1 = ",U1," V"
move w1,40,40:print w1,"Sf =",SFe," cm2"
move w1,40,60:print w1,"fx =",fx," Wb"
move w1,40,80:print w1,"N1 = ",N1," turns"
move w1,40,100:print w1,"N2 = ",N2," turns"
move w1,40,160:print w1,"I1 =",I1," A"
move w1,40,180:print w1,"I2 =",I2," A"
move w1,40,200:print w1,"Pw = ",P," W"
RETURN
'---------------------------------------------
SUB aboutT
about$="Transformer Calc     "+Chr$(10)
about1$="Written in Creative Basic   "+chr$(10)
about2$="Aurel 2008   "+chr$(10)
MessageBox w1,about$+chr$(10)+about1$+about2$,"About Transformer Calc",0|64
Return