From 82545605779d5dee5ba292744279792c31ed39c0 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 27 Jan 2019 16:00:36 +0800 Subject: [PATCH] sayma: properly determine SYSREF coarse calibration target --- artiq/firmware/libboard_artiq/jesd204sync.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/artiq/firmware/libboard_artiq/jesd204sync.rs b/artiq/firmware/libboard_artiq/jesd204sync.rs index f457b5f24..298f84bb6 100644 --- a/artiq/firmware/libboard_artiq/jesd204sync.rs +++ b/artiq/firmware/libboard_artiq/jesd204sync.rs @@ -135,7 +135,12 @@ fn reach_sysref_ddmtd_target(target: i32, tolerance: i32) -> Result<(), &'static } fn calibrate_sysref_target(rising_average: i32, falling_average: i32) -> Result { - let coarse_target = (falling_average - 16 + DDMTD_N) % DDMTD_N; // HACK + let coarse_target = + if rising_average < falling_average { + (rising_average + falling_average)/2 + } else { + ((falling_average - (DDMTD_N - rising_average))/2 + DDMTD_N) % DDMTD_N + }; info!("SYSREF calibration coarse target: {}", coarse_target); reach_sysref_ddmtd_target(coarse_target, 2)?; let target = measure_ddmdt_phase();