最近要用单片机配置MAX2150,ADF4106 ,于是用python写了个脚本输出寄存器的值。
'''
计算MAX2150的寄存器值。参见datasheetP9页。
D=N.F=N+F/pow(2,28) ---N整数,F小数
D=F_lo/F_comp ---其中N为D的整数部分,F为D的小数部分乘以2的28次方。
word1 = F的高14位再左移两位(地址0)
word2 = F的低14位再左移两位+1(地址1)
word3 = (18<<10)+(N<<2)+2 #010010=18 (地址2)
Author: liuyong
Date: 2013-08-13
'''
F_comp=20
for i in range(990,1122):#F_lo=i,F_comp=20MHz,
D = i/F_comp
N = int(D)
F = (D-N)*pow(2,28)
FH = int(F)>>14
FL = int(F) & 0x3FFF
word1 = FH<<2;
word2 = (FL<<2)+1;
word3 = (18<<10)+(N<<2)+2 #010010=18
str = '0x%04X,0x%04X,0x%04X, //%dMhz' % (word1,word2,word3,i)
print(str)
'''
#str= '%i,w1=%04X,w2=%04X,w3=%04X' % {i,word1,word2,word3}
#str ="{0:#06x},{0:#06x},{0:#06x},{0:d}MHz".format(word1,word2,word3,i)
#print(i,": w1=",word1,",w2=",word2,",w3=",word3)
#str = '{:04X}{:02x}'.format(254,12)
# str= 'i%d,w1=%04X,w2=%04X,w3=%04X' % {i,word1,word2,word3}
'''
////////////////////////////////////////
#0x1f,0x80,0x93, 0x1f,0x80,0x92, 0x00,0x00,0x50, 0x00,0x7d,0x01 1000MHz
'''
该脚本用于ADF4106寄存器的配置
Author: liuyong
Date: 2013-08-13
(B*P+A) * PFD = RFout
'''
F_out = 1000 #输出频率(MHz)
F_ref = 20 #参考频率(MHz)
F_pfd = 1 #鉴相频率(MHz)
Pres = 8 #Prescaler(8/9,16/17,32/33,64/65)
for i in range(999,1122):
Fre = i/F_pfd #输出/鉴相
B = int(Fre/Pres)
A = Fre - 8*B
#str = 'B=%d,A=%d, //%dMhz' % (B,A,i)
N = (B<<8) + (int(A)<<2) + 1 #地址1
N_h = N>>8
N_l = N&0xFF
str='0x1F,0x80,0x93, 0x1F,0x80,0x92,\
0x00,0x00,0x50, 0x00,\
0x%02X,0x%02X, //%dMhz' % (N_h,N_l,i)
print(str)