Skip to content

Instantly share code, notes, and snippets.

@aewallin
Created October 22, 2018 12:30
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 aewallin/6aff7227e95ef169a05d9dd3eb4ded35 to your computer and use it in GitHub Desktop.
Save aewallin/6aff7227e95ef169a05d9dd3eb4ded35 to your computer and use it in GitHub Desktop.
DDS and u-stepper calclations
import bigfloat
import numpy
dds_clk=1.0e9
ftw_length = pow(2,48)
IF = 100e6/1024.0 # 97656.25
def ftw_dds(f_hz):
return numpy.round(f_hz*ftw_length/dds_clk,0)
def hz_dds(ftw):
return dds_clk*ftw/ftw_length
def y_out(ftw1, ftw2):
""" fractional frequency of microstepper
F_out / F_REF
"""
with bigfloat.precision(200):
F1term = bigfloat.BigFloat.exact(ftw1 )
F2term = bigfloat.BigFloat.exact(ftw2/1024.0)
Fsum = F1term+F2term
y = 4.0*ftw_length* bigfloat.pow( 10.0*(Fsum), -1.0)-1
return y
F1 = ftw_dds(400e6-4*IF) # DDS1
F2 = ftw_dds(400e6) # DDS2
y1 = y_out(F1,F2)
y2 = y_out(F1,F2+1)
print "uStep output fractional frequency y"
print "FTW1 = %d (constant)" % F1
print "FTW2\t\tdFTW2\ty"
for delta in [-5,-4,-3,-2,-1,0,1,2,3,4,5]:
F2x = F2+delta-205
y1 = y_out(F1,F2x)
print "%d\t%d\t%.3g" % ( F2x, delta, y1)
""" OUTPUT:
uStep output fractional frequency y
FTW1 = 112480039521485 (constant)
FTW2 dFTW2 y
112589990684052 -5 4.86e-17
112589990684053 -4 3.99e-17
112589990684054 -3 3.12e-17
112589990684055 -2 2.26e-17
112589990684056 -1 1.39e-17
112589990684057 0 5.2e-18
112589990684058 1 -3.47e-18
112589990684059 2 -1.21e-17
112589990684060 3 -2.08e-17
112589990684061 4 -2.95e-17
112589990684062 5 -3.82e-17
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment