Created
September 29, 2016 19:36
-
-
Save anonymous/5d53f5bdbc50782a9d5e2c8d7062be69 to your computer and use it in GitHub Desktop.
Determine values of internal KX3 ATU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# (c) 2016 by Holger Schurig, DH3HS | |
# this program is released under the GPLv2 | |
import serial, time | |
# See this post for the backgrounds: | |
# http://elecraft.365791.n2.nabble.com/KX3-Operating-Tip-Determining-the-ATU-s-L-C-values-and-L-net-configuration-td7560189.html | |
L_VALUES = (8, 4, 2, 1, 0.5, 0.25, 0.12, 0.06) | |
C_VALUES = (1360, 680, 330, 164, 82, 39, 18, 10) | |
debug_cmd = False | |
ser = serial.Serial(port = '/dev/ttyUSB0', | |
baudrate=38400, | |
bytesize=serial.EIGHTBITS, | |
parity=serial.PARITY_NONE, | |
stopbits=serial.STOPBITS_ONE, | |
timeout=0.1) | |
def cmd(s): | |
cmd = s | |
ser.write(cmd.encode()) | |
ser.write(';') | |
r = ser.read(64) | |
if debug_cmd: | |
if r: | |
print "tx '%s;' rx '%s'" % (s, r) | |
else: | |
print "tx '%s;' " % s | |
return r | |
def sumbits(value, values): | |
value = int(value, 16) | |
# print "value:", value | |
bit = 8 | |
total = 0.0 | |
while bit: | |
mask = 1 << (bit-1) | |
if value & mask: | |
total += values[8-bit] | |
# print bit, value, mask, value & mask, total | |
bit -= 1 | |
# print total | |
return total | |
def getLCN(): | |
resp = cmd("AK") | |
# print "RESP:", resp | |
l = sumbits(resp[2:4], (8, 4, 2, 1, 0.5, 0.25, 0.12, 0.06)) | |
c = sumbits(resp[4:6], (1360, 680, 330, 164, 82, 39, 18, 10)) | |
n = int(resp[6:8], 16) | |
return (l, c, n) | |
############################################################################# | |
# | |
# Optional automated radio setup | |
# | |
# Just make sure the ATU is on | |
#cmd("MN023") # select ATU menu | |
#cmd("MP002") # turn ATU to "Auto" | |
#cmd("SWH35") # hold CLR to clear all ATU settings for this band | |
#cmd ("MN255") # turn menu off | |
############################################################################# | |
# | |
# Determine L and C and how they are combined | |
# | |
(l, c, n) = getLCN() | |
print "L:", l, "mH, ", | |
print "C:", c, "pF", | |
if n == 0: | |
print "on antenna side" | |
elif n == 1: | |
print "on transmitter side" | |
else: | |
print "invalid answer '%d'" % n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment