def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ glitches_per_ps = [] for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector( roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) glitches_per_ps *= 2 zero_glitches = [gl == 0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) n_zero = rising + 1 falling = zero_glitches.index(False, n_zero) n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len optimal_ps = rising + int((falling - rising) / 2) except ValueError: break if longest_min == None: #raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: optimal_ps = optimal_ps % 56 for ps in range(optimal_ps): inc_mmcm_phase(roach, zdok_n) return optimal_ps, glitches_per_ps
def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ glitches_per_ps = [] for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector(roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) glitches_per_ps *= 2 zero_glitches = [gl==0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) n_zero = rising + 1 falling = zero_glitches.index(False, n_zero) n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len optimal_ps = rising + int((falling-rising)/2) except ValueError: break if longest_min==None: #raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: optimal_ps = optimal_ps % 56 for ps in range(optimal_ps): inc_mmcm_phase(roach, zdok_n) return optimal_ps, glitches_per_ps
def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ print "calibrate" set_test_mode(roach, zdok_n, counter=True) sync_adc(roach) glitches_per_ps = [] # shift until we get to some bad data for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector(roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) if glitches > 0: print 'breaking at ps:%d with %d glitches'%(ps,glitches) break inc_mmcm_phase(roach, zdok_n) for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector(roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) unset_test_mode(roach, zdok_n) print glitches_per_ps; zero_glitches = [gl==0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) except ValueError: break print "rising, nzero", rising, n_zero n_zero = rising + 1 try: falling = zero_glitches.index(False, n_zero) except ValueError: falling = len(zero_glitches) - 1 print "falling, nzero", falling, n_zero n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len print " longest_min",longest_min optimal_ps = rising + int((falling-rising)/2) if longest_min==None: #raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: # decrement MMCM back to optimal place for ps in range(ps_range - optimal_ps): inc_mmcm_phase(roach, zdok_n, inc=0) return optimal_ps, glitches_per_ps
def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ set_test_mode(roach, zdok_n, counter=True) sync_adc(roach) glitches_per_ps = [] #start off by decrementing the mmcm right back to the beginning print "decrementing mmcm to start" for ps in range(ps_range): inc_mmcm_phase(roach, zdok_n, inc=0) for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector( roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) unset_test_mode(roach, zdok_n) zero_glitches = [gl == 0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) print "rising, nzero", rising, n_zero n_zero = rising + 1 falling = zero_glitches.index(False, n_zero) print "falling, nzero", falling, n_zero n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len print " longest_min", longest_min optimal_ps = rising + int((falling - rising) / 2) except ValueError: break if longest_min == None: #raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: for ps in range(optimal_ps): inc_mmcm_phase(roach, zdok_n) return optimal_ps, glitches_per_ps
def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ set_test_mode(roach, zdok_n, counter=True) sync_adc(roach) glitches_per_ps = [] # start off by decrementing the mmcm right back to the beginning print "decrementing mmcm to start" for ps in range(ps_range): inc_mmcm_phase(roach, zdok_n, inc=0) for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector(roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = ( total_glitches(core_a, 8) + total_glitches(core_c, 8) + total_glitches(core_b, 8) + total_glitches(core_d, 8) ) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) unset_test_mode(roach, zdok_n) zero_glitches = [gl == 0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) print "rising, nzero", rising, n_zero n_zero = rising + 1 falling = zero_glitches.index(False, n_zero) print "falling, nzero", falling, n_zero n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len print " longest_min", longest_min optimal_ps = rising + int((falling - rising) / 2) except ValueError: break if longest_min == None: # raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: for ps in range(optimal_ps): inc_mmcm_phase(roach, zdok_n) return optimal_ps, glitches_per_ps
def calibrate_mmcm_phase(roach, zdok_n, snap_names, bitwidth=8, man_trig=True, wait_period=2, ps_range=56): """ This function steps through all 56 steps of the MMCM clk-to-out phase and finds total number of glitchss in the test vector ramp per core. It then finds the least glitchy phase step and sets it. """ print "calibrate" set_test_mode(roach, zdok_n, counter=True) sync_adc(roach) glitches_per_ps = [] # shift until we get to some bad data for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector( roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) if glitches > 0: print 'breaking at ps:%d with %d glitches' % (ps, glitches) break inc_mmcm_phase(roach, zdok_n) for ps in range(ps_range): core_a, core_c, core_b, core_d = get_test_vector( roach, snap_names, man_trig=man_trig, wait_period=wait_period) glitches = total_glitches(core_a, 8) + total_glitches(core_c, 8) + \ total_glitches(core_b, 8) + total_glitches(core_d, 8) glitches_per_ps.append(glitches) inc_mmcm_phase(roach, zdok_n) unset_test_mode(roach, zdok_n) print glitches_per_ps zero_glitches = [gl == 0 for gl in glitches_per_ps] n_zero = 0 longest_min = None while True: try: rising = zero_glitches.index(True, n_zero) except ValueError: break print "rising, nzero", rising, n_zero n_zero = rising + 1 try: falling = zero_glitches.index(False, n_zero) except ValueError: falling = len(zero_glitches) - 1 print "falling, nzero", falling, n_zero n_zero = falling + 1 min_len = falling - rising if min_len > longest_min: longest_min = min_len print " longest_min", longest_min optimal_ps = rising + int((falling - rising) / 2) if longest_min == None: #raise ValueError("No optimal MMCM phase found!") return None, glitches_per_ps else: # decrement MMCM back to optimal place for ps in range(ps_range - optimal_ps): inc_mmcm_phase(roach, zdok_n, inc=0) return optimal_ps, glitches_per_ps