File indexing completed on 2024-11-27 03:17:55
0001 from math import pi,floor
0002
0003
0004 print(int(((-330+1024)*pi/(6.0*2048.0))/(0.625*pi/180.0)))
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 def bits(number, size_in_bits):
0026 """
0027 The bin() function is *REALLY* unhelpful when working with negative numbers.
0028 It outputs the binary representation of the positive version of that number
0029 with a '-' at the beginning. Woop-di-do. Here's how to derive the two's-
0030 complement binary of a negative number:
0031
0032 complement(bin(+n - 1))
0033
0034 `complement` is a function that flips each bit. `+n` is the negative number
0035 made positive.
0036
0037 """
0038 if number < 0:
0039 return compliment(bin(abs(number) - 1)[2:]).rjust(size_in_bits, '1')
0040 else:
0041 return bin(number)[2:].rjust(size_in_bits, '0')
0042
0043 def compliment(value):
0044 return ''.join(COMPLEMENT[x] for x in value)
0045
0046 COMPLEMENT = {'1': '0', '0': '1'}
0047
0048
0049
0050
0051
0052
0053
0054 phiLUT=[]
0055 kPHI = 57.2958/0.625/1024.;
0056
0057 for i in range(0,1024):
0058 phiLUT.append(0)
0059 for phi in range(-512,512):
0060 address = int(bits(phi,10),2)
0061 phiF=float(phi)
0062 phiNew = 24+int(floor(kPHI*phiF));
0063 if phiNew > 69:
0064 phiNew = 69;
0065 if phiNew < -8:
0066 phiNew = -8;
0067 phiLUT[address]=(str(phiNew))
0068 print('const ap_int<8> phiLUT[1024] = {'+','.join(phiLUT)+'};')
0069
0070
0071
0072 ptLUT=[]
0073 lsb = 1.25/(1<<13)
0074 for i in range(0,4096):
0075 ptLUT.append(6)
0076 for K in range(-2048,2048):
0077 address = int(bits(K,12),2)
0078 if K>=0:
0079 charge=1
0080 else:
0081 charge=-1
0082
0083
0084
0085 FK=lsb*abs(K)
0086
0087 if abs(K)>2047:
0088 FK=lsb*2047
0089
0090 if abs(K)<26:
0091 FK=lsb*26
0092
0093 FK = 0.898*FK/(1.0-0.6*FK);
0094 FK=FK-26.382*FK*FK*FK*FK*FK;
0095 FK=FK-charge*1.408e-3;
0096 FK=FK/1.17;
0097 if (FK!=0.0):
0098 pt=int(2.0/FK)
0099 else:
0100 pt=511
0101
0102 if pt>511:
0103 pt=511
0104
0105 if pt<6:
0106 pt=6;
0107 ptLUT[address]=str(pt)
0108
0109
0110
0111
0112 print('const ap_uint<9> ptLUT[4096] = {'+','.join(ptLUT)+'};')