Exemplo n.º 1
0
def main(num_trig):
    print("Connect to LabRAD manager.")
    cxn = labrad.connect(LABRAD_HOST)
    rft = cxn.zcu111_rftool_labrad_server

    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES, dac_freq=DAC_FREQ,
                       carrier_freq=20., amplitude=30000.0)
    sin_wave = nu.bytes_to_real(wgen.sinwave())

    amplitude = np.linspace(-1., 1., DAC_SAMPLES, endpoint=False)

    w_data = (sin_wave * amplitude).reshape(1, -1)[0].astype("<i2").tobytes()

    del sin_wave, amplitude

    w_size = len(w_data)  # for 16bit signed integer
    r_size = ADC_SAMPLES * 4  # for 32bit signed integer

    rft.termmode(0)

    print("Configure Bitstream.")
    config_bitstream(rft, BITSTREAM)

    print("Setup ADC.")
    for tile in [0, 1, 2, 3]:
        for block in [0, 1]:
            rft.setmixersettings(0, tile, block, 0.0, 0.0,
                2, 2, 0, 3, 0)
            rft.resetncophase(0, tile, block)
            rft.updateevent(0, tile, block, 1)
        rft.setupfifo(0, tile, 0)
        for block in [0, 1]:
            rft.setdither(tile, block, 1 if ADC_FREQ > 3000. else 0)
            rft.setdecimationfactor(tile, block, DUC_DDC_FACTOR)
        rft.setfabclkoutdiv(0, tile, 2 + int(np.log2(DUC_DDC_FACTOR)))
        for block in [0, 1]:
            rft.intrclr(0, tile, block, -1)
        rft.setupfifo(0, tile, 1)

    print("Setup DAC.")
    for tile in [0, 1]:
        for block in [0, 1, 2, 3]:
            rft.setmixersettings(1, tile, block, 0.0, 0.0,
                2, 1, 16, 4, 0)
            rft.resetncophase(1, tile, block)
            rft.updateevent(1, tile, block, 1)
        rft.setupfifo(1, tile, 0)
        for block in [0, 1, 2, 3]:
            rft.setinterpolationfactor(tile, block, DUC_DDC_FACTOR)
        rft.setfabclkoutdiv(1, tile, 2 + int(np.log2(DUC_DDC_FACTOR)))
        for block in [0, 1, 2, 3]:
            rft.intrclr(1, tile, block, -1)
        rft.setupfifo(1, tile, 1)

    print("Clear BlockRAM.")
    rft.clearbram()

    for ch in [6, 7]:
        print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
        writedatatomemory_w(rft, 1, ch, w_size, w_data)

    print("Setting trigger information.")
    rft.settriggerinfo(0, 0xFF, ADC_SAMPLES, 0)
    rft.settriggerinfo(1, 0xFF, DAC_SAMPLES, 0)
    rft.settriggerlatency(0, 97)
    rft.settriggerlatency(1, 0)
    rft.settriggercycle(32768, 1)  # trigger 32768 times
    rft.setaccumulatemode(0)  # disable accumulation

    print("Start trigger.")
    rft.starttrigger()  # for ADC calibration

    wait_trig_done(rft)

    print("Clear BlockRAM.")
    rft.clearbram()

    for ch in [6, 7]:
        print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
        writedatatomemory_w(rft, 1, ch, w_size, w_data)

    print("Setting trigger information.")
    rft.settriggercycle(num_trig, 1)
    rft.setaccumulatemode(1)  # enable accumulation

    print("Start trigger.")
    rft.starttrigger()  # for ADC accumualtion

    wait_trig_done(rft)

    r_data = []
    for ch in [0, 1]:
        print("Receive waveform data from ADC Ch.{} BlockRAM".format(ch))
        r_data.append(readdatafrommemory_w(rft, 0, ch, r_size))

    print("Check interrupt flags.")
    for ch in range(8):  # ADC
        check_intr_flags(rft, 0, ch)
    for ch in range(8):  # DAC
        check_intr_flags(rft, 1, ch)

    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data
    print("- ADC sample data")
    r_sample = np.array([nu.bytes_to_real_32(rd) for rd in r_data])
    del r_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR + str(num_trig) + "/", exist_ok=True)

    print("- entire DAC")
    plot_graph_entire(
        DAC_FREQ,
        w_sample,
        "C0",
        "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        PLOT_DIR + str(num_trig) + "/bram_send.png"
    )

    print("- crop DAC")
    plot_graph_crop(
        DAC_FREQ,
        w_sample,
        "C0",
        "DAC waveform {} samples{}, {} Msps".format(
            DAC_SAMPLES,
            " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
            DAC_FREQ),
        PLOT_DIR + str(num_trig) + "/bram_send_crop.png"
    )

    print("- FFT DAC")
    plot_graph_fft(
        DAC_FREQ,
        w_sample,
        "C0",
        "DAC FFT, {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        PLOT_DIR + str(num_trig) + "/bram_send_fft.png"
    )

    for ch in [0, 1]:
        print("- entire ADC Ch.{}".format(ch))
        plot_graph_entire(
            ADC_FREQ,
            r_sample[ch],
            "C{}".format(ch + 1),
            "ADC waveform {} samples, {} Msps({} times accum.)".format(ADC_SAMPLES, ADC_FREQ, str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}.png".format(ch)
        )

        print("- crop ADC Ch.{}".format(ch))
        plot_graph_crop(
            ADC_FREQ,
            r_sample[ch],
            "C{}".format(ch + 1),
            "ADC waveform {} samples{}, {} Msps({} times accum.)".format(
                ADC_SAMPLES,
                " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
                ADC_FREQ, str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}_crop.png".format(ch)
        )

        print("- FFT ADC Ch.{}".format(ch))
        plot_graph_fft(
            ADC_FREQ,
            r_sample[ch],
            "C{}".format(ch + 1),
            "ADC FFT {} samples, {} Msps({} times accum.)".format(ADC_SAMPLES, ADC_FREQ, str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}_fft.png".format(ch)
        )

    print("Done.")
    return
