-
Notifications
You must be signed in to change notification settings - Fork 5
/
tuning.py
357 lines (330 loc) · 10.6 KB
/
tuning.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/env python
"""
To facilitate WCDMA Tx tuning
This file is part of RF_Tuning_Tool.
:copyright: (c) 2013 by the A-mao Chang (maomaoto@gmail.com)
:license: MIT, see COPYING for more details.
"""
import msvcrt
import sys
from WCDMA_attributes import *
from QCOM import *
from Agilent8960 import *
from Anritsu8820C import *
ON_dict = {True:"ON",False:"OFF"}
def main():
# variables
test_band = "B1"
UL_ch = Band_UL_ch_map[test_band][1]
PDM = PDM_init
SMPS_ON = SMPS_ON_init #SMPS ON/OFF
SMPS = SMPS_init #SMPS value
txp = None
aclr = None
tx_on_flag = 0 #ON(1)/OFF(0)
PArange = iPArange_high #set to high gain mode as default
# Set default band at begining
if len(sys.argv) == 2:
test_band = sys.argv[1].upper()
if (test_band not in Band_UL_ch_map):
print("usage: python {0} {1}".format(sys.argv[0], Band_UL_ch_map.keys()))
exit()
else:
print("usage: python {0} {1}".format(sys.argv[0], Band_UL_ch_map.keys()))
exit()
UL_ch = Band_UL_ch_map[test_band][1]
# Set PA range
if (test_band in PA_range_map):
PArange = PA_range_map[test_band][0]
else:
PArange = iPArange_high
# initial instrument and distinguish Agilent and Anritsu
gpib_addr = "GPIB::{0}".format(Instrument_GPIB)
callbox = instrument(gpib_addr)
s = callbox.ask("*IDN?")
print(s)
callbox.close()
callbox = None
if "ANRITSU" in s:
callbox = Anritsu8820C(gpib_addr)
else:
callbox = Agilent8960(gpib_addr)
callbox.timeout = 10
#switch 8960 to WCDMA mode
if (callbox.switch_to_WCDMA() == 1):
print("switch format fail")
exit()
#preset instrument
callbox.preset()
callbox.update_path_loss()
# Set FDD test mode
callbox.set_FDD_test_mode()
# Set UL channel
callbox.set_FDD_UL_channel(UL_ch)
# Setup TxP and ACLR setting
callbox.setup_channel_power_mea(Average_times, "OFF") #Tx power measurement setting
callbox.setup_ACLR_mea(count = Average_times) #ACLR measurement setting
callbox.set_UL_power_FTM(23) #set 8960 UL power
# initial phone
phone = QCOM_phone()
phone.initial_QMSL(bUseQPST)
Phone_Com_Port_c = c_int(Phone_Com_Port)
phone.connect_phone(Phone_Com_Port_c)
phone.set_online_mode()
phone.set_FTM_mode()
# Set band/mode
eModeId = FTM_MODE_ID_WCDMA
eNewMode = Band_QMSL_map[test_band]
phone.set_band(eModeId, eNewMode)
# Set channel
phone.set_channel(UL_ch)
# Set Tx ON
phone.set_Tx_ON()
tx_on_flag = 1
# Set waveform
phone.set_waveform()
# Set PA range @ WCDMA_attributes
phone.set_PA_range(PArange)
# Set PDM
phone.set_PDM(PDM)
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS)
# measure one time
(txp, aclr) = measure(callbox)
#print control key, title, and result
print_command()
print_title()
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
while True:
chr = msvcrt.getch()
#print(chr)
if(chr in b'Qq'):
print("Quit")
break
elif (chr in b'Aa\r'): # enter to measure again
#measure
#print("measure")
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif(chr in b'12458'): #change band
phone.set_Tx_off() # Set Tx OFF
tx_on_flag = 0
test_band = "B"+chr #convert byte to string
#test_band = "B"+str(chr, encoding='UTF-8') #convert byte to string => not applicable in python2
eNewMode = Band_QMSL_map[test_band] # Get QMSL band id
phone.set_band(eModeId, eNewMode) # eModeId is always WCDMA
UL_ch = Band_UL_ch_map[test_band][1] # Set ch to new band Mid ch
callbox.set_FDD_UL_channel(UL_ch) # Set 8960 to new channel
phone.set_channel(UL_ch) # Set phone to new channel
phone.set_Tx_ON() # Set Tx ON
tx_on_flag = 1
phone.set_waveform() # Set waveform
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif(chr in b'Ll'): #Low gain mode
if (test_band in PA_range_map):
PArange = PA_range_map[test_band][1]
else:
PArange = iPArange_low
PDM = PDM_low
SMPS = SMPS_low
#print("{0}, {1}".format(PArange, SMPS))
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
callbox.set_UL_power_FTM(-20) # Set 8960 UL power
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif(chr in b'Hh'):
if (test_band in PA_range_map):
PArange = PA_range_map[test_band][0]
else:
PArange = iPArange_high
PDM = PDM_init
SMPS = SMPS_init
callbox.set_UL_power_FTM(23) #set 8960 UL power
#print("{0}, {1}".format(PArange, SMPS))
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif(chr in b'Oo'):
tx_on_flag = not tx_on_flag
if tx_on_flag:
phone.set_Tx_ON()
print("Tx: ON")
tx_on_flag = 1
phone.set_waveform() # Set waveform
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
else:
phone.set_Tx_off()
print("Tx: OFF")
elif(chr in b'Ss'):
phone.set_Tx_off()
tx_on_flag = 0
if (test_band in PA_range_map):
PArange = PA_range_map[test_band][0]
else:
PA_range = iPArange_high
PDM = PDM_init
SMPS = SMPS_init
callbox.set_UL_power_FTM(23) #set 8960 UL power
print_title()
for UL_ch in Band_UL_ch_map[test_band]: # Set ch to new band Mid ch
callbox.set_FDD_UL_channel(UL_ch) # Set 8960 to new channel
phone.set_channel(UL_ch) # Set phone to new channel
phone.set_Tx_ON() # Set Tx ON
tx_on_flag = 1
phone.set_waveform() # Set waveform
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
txp1 = None # store txp > TARGET_PWR
aclr1 = None
PDM1 = None
txp2 = None # store txp < TARGET_PWR
alcr2 = None
PDM2 = None
(txp, aclr) = measure(callbox)
if (txp > TARGET_PWR):
while (txp > TARGET_PWR):
txp1 = txp
aclr1 = aclr
PDM1 = PDM
if (PDM>PDM_min):
PDM -= 1
else: break
phone.set_PDM(PDM)
(txp, aclr) = measure(callbox)
txp2 = txp
aclr2 = aclr
PDM2 = PDM
else:
while (txp < TARGET_PWR):
txp2 = txp
aclr2 = aclr
PDM2 = PDM
if (PDM>PDM_min):
PDM += 1
else: break
phone.set_PDM(PDM)
(txp, aclr) = measure(callbox)
txp1 = txp
aclr1 = aclr
PDM1 = PDM
print_result(UL_ch, txp1, PDM1, aclr1, PArange, SMPS_ON, SMPS)
print_result(UL_ch, txp2, PDM2, aclr2, PArange, SMPS_ON, SMPS)
elif(chr == b'\xe0'):
chr = msvcrt.getch()
#print(chr)
if (chr in b'Hh'):
# PDM+1
#print("UP key")
if (PDM<PDM_max):
PDM +=1
#print("PDM: {0}".format(PDM))
phone.set_PDM(PDM)
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif (chr in b'Pp'):
#PDM-1
#print("Down key")
if (PDM>PDM_min):
PDM -=1
phone.set_PDM(PDM)
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif (chr in b'Kk'):
#-ch
#print("Left key")
i = Band_UL_ch_map[test_band].index(UL_ch)
if (i>0):
i -= 1
UL_ch = Band_UL_ch_map[test_band][i]
#print(UL_ch)
phone.set_Tx_off() # Set Tx OFF
tx_on_flag = 0
phone.set_band(eModeId, eNewMode) # eModeId is always WCDMA
callbox.set_FDD_UL_channel(UL_ch) # Set 8960 to new channel
phone.set_channel(UL_ch) # Set phone to new channel
phone.set_Tx_ON() # Set Tx ON
tx_on_flag = 1
phone.set_waveform() # Set waveform
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
elif (chr in b'Mm'):
#+ch
#print("Right key")
i = Band_UL_ch_map[test_band].index(UL_ch)
if (i<2):
i += 1
UL_ch = Band_UL_ch_map[test_band][i]
phone.set_Tx_off() # Set Tx OFF
tx_on_flag = 0
phone.set_band(eModeId, eNewMode) # eModeId is always WCDMA
callbox.set_FDD_UL_channel(UL_ch) # Set 8960 to new channel
phone.set_channel(UL_ch) # Set phone to new channel
phone.set_Tx_ON() # Set Tx ON
tx_on_flag = 1
phone.set_waveform() # Set waveform
phone.set_PA_range(PArange) # Set PA range @ WCDMA_attributes
phone.set_PDM(PDM) # Set PDM
# Set SMPS
phone.set_PA_BIAS_override(SMPS_ON) # Set SMPS override ON
phone.set_PA_BIAS_value(SMPS) # Set SMPS
(txp, aclr) = measure(callbox)
print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS)
else:
print_command()
print_title()
#Set Tx OFF
phone.set_Tx_off()
# Disconnect phone
phone.disconnect()
callbox.close()
exit()
def print_title():
#print title & result
print("{0:8}, {1:8}, {2:4}, {3:6}, {4:6}, {5:7}, {6:7}".format("channel", "Tx Power", "PDM", "-5MHz", "+5MHz", "PArange", "SMPS"))
def print_result(UL_ch, txp, PDM, aclr, PArange, SMPS_ON, SMPS):
print("{0:^8d}, {1:^8,.2f}, {2:4}, {3:6,.2f}, {4:6,.2f}, PAr:{5:3}, {6:3}:{7:3d}".format(UL_ch, txp, PDM, aclr[0], aclr[1], PArange, ON_dict[bool(SMPS_ON)], SMPS))
def print_command():
print("----------------------------------------------------------")
print("[^]+PDM [v]-PDM [<]-ch [>]+ch [12458]band")
print("[L]GM [H]GM me[A]sure")
print("[S]weep [O]NOFF [Q]uit")
print("----------------------------------------------------------")
def measure(callbox):
#callbox.init_TXP_ACLR() #start channel power & ACLR measurement
#time.sleep(0.1) #wait for stable reading
callbox.init_TXP_ACLR() #start channel power & ACLR measurement again
#read tx power
txp = callbox.read_TXP()
#read ACLR
aclr = callbox.read_ACLR()
return (txp, aclr)
main()