cube-kl/firmware/scripts/parameter_test.py

44 lines
838 B
Python

#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
PLL_FREQ = 800*10**6 # Mhz
def main():
# 8kHz to 150MHz
out_freq = np.uint32(np.arange(1*10**6, 160*10**6, 10))
fdiv = PLL_FREQ / out_freq
rm = PLL_FREQ % out_freq
c = np.uint32(0x0FFFFF);
a = np.uint32(fdiv)
b = np.uint32(np.uint64(c) * np.uint64(rm) / out_freq)
ideal_freq = PLL_FREQ / fdiv
real_freq = PLL_FREQ / (a + b/c)
err = (ideal_freq - real_freq)
out_freq = out_freq / 10**6
ideal_freq = ideal_freq / 10**6
real_freq = real_freq / 10**6
p1 = 128 * a + np.floor(128 * b / c) - 512;
p2 = 128 * b - c * np.uint32(128 * b / c);
#plt.plot(out_freq, ideal_freq)
#plt.plot(out_freq, real_freq)
plt.plot(out_freq, err)
plt.show()
if __name__ == '__main__':
main()