Exemplo n.º 2
0
def main():
    print("Connect to LabRAD manager.")
    cxn = labrad.connect(LABRAD_HOST)
    rft = cxn.zcu111_rftool_labrad_server

    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES,
                       dac_freq=DAC_FREQ,
                       carrier_freq=10.67,
                       amplitude=-30000.)
    sin_data = wgen.sinwave()
    pulse_data = wgen.pulsewave()
    tri_data = wgen.triwave()
    saw_data = wgen.sawwave()
    awg_data = sin_data
    mac_wav_data = sin_data + pulse_data + tri_data + saw_data
    adc_cap_len = ADC_SAMPLES * 2  # 16-bit signed integer
    dac_words = int(DAC_SAMPLES / 8)

    rft.termmode(0)

    print("Configure Bitstream.")
    config_bitstream(rft, BITSTREAM)

    print("Setup ADC.")
    for tile in [0, 1, 2, 3]:
        for block in [0, 1]:
            rft.setmixersettings(0, tile, block, 0.0, 0.0, 2, 2, 0, 3, 0)
            rft.resetncophase(0, tile, block)
            rft.updateevent(0, tile, block, 1)
        rft.setupfifo(0, tile, 0)
        for block in [0, 1]:
            rft.setdither(tile, block, 0)
            rft.setdecimationfactor(tile, block, 1)
        rft.setfabclkoutdiv(0, tile, 2)
        for block in [0, 1]:
            rft.intrclr(0, tile, block, -1)
        rft.setupfifo(0, tile, 1)

    print("Setup DAC.")
    for tile in [0, 1]:
        for block in [0, 1, 2, 3]:
            rft.setmixersettings(1, tile, block, 0.0, 0.0, 2, 1, 16, 4, 0)
            rft.resetncophase(1, tile, block)
            rft.updateevent(1, tile, block, 1)
        rft.setupfifo(1, tile, 0)
        for block in [0, 1, 2, 3]:
            rft.setinterpolationfactor(tile, block, 1)
        rft.setfabclkoutdiv(1, tile, 1)
        for block in [0, 1, 2, 3]:
            rft.intrclr(1, tile, block, -1)
        rft.setupfifo(1, tile, 1)

    print("Clear BlockRAM.")
    rft.clearbram()

    print("Send DAC AWG waveform data / parameters.")
    ## Write waveform data / trigger parameters for DAC AWG
    writedatatomemory_w(rft, 1, CH_AWG_CAP, len(awg_data), awg_data)
    dac_awg_params = np.array([0, dac_words] * 16, dtype="<i4")
    dac_awg_params_b = nu.real_to_bytes_32(dac_awg_params)
    writedatatomemory_w(rft, 5, CH_AWG_CAP, len(dac_awg_params_b),
                        dac_awg_params_b)

    print("Send waveform data for DAC Waveform selector.")
    ## Write waveform data / trigger parameters for DAC Waveform selector
    # 4 patterns output
    writedatatomemory_w(rft, 1, CH_TEST_MAC, len(mac_wav_data), mac_wav_data)

    print("Set trigger parameters.")
    # Set parameters for ADC/DAC-BRAM Bridge controller
    rft.settriggerinfo(0, ((0x1 << CH_TEST_MAC) | (0x1 << CH_AWG_CAP)),
                       ADC_SAMPLES, 0)
    rft.settriggerlatency(0, 48)
    rft.settriggercycle(32768 * 32, 1)
    rft.setmacconfig(0xFF, 0x00)  # all ADC channels is 12-bit format
    # do not trigger all DACs when MAC is overrange

    print("Start Trigger.")
    rft.starttrigger()

    wait_trig_done(rft)

    # Get RFDC ADC interrupt flags / overvoltage detection
    adc_test_ch_flags = rft.getintrstatus(0, (CH_TEST_MAC >> 1) & 0x3,
                                          CH_TEST_MAC & 0x1)[3]
    adc_cap_ch_flags = rft.getintrstatus(0, (CH_AWG_CAP >> 1) & 0x3,
                                         CH_AWG_CAP & 0x1)[3]
    check_adc_overvoltage(adc_test_ch_flags, CH_TEST_MAC)
    check_adc_overvoltage(adc_cap_ch_flags, CH_AWG_CAP)

    print("Receive ADC MAC channel capture data.")
    # Get ADC capture data of test channel
    adc_mac_capdata = readdatafrommemory_w(rft, 0, CH_TEST_MAC * 2,
                                           adc_cap_len)

    adc_awg_force_captures = []
    for sel_pattern in [0, 1, 2, 3]:
        print("Set force DAC Waveform selector output pattern {}".format(
            sel_pattern))
        dac_sel_params = np.array([sel_pattern * dac_words, dac_words] * 16,
                                  dtype="<i4")
        dac_sel_params_b = nu.real_to_bytes_32(dac_sel_params)
        writedatatomemory_w(rft, 5, CH_TEST_MAC, len(dac_sel_params_b),
                            dac_sel_params_b)

        print("Start Trigger.")
        rft.starttrigger()

        wait_trig_done(rft)

        # Get RFDC ADC interrupt flags / overvoltage detection
        adc_test_ch_flags = rft.getintrstatus(0, (CH_TEST_MAC >> 1) & 0x3,
                                              CH_TEST_MAC & 0x1)[3]
        check_adc_overvoltage(adc_test_ch_flags, CH_TEST_MAC)
        adc_cap_ch_flags = rft.getintrstatus(0, (CH_AWG_CAP >> 1) & 0x3,
                                             CH_AWG_CAP & 0x1)[3]
        check_adc_overvoltage(adc_cap_ch_flags, CH_AWG_CAP)

        print("Receive ADC capture data for DAC Waveform selector output.")
        adc_awg_capdata_force = readdatafrommemory_w(rft, 0, CH_AWG_CAP * 2,
                                                     adc_cap_len)
        adc_awg_capsample_force = np.array(
            nu.bytes_to_real(adc_awg_capdata_force)) / 16
        check_low_input_signal(adc_awg_capsample_force, CH_AWG_CAP)
        adc_awg_force_captures.append(adc_awg_capsample_force)

    print("Disconnect from server.")

    adc_mac_capsample = np.array(
        nu.bytes_to_real(adc_mac_capdata)) / 16  # conv. 12-bit integer
    check_low_input_signal(adc_mac_capsample, CH_TEST_MAC)

    print("Prepare MAC multiplied coefficients for self-test.")

    require_mac_val = [-25165824, -8388608, 8388608, 25165824]
    mac_cap_sq_sum = np.dot(1. * adc_mac_capsample, adc_mac_capsample)
    multiplied_samples = [
        np.round((rq / mac_cap_sq_sum) * adc_mac_capsample).astype("<i4")
        for rq in require_mac_val
    ]

    # print("mac_cap_sq_sum: {}".format(mac_cap_sq_sum))
    # print("require_mac_val / mac_cap_sq_sum = {}".format(np.array(require_mac_val) / mac_cap_sq_sum))
    print("MAC multiplied coefficients .max={0}, min={1}".format(
        np.max(multiplied_samples), np.min(multiplied_samples)))

    multiplied_data = [nu.real_to_bytes_32(smp) for smp in multiplied_samples]
    mac_comp_coeff = np.array([-16777216, 0, 16777216], dtype="<i4")
    mac_comp_coeff_b = nu.real_to_bytes_32(mac_comp_coeff)

    # Clear all ADC interrupt flags
    for tile in [0, 1, 2, 3]:
        for block in [0, 1]:
            rft.intrclr(0, tile, block, -1)

    print("Send ADC MAC result comparation coefficient data.")
    ## Write comparation coefficients for ADC MAC
    writedatatomemory_w(rft, 4, CH_TEST_MAC * 2, len(mac_comp_coeff_b),
                        mac_comp_coeff_b)

    print("Set DAC Waveform selector parameters.")
    dac_sel_params = np.array(
        [
            0 * dac_words,
            dac_words,  # sine
            1 * dac_words,
            dac_words,  # pulse
            2 * dac_words,
            dac_words,  # triangle
            3 * dac_words,
            dac_words,  # sawtooth
        ] * 4,
        dtype="<i4")
    dac_sel_params_b = nu.real_to_bytes_32(dac_sel_params)
    writedatatomemory_w(rft, 5, CH_TEST_MAC, len(dac_sel_params_b),
                        dac_sel_params_b)

    rft.settriggercycle(3, 1)

    adc_awg_result_captures = []
    adc_mac_actual_captures = []
    for sel_pattern in [0, 1, 2, 3]:
        print(
            "Send ADC MAC multiplied coefficient data where DAC Waveform selector output to be pattern {}."
            .format(sel_pattern))
        ## Write Multiplied coefficients for ADC MAC
        writedatatomemory_w(rft, 3, CH_TEST_MAC * 2,
                            len(multiplied_data[sel_pattern]),
                            multiplied_data[sel_pattern])

        print("Start trigger BRAM Bridge controller.")
        rft.starttrigger()

        wait_trig_done(rft)

        mac_ovrrange = rft.getaccumulateoverrange()
        check_mac_overrange(mac_ovrrange, CH_TEST_MAC)

        # Get RFDC ADC interrupt flags / overvoltage detection
        adc_test_ch_flags = rft.getintrstatus(0, (CH_TEST_MAC >> 1) & 0x3,
                                              CH_TEST_MAC & 0x1)[3]
        check_adc_overvoltage(adc_test_ch_flags, CH_TEST_MAC)
        adc_cap_ch_flags = rft.getintrstatus(0, (CH_AWG_CAP >> 1) & 0x3,
                                             CH_AWG_CAP & 0x1)[3]
        check_adc_overvoltage(adc_cap_ch_flags, CH_AWG_CAP)

        print(
            "Receive ADC capture data for DAC Waveform selector output validation."
        )
        # Get ADC capture data of test channel
        adc_awg_result_capdata = readdatafrommemory_w(rft, 0, CH_AWG_CAP * 2,
                                                      adc_cap_len)
        adc_awg_result_capsample = np.array(
            nu.bytes_to_real(adc_awg_result_capdata)) / 16
        check_low_input_signal(adc_awg_result_capsample, CH_AWG_CAP)
        adc_awg_result_captures.append(adc_awg_result_capsample)

        print("Receive ADC MAC channel actual capture data.")
        # Get ADC capture data of test channel
        adc_mac_actual_capdata = readdatafrommemory_w(rft, 0, CH_TEST_MAC * 2,
                                                      adc_cap_len)
        adc_mac_actual_capsample = np.array(
            nu.bytes_to_real(adc_mac_actual_capdata)) / 16
        check_low_input_signal(adc_mac_actual_capsample, CH_TEST_MAC)
        adc_mac_actual_captures.append(adc_mac_actual_capsample)

    time_dac = np.linspace(0.,
                           DAC_SAMPLES / DAC_FREQ,
                           DAC_SAMPLES,
                           endpoint=False)  # us
    time_adc = np.linspace(0.,
                           ADC_SAMPLES / DAC_FREQ,
                           ADC_SAMPLES,
                           endpoint=False)  # us

    validation_res = False
    os.makedirs(PLOT_DIR, exist_ok=True)

    for sel_pattern in [0, 1, 2, 3]:
        print("Validation DAC Waveform selector output pattern {}".format(
            sel_pattern))
        expected_mac_result = np.dot(adc_mac_capsample,
                                     multiplied_samples[sel_pattern])
        print("    Expected MAC Result = {}".format(expected_mac_result))
        actual_mac_result = np.dot(adc_mac_actual_captures[sel_pattern],
                                   multiplied_samples[sel_pattern])
        print(" Actual last MAC Result = {}".format(actual_mac_result))
        adc_awg_error = np.abs(adc_awg_result_captures[sel_pattern] -
                               adc_awg_force_captures[sel_pattern])
        adc_awg_error_sum = np.sum(adc_awg_error)
        print(" DAC Waveform selector output error sum. = {}".format(
            adc_awg_error_sum))
        if adc_awg_error_sum < ERR_THRESHOLD:
            print(
                "Validate DAC Waveform selector output pattern {} successful.".
                format(sel_pattern))
        else:
            print("Validate DAC Waveform selector output pattern {} failed.".
                  format(sel_pattern))
            validation_res = True

        print("Generate graph image.")
        fig = plt.figure(figsize=(8, 6), dpi=300)
        plt.xlabel("Time [us]")
        plt.title(
            "ADC capture DAC Sel. output Pattern {2} ({0} samples, {1} Msps)".
            format(ADC_SAMPLES, ADC_FREQ, sel_pattern))
        plt.plot(time_adc,
                 adc_awg_force_captures[sel_pattern],
                 linewidth=0.8,
                 label="Expected")
        plt.plot(time_adc,
                 adc_awg_result_captures[sel_pattern],
                 linewidth=0.8,
                 label="Actual")
        plt.legend()
        plt.savefig(PLOT_DIR +
                    "adc_cap_dacsel_pattern_{}.png".format(sel_pattern))

        fig = plt.figure(figsize=(8, 6), dpi=300)
        plt.xlabel("Time [us]")
        plt.title(
            "ADC capture DAC AWG output Pattern {2} ({0} samples, {1} Msps)".
            format(ADC_SAMPLES, ADC_FREQ, sel_pattern))
        plt.plot(time_adc, adc_mac_capsample, linewidth=0.8, label="Expected")
        plt.plot(time_adc,
                 adc_mac_actual_captures[sel_pattern],
                 linewidth=0.8,
                 label="Actual")
        plt.legend()
        plt.savefig(PLOT_DIR +
                    "adc_cap_awg_pattern_{}.png".format(sel_pattern))

    print("Done.")
    return validation_res
