Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
Created February 5, 2020 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogersguedes/474112edb82a5cbb40fea3fe741e9fb0 to your computer and use it in GitHub Desktop.
Save rogersguedes/474112edb82a5cbb40fea3fe741e9fb0 to your computer and use it in GitHub Desktop.
PTP Increment and Addend calculator
#!/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