From 6636560c41c91ab49734dfa795b6ddfeca369cd1 Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Wed, 13 Jul 2022 11:12:20 +0200 Subject: [PATCH] cores/clocks/lattice_ecp5: Fix phase calculation to match Diamond output --- litex/soc/cores/clock/lattice_ecp5.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/litex/soc/cores/clock/lattice_ecp5.py b/litex/soc/cores/clock/lattice_ecp5.py index ea69b945f..aead77333 100644 --- a/litex/soc/cores/clock/lattice_ecp5.py +++ b/litex/soc/cores/clock/lattice_ecp5.py @@ -159,11 +159,11 @@ class ECP5PLL(LiteXModule): self.comb += self.locked.eq(locked & ~self.reset) for n, (clk, f, p, m, dpa) in sorted(self.clkouts.items()): div = config[f"clko{n}_div"] - cphase = int(p*(div + 1)/360 + div - 1) + phase = round(p*div/45) self.params[f"p_CLKO{n_to_l[n]}_ENABLE"] = "ENABLED" self.params[f"p_CLKO{n_to_l[n]}_DIV"] = div - self.params[f"p_CLKO{n_to_l[n]}_FPHASE"] = 0 - self.params[f"p_CLKO{n_to_l[n]}_CPHASE"] = cphase + self.params[f"p_CLKO{n_to_l[n]}_FPHASE"] = phase & 7 + self.params[f"p_CLKO{n_to_l[n]}_CPHASE"] = (phase >> 3) + (div - 1) self.params[f"o_CLKO{n_to_l[n]}"] = clk if f > 0: # i.e. not a feedback-only clock self.params["attr"].append((f"FREQUENCY_PIN_CLKO{n_to_l[n]}", str(f/1e6)))