firmware: Analog read was to shaky, the number of read per millisecond is now increased to 20. meas.py: Some modifications to get the output more userfriendly. CSV output is implemented now.
This commit is contained in:
parent
8bc17c45c7
commit
7e9c8b086e
2 changed files with 55 additions and 18 deletions
|
@ -222,8 +222,16 @@ void cc_startMeasurement()
|
||||||
{
|
{
|
||||||
// 3. on every loop read the analog input A0 and A1 for the in intervall (milliseconds)
|
// 3. on every loop read the analog input A0 and A1 for the in intervall (milliseconds)
|
||||||
// and generate the average value, read the ADC value every milli second.
|
// and generate the average value, read the ADC value every milli second.
|
||||||
a0_sum += analogRead(A0);
|
uint8_t t = 0;
|
||||||
a1_sum += analogRead(A1);
|
uint16_t ta0 = 0;
|
||||||
|
uint16_t ta1 = 0;
|
||||||
|
for (t = 0; t < 20; t++)
|
||||||
|
{
|
||||||
|
ta0 += analogRead(A0);
|
||||||
|
ta1 += analogRead(A1);
|
||||||
|
}
|
||||||
|
a0_sum += (ta0 / 20);
|
||||||
|
a1_sum += (ta1 / 20);
|
||||||
|
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,11 +68,6 @@ THREAD_LOOP_DELAY_S = 0.01
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
MUX_MIN_VAL = 0
|
|
||||||
MUX_MAX_VAL = 7
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
ser = None
|
ser = None
|
||||||
device = "/dev/ttyUSB0"
|
device = "/dev/ttyUSB0"
|
||||||
|
|
||||||
|
@ -339,6 +334,18 @@ def sendSerialData(data):
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
def user_friendly_freq(f):
|
||||||
|
|
||||||
|
if f >= 1000000:
|
||||||
|
return str(f / 1000000.0) + " MHz"
|
||||||
|
|
||||||
|
elif f >= 1000:
|
||||||
|
return str(f / 1000.0) + " kHz"
|
||||||
|
|
||||||
|
return str(f) + " Hz"
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
start_freq = 0
|
start_freq = 0
|
||||||
|
@ -447,7 +454,7 @@ if __name__ == "__main__":
|
||||||
a0 += e[3][5]
|
a0 += e[3][5]
|
||||||
a1 = e[3][6] << 8
|
a1 = e[3][6] << 8
|
||||||
a1 += e[3][7]
|
a1 += e[3][7]
|
||||||
print "freq: " + str(freq)
|
print "freq: " + user_friendly_freq(freq)
|
||||||
print "a0: " + str(a0)
|
print "a0: " + str(a0)
|
||||||
print "a1: " + str(a1)
|
print "a1: " + str(a1)
|
||||||
|
|
||||||
|
@ -471,11 +478,11 @@ if __name__ == "__main__":
|
||||||
intervall += e[3][13]
|
intervall += e[3][13]
|
||||||
drive_str = e[3][14]
|
drive_str = e[3][14]
|
||||||
|
|
||||||
print "start_freq = " + str(start_freq)
|
print "start_freq = " + user_friendly_freq(start_freq)
|
||||||
print "end_freq = " + str(end_freq)
|
print "end_freq = " + user_friendly_freq(end_freq)
|
||||||
print "step_freq = " + str(step_freq)
|
print "step_freq = " + user_friendly_freq(step_freq)
|
||||||
print "intervall = " + str(intervall)
|
print "intervall = " + str(intervall) + " ms"
|
||||||
print "drive_str = " + str(drive_str)
|
print "drive_str = " + str((drive_str + 1) * 2) + " mA"
|
||||||
|
|
||||||
if args.start_meas == True and config_read == False:
|
if args.start_meas == True and config_read == False:
|
||||||
dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq)
|
dataSend = dataSend + 1 + ((end_freq - start_freq) / step_freq)
|
||||||
|
@ -489,19 +496,33 @@ if __name__ == "__main__":
|
||||||
meas_r = []
|
meas_r = []
|
||||||
meas_p = []
|
meas_p = []
|
||||||
|
|
||||||
|
min_vswr = [ 10, 0 ] # the default VSWR is 10 and the default freq is 0]
|
||||||
|
|
||||||
i = ((drive_str + 1) * 2.0) / 1000.0
|
i = ((drive_str + 1) * 2.0) / 1000.0
|
||||||
|
|
||||||
if args.output_file != None or args.show_graph == True:
|
if args.output_file != None or args.show_graph == True:
|
||||||
for m in meas_data:
|
for m in meas_data:
|
||||||
|
|
||||||
meas_freq.append(m[0])
|
meas_freq.append(m[0])
|
||||||
|
vswr = 0
|
||||||
|
|
||||||
|
if m[1] > 0 and m[2] > 0:
|
||||||
if m[1] > m[2]:
|
if m[1] > m[2]:
|
||||||
meas_ratio.append(m[1] / m[2])
|
vswr = (m[1] / m[2])
|
||||||
|
meas_ratio.append(vswr)
|
||||||
elif m[1] < m[2]:
|
elif m[1] < m[2]:
|
||||||
meas_ratio.append(m[2] / m[1])
|
vswr = (m[2] / m[1])
|
||||||
|
meas_ratio.append(vswr)
|
||||||
else:
|
else:
|
||||||
|
vswr = 1
|
||||||
meas_ratio.append(1)
|
meas_ratio.append(1)
|
||||||
|
else:
|
||||||
|
vswr = 1
|
||||||
|
meas_ratio.append(1)
|
||||||
|
|
||||||
|
if vswr < min_vswr[0]:
|
||||||
|
min_vswr[0] = vswr
|
||||||
|
min_vswr[1] = m[0] # the frequency
|
||||||
|
|
||||||
# R = meas_data[0] * 5V / 1023 * I
|
# R = meas_data[0] * 5V / 1023 * I
|
||||||
r = (m[1] * 5.0 / 1023.0) / i
|
r = (m[1] * 5.0 / 1023.0) / i
|
||||||
|
@ -514,7 +535,13 @@ if __name__ == "__main__":
|
||||||
meas_p.append(0)
|
meas_p.append(0)
|
||||||
|
|
||||||
if args.output_file != None:
|
if args.output_file != None:
|
||||||
pass # TODO impl
|
FILE = open(args.output_file, "w")
|
||||||
|
j = 0
|
||||||
|
for m in meas_ratio:
|
||||||
|
FILE.write("%f;%f;%f;%f;%f\n" % (meas_freq[j], m, meas_r[j], meas_p[j], i))
|
||||||
|
j = j + 1
|
||||||
|
FILE.close()
|
||||||
|
print "Output file " + args.output_file + " written."
|
||||||
|
|
||||||
if args.show_graph == True:
|
if args.show_graph == True:
|
||||||
plt.plot(meas_freq, meas_ratio)
|
plt.plot(meas_freq, meas_ratio)
|
||||||
|
@ -524,6 +551,8 @@ if __name__ == "__main__":
|
||||||
print "Please close the mathplot window to exit..."
|
print "Please close the mathplot window to exit..."
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
print "First minimum VSWR " + str(min_vswr[0]) + " found at freqency " + user_friendly_freq(min_vswr[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "err: unknown type 0x%02x" % (e[1])
|
print "err: unknown type 0x%02x" % (e[1])
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue