Skip to content

Commit

Permalink
REV: this is not clear and likely a bug by integer/float conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLP committed Jan 6, 2019
1 parent 55c8095 commit 9fbd339
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions basil/HL/MIO_PLL.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# ------------------------------------------------------------
#

from __future__ import division
import logging

from basil.HL.HardwareLayer import HardwareLayer
Expand Down Expand Up @@ -125,27 +124,27 @@ def _calculateParameters(self, fout):
'''
for self.q_counter in range(128):
self.q_total = self.q_counter + 2
if (self.fref // self.q_total) < 0.25: # PLL constraint
if (self.fref / self.q_total) < 0.25: # PLL constraint
break
for self.div in range(2, 128):
q_d_f = self.q_total * self.div * fout
if isinstance(q_d_f, (long, int)) and q_d_f > (15 * self.fref): # = f0 * p
if int(q_d_f) % int(self.fref) == 0: # p, q, and d found
self.p_total = q_d_f // self.fref
self.p_total = q_d_f / self.fref
while self.p_total <= 16: # counter constraint
self.p_total = self.p_total * 2
self.div = self.div * 2
if self.div > 127:
break
if self.p_total > 1023:
break
if ((self.fref * self.p_total // self.q_total) < 100 or (self.fref * self.p_total // self.q_total) > 400): # PLL constraint
if ((self.fref * self.p_total / self.q_total) < 100 or (self.fref * self.p_total / self.q_total) > 400): # PLL constraint
break
if int(self.p_total) % 2 == 0:
self.p_0 = 0
else:
self.p_0 = 1
self.p_counter = ((int(self.p_total) - self.p_0) // 2) - 4 # set p counter value
self.p_counter = ((int(self.p_total) - self.p_0) / 2) - 4 # set p counter value

if self.div == 2:
self.clk1SRC = 0x02
Expand All @@ -172,8 +171,8 @@ def _calculateParameters(self, fout):
else:
if self.p_total <= 1023:
self.chg_pump = 4
ftest = self.fref * self.p_total // self.q_total * 1 // self.div
fvco = self.fref * self.p_total // self.q_total
ftest = self.fref * self.p_total / self.q_total * 1 / self.div
fvco = self.fref * self.p_total / self.q_total
logger.info('PLL frequency set to ' + str(ftest) + ' MHz' + ' (VCO @ ' + str(fvco) + ' MHz)')
return True
logger.error('MIO_PLL: Could not find PLL parameters')
Expand Down

0 comments on commit 9fbd339

Please sign in to comment.