def main(): parser = argparse.ArgumentParser(prog="set_dac", description="Set a DAC output channel") parser.add_argument( "-d", "--dac_num", type=int, help="Which DAC to set", choices=[0, 1], required=True, ) parser.add_argument( "-c", "--channel", type=str, help="Which channel to set", choices=["a", "b", "all"], required=True, ) parser.add_argument("-v", "--value", type=int, help="DAC value to set", required=True) # Setup arguments args = parser.parse_args() zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) zed.set_dac(args.dac_num, args.channel, args.value)
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) chan = int(sys.argv[1]) pattern = sys.argv[2] print("Resetting waveform buffers and adc...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) zed.init_adcs() time.sleep(0.1) print(f"setting {pattern} test pattern") if pattern == "deskew": print("Setting deskew") zed.set_deskew_pattern(chan) pattern = "custom" elif pattern not in zed.adc_data["test_patterns"]: try: zed.set_custom_pattern(chan, int(pattern)) pattern = "custom" except ValueError: pass if pattern != "none": zed.set_adc_test_pattern(chan, pattern) print("Configuring test conf") zed.fpga_write(f"test_conf[{chan}]", test_conf) zed.fpga_write("buf_reader_dpram_mode", 1) print("Sending software triggers") zed.fpga_write("sw_trig", 1 << chan) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) while True: wfm = zed.read_waveform() if wfm is None: break chan = wfm["chan_num"] evt_len = wfm["evt_len"] wfm_ltc = wfm["ltc"] print(f'chan {chan} adc_samples: {wfm["samples"][:16]}') # look at bit pairs for pair_ind in range(6): pair_vals = (wfm["samples"] >> (2 * pair_ind)) & 0x3 print(f"pair {pair_ind}: {pair_vals[:16]}") # print sample mean to help with testing print(f'sample mean = {np.average(wfm["samples"]):.2f}') print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0)
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) success = True for pat in 0x5A, 0xA5: for dig_num in 0, 1: print(f"Resetting dig {dig_num}") zed.sw_reset(dig_num=dig_num) mod_pat = get_mod_pat(pat, dig_num) print(f"Writing 0x{mod_pat:02x} to scratch reg of dig {dig_num}") zed.adc_write(dig_num=dig_num, adr=0x3F, data=mod_pat) for dig_num in 0, 1: mod_pat = get_mod_pat(pat, dig_num) read_back = zed.adc_read(dig_num=dig_num, adr=0x3F) print(f"read back: 0x{read_back:02x} from dig {dig_num}") success &= read_back == mod_pat if success: print("Success! Everything works") else: print("Failure. Something didn't work.")
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) print("Resetting waveform buffers and adc...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) zed.init_adcs() time.sleep(0.1) for chan in 0, 1: print(f"Setting deskew pattern for chan {chan}") zed.set_deskew_pattern(chan) zed.set_adc_test_pattern(chan, "custom") print(f"Configuring test conf for chan {chan}") zed.fpga_write(f"test_conf[{chan}]", test_conf) print(f"Resetting io & delay for chan {chan}") zed.fpga_write(f"dig_io_reset[{chan}]", 1) zed.fpga_write(f"dig_delay_reset[{chan}]", 1) zed.fpga_write(f"dig_io_reset[{chan}]", 0) zed.fpga_write(f"dig_delay_reset[{chan}]", 0) zed.fpga_write("buf_reader_dpram_mode", 1) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) # results for each channel scan_results = [{}, {}] for _ in range(32): zed.fpga_write("sw_trig", 0x3) wfms = (zed.read_waveform(), zed.read_waveform()) if None in wfms: raise RuntimeError("Failed to read a waveform from both channels!") for wfm in wfms: chan = wfm["chan_num"] delay = zed.fpga_read(f"dig_delay_tapout_low[{chan}]") & 0x1F # scan_results[chan][delay] = check_toggle_wfm(wfm) scan_results[chan][delay] = check_deskew_wfm(wfm) # inc delay zed.fpga_write(f"dig_io_ctrl[{chan}]", 0x3) print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0) for chan in 0, 1: print(f"Channel {chan} results:") print_delay_scan_result(scan_results[chan]) best_delay = get_best_delay(scan_results[chan]) print(f"setting delay for channel {chan} to {best_delay}") set_delay(zed, chan, best_delay) print(f"Chan {chan} delay readback: {read_all_delays(zed, chan)}") if chan == 0: print("-----")
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) print("Resetting waveform buffers...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) time.sleep(0.1) print("Configuring test conf") for chan in 0, 1: zed.fpga_write(f"test_conf[{chan}]", test_conf) zed.fpga_write("buf_reader_dpram_mode", 1) print_wfm_count(zed) print("Sending software triggers") zed.fpga_write("sw_trig", 0x3) print_wfm_count(zed) print("Enabling reader") ltc = None zed.fpga_write("buf_reader_enable", 0x1) while True: wfm = zed.read_waveform() if wfm is None: break chan = wfm["chan_num"] evt_len = wfm["evt_len"] wfm_ltc = wfm["ltc"] if ltc is None: ltc = wfm_ltc try: check_wfm(wfm, ltc) except: print("Failed wfm!") print(wfm) raise print(f'chan {chan} adc_samples: {wfm["samples"][:5]}') print_wfm_count(zed) print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0)
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) print("Resetting waveform buffers...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) zed.fpga_write("buf_reader_dpram_mode", 1) print("Configuring test conf") for chan in 0, 1: zed.fpga_write(f"test_conf[{chan}]", test_conf) print("Causing buffer overflow...") while zed.fpga_read("buf_overflow") != 0x3: zed.fpga_write("sw_trig", 0x3) print_wfm_count(zed) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) print("draining buffers...") counter = 0 start = time.time() samp_acc = 0 while True: wfm = zed.read_waveform() if wfm is None: break samp_acc += len(wfm["samples"]) counter = counter + 1 if counter % 100 == 0: print_wfm_count(zed) delta = time.time() - start print(counter) print_wfm_count(zed) print(f"Read {samp_acc} samples in {delta:.2f} seconds") data_rate = 16 * samp_acc / delta / 1e6 print(f"Data rate: {data_rate:3f} Mbit/s with test_conf of {test_conf}") print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0)
def main(): if len(sys.argv) < 3: print("Usage: fpga_brd.py <start_adr> <read_len>") return 0 start_adr = sys.argv[1] zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) n_to_read = int(sys.argv[2]) read_data = zed.fpga_read(start_adr, read_len=n_to_read) if n_to_read == 1: read_data = [read_data] for word in read_data: print(hex(word))
def main(): if len(sys.argv) == 1: print_register_map() return 0 adr = sys.argv[1] if len(sys.argv) >= 3: data = sys.argv[2] else: data = None zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) if data is not None: zed.fpga_write(adr, data) print(hex(zed.fpga_read(adr)))
def main(): if len(sys.argv) == 1: print_register_map() return 0 dig_num = int(sys.argv[1]) adr = sys.argv[2] if len(sys.argv) >= 4: data = sys.argv[3] else: data = None zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) if data is not None: zed.adc_write(dig_num, adr, data) print(hex(zed.adc_read(dig_num, adr)))
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) if len(sys.argv) == 2: test_conf = int(sys.argv[1]) else: test_conf = default_test_conf print("Resetting waveform buffers and adc...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) zed.init_adcs() time.sleep(0.1) print("Configuring test conf") for chan in 0, 1: zed.fpga_write(f"test_conf[{chan}]", test_conf) zed.fpga_write("buf_reader_dpram_mode", 1) print("Sending software triggers") zed.fpga_write("sw_trig", 0x3) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) wfms = (zed.read_waveform(), zed.read_waveform()) if None in wfms: raise RuntimeError("Failed to read a waveform from both channels!") print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0) wfms = order_wfms(wfms) # quick plotting test fig, axes = plt.subplots(ncols=2, nrows=3, figsize=(12.0, 12.0)) plt.subplots_adjust(hspace=0.3) make_plots(wfms, axes) plt.show()
def main(): if len(sys.argv) < 3: print("Usage: bwr_from_file.py <start_adr> <file_name>") return 0 start_adr = sys.argv[1] h_data = read_file(sys.argv[2]) zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) zed.fpga_burst_write(start_adr, h_data) time.sleep(0.001) n_to_read = len(h_data) // 4 read_data = zed.fpga_read(start_adr, read_len=n_to_read) for word in read_data: print(f"0x{word:4x}")
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) print("Resetting waveform buffers...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) time.sleep(0.1) print("Configuring trigger settings") for chan in (0, 1): zed.fpga_write(f"pre_conf[{chan}]", pre_conf) zed.fpga_write(f"post_conf[{chan}]", post_conf) zed.fpga_write(f"trig_mode[{chan}]", 1) zed.fpga_write(f"trig_threshold[{chan}]", thresh_val) zed.fpga_write("buf_reader_dpram_mode", 1) print("Arming triggers") zed.fpga_write("trig_arm", 0x3) print("Armed readback:") print(zed.fpga_read("trig_armed")) print_wfm_count(zed) print("Enabling triggers") for chan in 0, 1: zed.fpga_write(f"trig_settings[{chan}]", 0x9) print("Armed readback:") print(zed.fpga_read("trig_armed")) print_wfm_count(zed) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) while True: wfm = zed.read_waveform() if wfm is None: break chan = wfm["chan_num"] evt_len = wfm["evt_len"] wfm_ltc = wfm["ltc"] try: check_wfm(wfm) except: print("Failed wfm!") print(wfm) raise print(f'chan {chan} adc_samples: {wfm["samples"][:5]}') tot_index = np.argwhere(wfm["tot"] == 1)[0][0] print(f"chan {chan} tot index: {tot_index}") print_wfm_count(zed) print("disabling triggers...") for chan in 0, 1: zed.fpga_write(f"trig_settings[{chan}]", 0x0) zed.fpga_write(f"trig_mode[{chan}]", 0x0) zed.fpga_write(f"trig_threshold[{chan}]", 0x0) print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0)
def main(): zed = wdcZedboard(dev_path=read_dev_path("./conf/uart_path.txt")) io_rst_state = 0 for chan in 0, 1: io_rst_state |= zed.fpga_read(f"dig_io_reset[{chan}]") if io_rst_state == 1: raise RuntimeError("ADC IO is in reset! " "Either manually enable both ADC IO modules " "or run the delay_scan script.") print("Resetting waveform buffers and adc...") zed.fpga_write("buf_rst", 0xFFFF) zed.fpga_write("buf_rst", 0x0) zed.init_adcs() time.sleep(0.1) for chan in 0, 1: print(f"Setting ramp pattern for chan {chan}") zed.set_adc_test_pattern(chan, "ramp") print(f"Configuring pre conf for chan {chan}") zed.fpga_write(f"pre_conf[{chan}]", pre_conf) print(f"Configuring post conf for chan {chan}") zed.fpga_write(f"post_conf[{chan}]", post_conf) print(f"Setting trig mode for chan {chan}") zed.fpga_write(f"trig_mode[{chan}]", 0x1) zed.fpga_write("buf_reader_dpram_mode", 1) print("Enabling reader") zed.fpga_write("buf_reader_enable", 0x1) # try triggering on chan 0 and linking in chan 1 print("Enabling trigger link for channel 1") zed.fpga_write("trig_link_en", 0x2) print("Arming triggers") zed.fpga_write("trig_arm", 0x3) print("Armed readback:") print(zed.fpga_read("trig_armed")) print("Enabling triggers for channel 1") zed.fpga_write("trig_settings[0]", 0x9) print("Armed readback:") print(zed.fpga_read("trig_armed")) wfms = (zed.read_waveform(), zed.read_waveform()) check_ltcs(wfms) print("Waveforms:") ramp_starts = [None, None] for wfm in wfms: print(wfm) if wfm is not None: print(f'n samples: {len(wfm["samples"])}') ramp_starts[wfm["chan_num"]] = wfm["samples"][0] ramp_offset = (ramp_starts[1] - ramp_starts[0]) & 0xFFF print(ramp_offset) print("Configuring channel 1 for a trigger 8 clock ticks after channel 0") chan1_thresh = (ramp_offset + 2) & 0xFFF print(f"Chan 1 threshold: {chan1_thresh}") zed.fpga_write("trig_threshold[1]", (chan1_thresh + 2) & 0xFFF) zed.fpga_write("trig_settings[1]", 0x9) print("Enabling trig link for both channels") zed.fpga_write("trig_link_en", 0x3) print("Arming triggers") zed.fpga_write("trig_arm", 0x3) print("Armed readback:") print(zed.fpga_read("trig_armed")) wfms = (zed.read_waveform(), zed.read_waveform()) check_ltcs(wfms) print("New waveforms:") for wfm in wfms: print(wfm) if wfm is not None: print(f'n samples: {len(wfm["samples"])}') ramp_starts[wfm["chan_num"]] = wfm["samples"][0] print("disabling triggers...") zed.fpga_write("trig_link_en", 0x0) for chan in 0, 1: zed.fpga_write(f"trig_settings[{chan}]", 0x0) zed.fpga_write(f"trig_threshold[{chan}]", 0x0) zed.fpga_write(f"trig_mode[{chan}]", 0x0) # empty the buffers # while zed.read_waveform() is not None: # pass print("disabling reader...") zed.fpga_write("buf_reader_enable", 0x0)