Exemplo n.º 3
0
def main(num_trig):
    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES,
                       dac_freq=DAC_FREQ,
                       carrier_freq=20.,
                       amplitude=30000.0)
    sin_wave = nu.bytes_to_real(wgen.sinwave())

    amplitude = np.linspace(-1., 1., DAC_SAMPLES, endpoint=False)

    w_data = (sin_wave * amplitude).reshape(1, -1)[0].astype("<i2").tobytes()

    del sin_wave, amplitude

    w_size = len(w_data)  # for 16bit signed integer
    r_size = ADC_SAMPLES * 4  # for 32bit signed integer

    with client.RftoolClient(logger=logger) as rft:
        print("Connect to RFTOOL Server.")
        rft.connect(ZCU111_IP_ADDR)
        rft.command.TermMode(0)

        print("Configure Bitstream.")
        config_bitstream(rft.command, BITSTREAM)

        print("Setup ADC.")
        for tile in [0, 1, 2, 3]:
            for block in [0, 1]:
                rft.command.SetMixerSettings(0, tile, block, 0.0, 0.0, 2, 2, 0,
                                             3, 0)
                rft.command.ResetNCOPhase(0, tile, block)
                rft.command.UpdateEvent(0, tile, block, 1)
            rft.command.SetupFIFO(0, tile, 0)
            for block in [0, 1]:
                rft.command.SetDither(tile, block,
                                      1 if ADC_FREQ > 3000. else 0)
                rft.command.SetDecimationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(0, tile,
                                        2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1]:
                rft.command.IntrClr(0, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(0, tile, 1)

        print("Setup DAC.")
        for tile in [0, 1]:
            for block in [0, 1, 2, 3]:
                rft.command.SetMixerSettings(1, tile, block, 0.0, 0.0, 2, 1,
                                             16, 4, 0)
                rft.command.ResetNCOPhase(1, tile, block)
                rft.command.UpdateEvent(1, tile, block, 1)
            rft.command.SetupFIFO(1, tile, 0)
            for block in [0, 1, 2, 3]:
                rft.command.SetInterpolationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(1, tile,
                                        2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1, 2, 3]:
                rft.command.IntrClr(1, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(1, tile, 1)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in [6, 7]:
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(1, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerInfo(0, 0xFF, ADC_SAMPLES, 0)
        rft.command.SetTriggerInfo(1, 0xFF, DAC_SAMPLES, 0)
        rft.command.SetTriggerLatency(0, 97)
        rft.command.SetTriggerLatency(1, 0)
        rft.command.SetTriggerCycle(32768, 1)  # trigger 32768 times
        rft.command.SetAccumulateMode(0)  # disable accumulation

        print("Configure PMOD.")
        # 4 つの PMOD 出力データ (0xAA, 0xBB, 0xCC, xDD) を設定
        rft.if_data.WriteDataToMemory(2, 0, 4, b"\xAA\xBB\xCC\xDD")
        rft.command.SetPMODConfig(
            bit_to_enable=0xFF,  # 全 PMOD の出力 bit を有効にする
            num_samples=4,  # 出力されるサンプル数 (1サンプル = 8 bit)
            latency=0,  # トリガーレイテンシ
            divratio=32,  # 1 サンプルの出力が保持される長さ (DAC tile 1 のサンプリングレートに依存)
            polarity=0x0F)  # 下位 4 bit の PMOD 出力を反転する

        print("Start trigger.")
        rft.command.StartTrigger()  # for ADC calibration

        wait_trig_done(rft.command)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in [6, 7]:
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(1, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerCycle(num_trig, 1)
        rft.command.SetAccumulateMode(1)  # enable accumulation

        print("Start trigger.")
        rft.command.StartTrigger()  # for ADC accumualtion

        wait_trig_done(rft.command)

        r_data = []
        for ch in [0, 1]:
            print("Receive waveform data from ADC Ch.{} BlockRAM".format(ch))
            r_data.append(rft.if_data.ReadDataFromMemory(0, ch, r_size))

        print("Check interrupt flags.")
        for ch in range(8):  # ADC
            check_intr_flags(rft.command, 0, ch)
        for ch in range(8):  # DAC
            check_intr_flags(rft.command, 1, ch)

    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data
    print("- ADC sample data")
    r_sample = np.array([nu.bytes_to_real_32(rd) for rd in r_data])
    del r_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR + str(num_trig) + "/", exist_ok=True)

    print("- entire DAC")
    plot_graph_entire(
        DAC_FREQ, w_sample, "C0",
        "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        PLOT_DIR + str(num_trig) + "/bram_send.png")

    print("- crop DAC")
    plot_graph_crop(
        DAC_FREQ, w_sample, "C0", "DAC waveform {} samples{}, {} Msps".format(
            DAC_SAMPLES, " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
            DAC_FREQ), PLOT_DIR + str(num_trig) + "/bram_send_crop.png")

    print("- FFT DAC")
    plot_graph_fft(
        DAC_FREQ, w_sample, "C0",
        "DAC FFT, {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        PLOT_DIR + str(num_trig) + "/bram_send_fft.png")

    for ch in [0, 1]:
        print("- entire ADC Ch.{}".format(ch))
        plot_graph_entire(
            ADC_FREQ, r_sample[ch], "C{}".format(ch + 1),
            "ADC waveform {} samples, {} Msps({} times accum.)".format(
                ADC_SAMPLES, ADC_FREQ, str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}.png".format(ch))

        print("- crop ADC Ch.{}".format(ch))
        plot_graph_crop(
            ADC_FREQ, r_sample[ch], "C{}".format(ch + 1),
            "ADC waveform {} samples{}, {} Msps({} times accum.)".format(
                ADC_SAMPLES, " (crop {}-{})".format(CROP_PLOT[0],
                                                    CROP_PLOT[1]), ADC_FREQ,
                str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}_crop.png".format(ch))

        print("- FFT ADC Ch.{}".format(ch))
        plot_graph_fft(
            ADC_FREQ, r_sample[ch], "C{}".format(ch + 1),
            "ADC FFT {} samples, {} Msps({} times accum.)".format(
                ADC_SAMPLES, ADC_FREQ, str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}_fft.png".format(ch))

    print("Done.")
    return
Exemplo n.º 4
0
def main():

    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    # 送信する波の形状をサンプリングレートによらず一定にするため, dac_freq = 4096.0 で固定
    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES,
                       dac_freq=4096.0,
                       carrier_freq=1.0,
                       amplitude=30000.0)
    sin_wave = nu.bytes_to_real(wgen.sinwave())
    amplitude = np.linspace(-1., 1., DAC_SAMPLES, endpoint=False)
    w_data = (sin_wave * amplitude).reshape(1, -1)[0].astype("<i2").tobytes()
    del sin_wave, amplitude
    w_size = len(w_data)  # for 16bit signed integer

    with client.RftoolClient(logger=logger) as rft:
        print("Connect to RFTOOL Server.")
        rft.connect(ZCU111_IP_ADDR)
        rft.command.TermMode(0)

        print("Configure Bitstream.")
        config_bitstream(rft.command, BITSTREAM)

        print("set sampling rate.")
        set_dac_sampling_rate(rft.command, DAC_FREQ)

        print("Setup DAC.")
        for tile in [0, 1]:
            for block in [0, 1, 2, 3]:
                rft.command.SetMixerSettings(DAC, tile, block, 0.0, 0.0, 2, 1,
                                             16, 4, 0)
                rft.command.ResetNCOPhase(DAC, tile, block)
                rft.command.UpdateEvent(DAC, tile, block, 1)
            rft.command.SetupFIFO(DAC, tile, 0)
            for block in [0, 1, 2, 3]:
                rft.command.SetInterpolationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(DAC, tile,
                                        2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1, 2, 3]:
                rft.command.IntrClr(DAC, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(DAC, tile, 1)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in range(8):
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(DAC, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerInfo(DAC, 0xFF, DAC_SAMPLES, USE_REAL)
        rft.command.SetTriggerLatency(DAC, 0)
        rft.command.SetTriggerCycle(1, 1)

        print("Start trigger.")
        rft.command.StartTrigger()

        wait_trig_done(rft.command)

        print("Check interrupt flags.")
        for ch in range(8):
            check_intr_flags(rft.command, DAC, ch)

    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR, exist_ok=True)

    print("- entire DAC")
    plot_graph_entire(
        DAC_FREQ, w_sample, CHUNK_DAC_PLOT, "C0",
        "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES,
                                                  DAC_FREQ), "bram_send.png")

    print("- crop DAC")
    plot_graph_crop(
        DAC_FREQ, w_sample, "C0", "DAC waveform {} samples{}, {} Msps".format(
            DAC_SAMPLES, " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
            DAC_FREQ), "bram_send_crop.png")

    print("- FFT DAC")
    plot_graph_fft(
        DAC_FREQ, w_sample, "C0",
        "DAC FFT, {} samples, {} Msps".format(DAC_SAMPLES,
                                              DAC_FREQ), "bram_send_fft.png")

    print("Done.")
    return
Exemplo n.º 5
0
def main():
    
    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES, dac_freq=DAC_FREQ,
                       carrier_freq=30.0, amplitude=30000.0)
    w_data = wgen.sinwave()
    w_size = len(w_data)  # for 16bit signed integer
    r_size = ADC_SAMPLES * 4 * 2  # for two 32bit signed integer values (I Data and Q Data)
    
    with client.RftoolClient(logger=logger) as rft:
        print("Connect to RFTOOL Server.")
        rft.connect(ZCU111_IP_ADDR)
        rft.command.TermMode(0)

        print("Configure Bitstream.")
        config_bitstream(rft.command, BITSTREAM)

        print("set sampling rate.")
        set_adc_sampling_rate(rft.command, ADC_FREQ)
        set_dac_sampling_rate(rft.command, DAC_FREQ)

        print("Setup ADC.")
        for tile in [0, 1, 2, 3]:
            for block in [0, 1]:
                rft.command.SetMixerSettings(ADC, tile, block, 10, 45.0,
                    2, 2, 16, 3, 0)
                rft.command.ResetNCOPhase(ADC, tile, block)
                rft.command.UpdateEvent(ADC, tile, block, 1)
            rft.command.SetupFIFO(ADC, tile, 0)
            for block in [0, 1]:
                rft.command.SetDither(tile, block, 1 if ADC_FREQ > 3000. else 0)
                rft.command.SetDecimationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(ADC, tile, 2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1]:
                rft.command.IntrClr(ADC, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(ADC, tile, 1)

        print("Setup DAC.")
        for tile in [0, 1]:
            for block in [0, 1, 2, 3]:
                rft.command.SetMixerSettings(DAC, tile, block, 0.0, 0.0,
                    2, 1, 16, 4, 0)
                rft.command.ResetNCOPhase(DAC, tile, block)
                rft.command.UpdateEvent(DAC, tile, block, 1)
            rft.command.SetupFIFO(DAC, tile, 0)
            for block in [0, 1, 2, 3]:
                rft.command.SetInterpolationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(DAC, tile, 2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1, 2, 3]:
                rft.command.IntrClr(DAC, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(DAC, tile, 1)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in [6, 7]:
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(DAC, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerInfo(ADC, 0xFF, ADC_SAMPLES, USE_IQ)
        rft.command.SetTriggerInfo(DAC, 0xFF, DAC_SAMPLES, USE_REAL)
        rft.command.SetTriggerLatency(ADC, 45)
        rft.command.SetTriggerLatency(DAC, 0)
        rft.command.SetTriggerCycle(1, 1)
        rft.command.SetAccumulateMode(0)  # disable accumulation

        print("Start trigger.")
        rft.command.StartTrigger()
        wait_trig_done(rft.command)

        r_data = []
        for ch in [0, 1]:
            print("Receive waveform data from ADC Ch.{} BlockRAM".format(ch))
            r_data.append(rft.if_data.ReadDataFromMemory(ADC, ch, r_size))

        print("Check interrupt flags.")
        for ch in range(8):
            check_intr_flags(rft.command, ADC, ch)
        for ch in range(8):
            check_intr_flags(rft.command, DAC, ch)
    
    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data
    print("- ADC sample data")
    r_sample = np.array([nu.bytes_to_complex_32(rd) for rd in r_data])
    del r_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR, exist_ok=True)

    print("- entire DAC")
    plot_graph_entire(
        DAC_FREQ,
        w_sample,
        1,
        "C0",
        "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        "bram_send.png"
    )

    print("- crop DAC")
    plot_graph_crop(
        DAC_FREQ,
        w_sample,
        "C0",
        "DAC waveform {} samples{}, {} Msps".format(
            DAC_SAMPLES,
            " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
            DAC_FREQ),
        "bram_send_crop.png"
    )

    print("- FFT DAC")
    plot_graph_fft(
        DAC_FREQ,
        w_sample,
        "C0",
        "DAC FFT, {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
        "bram_send_fft.png"
    )    

    for ch in range(2):
        print("- entire ADC Ch.{}".format(ch))
        plot_graph_entire_iq(
            ADC_FREQ,
            r_sample[ch],
            1,
            "C{}".format(ch + 1),
            "ADC waveform {} samples, {} Msps".format(ADC_SAMPLES, ADC_FREQ),
            "bram_recv_{}.png".format(ch)
        )

        print("- crop ADC Ch.{}".format(ch))
        plot_graph_crop_iq(
            ADC_FREQ,
            r_sample[ch],
            "C{}".format(ch + 1),
            "ADC waveform {} samples{}, {} Msps".format(
                ADC_SAMPLES,
                " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
                ADC_FREQ),
            "bram_recv_{}_crop.png".format(ch)
        )

        print("- FFT ADC Ch.{}".format(ch))
        plot_graph_fft_iq(
            ADC_FREQ,
            r_sample[ch],
            "C{}".format(ch + 1),
            "ADC FFT {} samples, {} Msps".format(ADC_SAMPLES, ADC_FREQ),
            "bram_recv_{}_fft.png".format(ch)
        )
    print("Done.")
    return
Exemplo n.º 6
0
def main(num_trig):
    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES,
                       dac_freq=DAC_FREQ,
                       carrier_freq=64.,
                       amplitude=-30000.0)

    w_data = wgen.sinwave()

    w_size = len(w_data)  # for 16bit signed integer
    r_size = ADC_SAMPLES * 4  # for 32bit signed integer

    with client.RftoolClient(logger=logger) as rft:
        print("Connect to RFTOOL Server.")
        rft.connect(ZCU111_IP_ADDR)
        rft.command.TermMode(0)

        print("Configure Bitstream.")
        config_bitstream(rft.command, BITSTREAM)

        print("Setup ADC.")
        for tile in [0, 1, 2, 3]:
            for block in [0, 1]:
                rft.command.SetMixerSettings(0, tile, block, 0.0, 0.0, 2, 2, 0,
                                             3, 0)
                rft.command.ResetNCOPhase(0, tile, block)
                rft.command.UpdateEvent(0, tile, block, 1)
            rft.command.SetupFIFO(0, tile, 0)
            for block in [0, 1]:
                rft.command.SetDither(tile, block,
                                      1 if ADC_FREQ > 3000. else 0)
                rft.command.SetDecimationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(0, tile,
                                        2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1]:
                rft.command.IntrClr(0, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(0, tile, 1)

        print("Setup DAC.")
        for tile in [0, 1]:
            for block in [0, 1, 2, 3]:
                rft.command.SetMixerSettings(1, tile, block, 0.0, 0.0, 2, 1,
                                             16, 4, 0)
                rft.command.ResetNCOPhase(1, tile, block)
                rft.command.UpdateEvent(1, tile, block, 1)
            rft.command.SetupFIFO(1, tile, 0)
            for block in [0, 1, 2, 3]:
                rft.command.SetInterpolationFactor(tile, block, DUC_DDC_FACTOR)
            rft.command.SetFabClkOutDiv(1, tile,
                                        2 + int(np.log2(DUC_DDC_FACTOR)))
            for block in [0, 1, 2, 3]:
                rft.command.IntrClr(1, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(1, tile, 1)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in [6, 7]:
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(1, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerInfo(0, 0xFF, ADC_SAMPLES, 0)
        rft.command.SetTriggerInfo(1, 0xFF, DAC_SAMPLES, 0)
        rft.command.SetTriggerLatency(0, 97)
        rft.command.SetTriggerLatency(1, 0)
        rft.command.SetTriggerCycle(32768, 1)  # trigger 32768 times
        rft.command.SetAccumulateMode(0)  # disable accumulation

        print("Start trigger.")
        rft.command.StartTrigger()  # for ADC calibration

        wait_trig_done(rft.command)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        for ch in [6, 7]:
            print("Send waveform data to DAC Ch.{} BlockRAM".format(ch))
            rft.if_data.WriteDataToMemory(1, ch, w_size, w_data)

        print("Setting trigger information.")
        rft.command.SetTriggerCycle(num_trig, 1)
        rft.command.SetAccumulateMode(1)  # enable accumulation

        print("Start trigger.")
        rft.command.StartTrigger()  # for ADC accumualtion

        wait_trig_done(rft.command)

        r_data = []
        for ch in [0, 1]:
            print("Receive waveform data from ADC Ch.{} BlockRAM".format(ch))
            r_data.append(rft.if_data.ReadDataFromMemory(0, ch, r_size))

        print("Check interrupt flags.")
        for ch in range(8):  # ADC
            check_intr_flags(rft.command, 0, ch)
        for ch in range(8):  # DAC
            check_intr_flags(rft.command, 1, ch)

    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data
    print("- ADC sample data")
    r_sample = np.array([nu.bytes_to_real_32(rd) for rd in r_data])
    del r_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR + str(num_trig) + "/", exist_ok=True)

    # print("- entire DAC")
    # plot_graph_entire(
    #     DAC_FREQ,
    #     w_sample,
    #     "C0",
    #     "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
    #     PLOT_DIR + str(num_trig) + "/bram_send.png"
    # )
    #
    print("- crop DAC")
    plot_graph_crop(
        DAC_FREQ, w_sample, "C0", "DAC waveform {} samples{}, {} Msps".format(
            DAC_SAMPLES, " (crop {}-{})".format(CROP_PLOT[0], CROP_PLOT[1]),
            DAC_FREQ), PLOT_DIR + str(num_trig) + "/bram_send_crop.png")
    #
    # print("- FFT DAC")
    # plot_graph_fft(
    #     DAC_FREQ,
    #     w_sample,
    #     "C0",
    #     "DAC FFT, {} samples, {} Msps".format(DAC_SAMPLES, DAC_FREQ),
    #     PLOT_DIR + str(num_trig) + "/bram_send_fft.png"
    # )

    for ch in [0, 1]:
        # print("- entire ADC Ch.{}".format(ch))
        # plot_graph_entire(
        #     ADC_FREQ,
        #     r_sample[ch],
        #     "C{}".format(ch + 1),
        #     "ADC waveform {} samples, {} Msps({} times accum.)".format(ADC_SAMPLES, ADC_FREQ, str(num_trig)),
        #     PLOT_DIR + str(num_trig) + "/bram_recv_{}.png".format(ch)
        # )

        print("- crop ADC Ch.{}".format(ch))
        plot_graph_crop(
            ADC_FREQ, r_sample[ch], "C{}".format(ch + 1),
            "ADC waveform {} samples{}, {} Msps({} times accum.)".format(
                ADC_SAMPLES, " (crop {}-{})".format(CROP_PLOT[0],
                                                    CROP_PLOT[1]), ADC_FREQ,
                str(num_trig)),
            PLOT_DIR + str(num_trig) + "/bram_recv_{}_crop.png".format(ch))

        # print("- FFT ADC Ch.{}".format(ch))
        # plot_graph_fft(
        #     ADC_FREQ,
        #     r_sample[ch],
        #     "C{}".format(ch + 1),
        #     "ADC FFT {} samples, {} Msps({} times accum.)".format(ADC_SAMPLES, ADC_FREQ, str(num_trig)),
        #     PLOT_DIR + str(num_trig) + "/bram_recv_{}_fft.png".format(ch)
        # )

    print("Done.")
    return
Exemplo n.º 7
0
def main():
    wgen = wavegen.WaveGen(logger=logger)
    nu = ndarrayutil.NdarrayUtil

    print("Generate waveform data.")
    wgen.set_parameter(num_sample=DAC_SAMPLES,
                       dac_freq=DAC_FREQ,
                       carrier_freq=20.0,
                       amplitude=-30000.0)
    w_data = wgen.sinwave()

    w_size = len(w_data)  # for 16-bit signed integer
    r_size = ADC_SAMPLES * 2  # for 16-bit signed integer

    mac_comp_coeff = np.array(
        [-1, 0, 1], dtype="<i4")  # MAC result comparation coefficients
    mac_comp_coeff_b = nu.real_to_bytes_32(mac_comp_coeff)

    dac_trig_params = np.array(
        [0, DAC_SAMPLES / 8] * 16,
        dtype="<i4")  # start of word:0, num of word:DAC_SAMPLES/8
    dac_trig_params_b = nu.real_to_bytes_32(dac_trig_params)

    with client.RftoolClient(logger=logger) as rft:
        print("Connect to RFTOOL Server.")
        rft.connect(ZCU111_IP_ADDR)
        rft.command.TermMode(0)

        print("Configure Bitstream.")
        config_bitstream(rft.command, BITSTREAM)

        print("Setup ADC.")
        for tile in [0, 1, 2, 3]:
            for block in [0, 1]:
                rft.command.SetMixerSettings(0, tile, block, 0.0, 0.0, 2, 2, 0,
                                             3, 0)
                rft.command.ResetNCOPhase(0, tile, block)
                rft.command.UpdateEvent(0, tile, block, 1)
            rft.command.SetupFIFO(0, tile, 0)
            for block in [0, 1]:
                rft.command.SetDither(tile, block,
                                      1 if ADC_FREQ > 3000. else 0)
                rft.command.SetDecimationFactor(tile, block, 1)
            rft.command.SetFabClkOutDiv(0, tile, 2)
            for block in [0, 1]:
                rft.command.IntrClr(0, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(0, tile, 1)

        print("Setup DAC.")
        for tile in [0, 1]:
            for block in [0, 1, 2, 3]:
                rft.command.SetMixerSettings(1, tile, block, 0.0, 0.0, 2, 1,
                                             16, 4, 0)
                rft.command.ResetNCOPhase(1, tile, block)
                rft.command.UpdateEvent(1, tile, block, 1)
            rft.command.SetupFIFO(1, tile, 0)
            for block in [0, 1, 2, 3]:
                rft.command.SetInterpolationFactor(tile, block, 1)
            rft.command.SetFabClkOutDiv(1, tile, 1)
            for block in [0, 1, 2, 3]:
                rft.command.IntrClr(1, tile, block, 0xFFFFFFFF)
            rft.command.SetupFIFO(1, tile, 1)

        print("Clear BlockRAM.")
        rft.command.ClearBRAM()

        # Write waveform data to DAC channel 0, 1 (Tile 1 Block 2, 3) BRAM region
        for ch in [0, 1]:
            print("Send waveform data to Feedback system Ch.{} DAC BlockRAM".
                  format(ch))
            rft.if_data.WriteDataToMemory(1, ch, w_size, w_data)

        # Write MAC result comparation coefficients for ADC channel 0 I part, 0 Q part, 1 I part, 1 Q part
        for ch in [0, 1, 2, 3]:
            print(
                "Send waveform data to Feedback system Ch.{} MAC result comparation coefficients."
                .format(ch))
            rft.if_data.WriteDataToMemory(4, ch, len(mac_comp_coeff_b),
                                          mac_comp_coeff_b)

        print(
            "Send waveform data to Feedback system Ch.{} DAC trigger parameters."
            .format(0))
        rft.if_data.WriteDataToMemory(5, 0, len(dac_trig_params_b),
                                      dac_trig_params_b)
        print(
            "Send waveform data to Feedback system Ch.{} DAC trigger parameters."
            .format(1))
        rft.if_data.WriteDataToMemory(5, 1, len(dac_trig_params_b),
                                      dac_trig_params_b)

        print("Setting trigger information.")
        rft.command.SetTriggerInfo(
            0, 0x03, ADC_SAMPLES, 0
        )  # enable ADC channel 0(Tile 0 Block 0), channel 1(Tile 0 Block 1)
        # to trigger DAC channel 0(Tile 1 Block 2), channel 1(Tile 1 Block 3)
        rft.command.SetTriggerLatency(
            0, 66)  # ADC trigger latency (approx. 0.22us = 66/300MHz)
        rft.command.SetMACConfig(0x00,
                                 0xFF)  # all ADC channels is 16-bit format
        # force trigger all DACs regardless of MAC overrange
        rft.command.SetTriggerCycle(32768, 1)  # trigger 32768 times

        print("Start trigger.")
        rft.command.StartTrigger()

        wait_trig_done(rft.command)

        time.sleep(1.)

        print("Setting trigger information.")
        rft.command.SetTriggerCycle(3, 1)  # trigger 3 times

        print("Start trigger.")
        rft.command.StartTrigger()

        wait_trig_done(rft.command)

        # Read I(Real) data from ADC Tile 0 Block 0, 1 RAM region
        r_data = []
        for ch in [0, 2]:
            print(
                "Receive waveform data from Feedback system Ch.{} ADC capture BlockRAM"
                .format(ch))
            r_data.append(rft.if_data.ReadDataFromMemory(0, ch, r_size))

        print("Check interrupt flags.")
        for ch in range(8):  # ADC
            check_intr_flags(rft.command, 0, ch)
        for ch in range(8):  # DAC
            check_intr_flags(rft.command, 1, ch)

    print("Processing sample data.")
    print("- DAC sample data")
    w_sample = nu.bytes_to_real(w_data)
    del w_data
    print("- ADC sample data")
    r_sample = [nu.bytes_to_real(r_data[ch]) for ch in [0, 1]]
    del r_data

    print("Generating graph image.")
    os.makedirs(PLOT_DIR, exist_ok=True)

    print("- DAC waveform")
    plot_graph(
        DAC_FREQ, w_sample, "C0",
        "DAC waveform {} samples, {} Msps".format(DAC_SAMPLES,
                                                  DAC_FREQ), "bram_send.png")

    for ch in range(2):
        print("- ADC waveform Ch.{}".format(ch))
        plot_graph(
            ADC_FREQ, r_sample[ch], "C{}".format(ch + 1),
            "ADC waveform {} samples, {} Msps".format(ADC_SAMPLES, ADC_FREQ),
            "bram_recv_{}.png".format(ch))

    print("Done.")
    return