Created
February 5, 2020 16:50
-
-
Save rogersguedes/474112edb82a5cbb40fea3fe741e9fb0 to your computer and use it in GitHub Desktop.
PTP Increment and Addend calculator
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/env python | |
from tabulate import tabulate | |
import math | |
def getHexStr(num, dig): | |
return '0x{0:0{1}X}'.format(num, dig) | |
minClk=50000000.0 | |
sysClk=216000000.0 | |
#sysClk=76000000.0 | |
#sysClk=144000000.0 | |
ratio=sysClk/minClk | |
tHeaders = ["Tick", "Increment", "Addend"] | |
ANtable = [] | |
RMtable = [] | |
for increment in range(1, 256): | |
# Application Note Calculus | |
tick = increment*math.pow(10,9)/math.pow(2,31) | |
addend = int(math.pow(2,63)/(sysClk*increment)) | |
ANtable.append([tick, increment, getHexStr(addend, 8)]) | |
# Reference Manual Calculus | |
addend = int(math.pow(2, 32) / ratio) | |
increment= int(math.pow(2,63)/(sysClk*addend)) | |
tick = increment*math.pow(10,9)/math.pow(2,31) | |
RMtable.append([tick, increment, getHexStr(addend, 8)]) | |
print "Application Note Calculus" | |
print(tabulate(ANtable, tHeaders, tablefmt="grid")) | |
print "Reference Manual Calculus" | |
print(tabulate(RMtable, tHeaders, tablefmt="grid")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment