-
Notifications
You must be signed in to change notification settings - Fork 3
/
Balun_X_Example.py
100 lines (80 loc) · 3.29 KB
/
Balun_X_Example.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'''
This script is to call the appropriate functions to generate a balun with the
'X' structure only. Also, this script assumes that the cells generated by the
individual functions remain in memory so 'Balun_X_Build' function can reference
to them and use them to construct the balun. Apparently this is how 'gdspy' works.
'''
import gdspy
import Balun_Scripts.Balun_Parts as BP
import Balun_Scripts.Valid_Check as VC
from Balun_Scripts.Balun_X_Build import Balun_X_Build
#define global library
lib = gdspy.GdsLibrary()
#########################
# Variables. Change me. #
#########################
# GDS cell name for the balun
Cell_Name = 'Balun_X'
# via row and columns
viaM = 4
# Square via width
viaW = 1
# via spacing
viaS = 1
# Length of the balun
balunLength = 250
# Width of each track
trackWidth = 9
# Spacing between tracks
trackSpacing = 3
# Turns in the primary
primaryTurns = 2
# Turns in the secondary
secondaryTurns = 3
##########################################
# Generate GDS cells of some balun parts #
##########################################
# Order is important as certain functions depend on previously generated GDS cells.
# Generate GDS cell for a square
BP.SQ(lib, trackWidth)
# Generate GDS cell for the via array
BP.VIA(lib, int(viaM), viaW, viaS)
# Generate the 'X' crossover
BP.X(lib, trackWidth, trackSpacing)
#############################################################
# With the given balun parameters, will the balun be valid? #
#############################################################
# Total number of tracks is primary turns plus secondary turns
max_tracks = VC.max_tracks(lib, balunLength, trackWidth, trackSpacing, 'X')
# There should not be zero turns anywhere
ratio_valid = VC.Ratio_X(int(primaryTurns), int(secondaryTurns))
if max_tracks >= (int(primaryTurns) + int(secondaryTurns)) and ratio_valid:
###############################################
# Generate GDS cells of remaining balun parts #
###############################################
# Generate the all the tracks
BP.TR(lib, balunLength, trackWidth, trackSpacing, int(primaryTurns), int(secondaryTurns))
# Generate ports
BP.P(lib, 'X')
################################
# Construct the 'X' type balun #
################################
Balun_X_Build(lib, balunLength, trackWidth, trackSpacing, int(primaryTurns), int(secondaryTurns), C_Name = Cell_Name)
#####################################################
# Only write the balun cell into the GDS file in um #
#####################################################
cell_list = []
cell_list.append(Cell_Name)
gdspy.write_gds(Cell_Name + '.gds', cells = cell_list, unit = 1.0e-6, precision = 1.0e-9)
################################################
# Display all the GDS cells in current library #
################################################
gdspy.LayoutViewer(lib)
else:
##############################
# Display issues with inputs #
##############################
if max_tracks < (int(primaryTurns) + int(secondaryTurns)):
print('Maximum number of tracks is: '+str(max_tracks))
if ratio_valid == False:
print('Turn ratio not valid!')