Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "--stages",
        type=str,
        nargs="*",
        default=["firmware", "ramp", "adc", "afe"],
        help="Select which setup stages to run.",
    )

    args = parser.parse_args()

    if "firmware" in args.stages:
        program_firmware()

    if "erase_nvm" in args.stages:
        erase_nvm()

    if "ramp" in args.stages:
        run_ramp_calibration()

    if "adc" in args.stages:
        run_adc_calibration()

    if "afe" in args.stages:
        run_afe_calibration()

    log.section("Soft-resetting")
    gem = gemini.Gemini()
    gem.soft_reset()
    log.success("Finished")
Exemplo n.º 2
0
def erase_nvm():
    log.section("Erasing NVM")
    gem = gemini.Gemini()
    gem.erase_lut()
    log.success("Erased ramp look-up-table.")
    gem.reset_settings()
    log.success("Erased user settings.")
    gem.close()
Exemplo n.º 3
0
def run_knob_calibration():
    log.section("Calibrating knob")

    knob_calibration.run(
        adc_resolution=2**12,
        adc_channel=1,
        invert=True,
        save=True,
    )
Exemplo n.º 4
0
def run_afe_calibration():
    log.section("Calibrating AFE")

    adc_calibration.run(
        num_calibration_points=50,
        sample_count=128,
        strategy="afe",
        save=True,
    )
Exemplo n.º 5
0
def run_adc_calibration():
    log.section("Calibrating ADC")

    adc_calibration.run(
        num_calibration_points=20,
        sample_count=128,
        strategy="adc",
        save=True,
    )
def run_adc_calibration():
    log.section("Calibrating ADC")
    # TODO: copy over Sol's code.

    adc_calibration.run(
        num_calibration_points=50,
        sample_count=128,
        strategy="adc",
        save=True,
    )
Exemplo n.º 7
0
def run_adc_calibration():
    log.section("Calibrating ADC")
    # TODO: copy over Sol's code.

    input("Connect Sol output A to Gemini CV A, press enter when ready.")

    adc_calibration.run(
        calibration_points=50,
        sample_count=128,
        adc_range=6.0,
        adc_resolution=2**12,
        adc_channel=0,
        invert=True,
        save=True,
    )
Exemplo n.º 8
0
def run(save):
    # Oscilloscope setup.
    log.info("Configuring oscilloscope...")
    resource_manager = visa.ResourceManager("@ivi")
    scope = oscilloscope.Oscilloscope(resource_manager)

    scope.reset()
    scope.enable_bandwidth_limit()
    scope.set_intensity(50, 100)

    # Enable both channels initially so that it's clear if the programming
    # board isn't connecting to the POGO pins.
    scope.set_time_division("10ms")
    scope.enable_channel("c1")
    scope.enable_channel("c2")
    scope.set_vertical_cursor("c1", 0, 3.3)
    scope.set_vertical_cursor("c2", 0, 3.3)
    scope.set_vertical_division("c1", "800mV")
    scope.set_vertical_division("c2", "800mV")
    scope.set_vertical_offset("c1", -1.65)
    scope.set_vertical_offset("c2", -1.65)

    # Gemini setup
    log.info("Connecting to Gemini...")
    gem = gemini.Gemini()
    gem.enter_calibration_mode()

    input(
        "Connect PROBE ONE to RAMP A\nConnect PROBE TWO to RAMP B\n> press enter to start."
    )

    # Calibrate both oscillators
    log.section("Calibrating Castor...", depth=2)
    castor_calibration = _calibrate_oscillator(gem, scope, 0)

    lowest_voltage = oscillators.charge_code_to_volts(
        min(castor_calibration.values()))
    highest_voltage = oscillators.charge_code_to_volts(
        max(castor_calibration.values()))
    log.success(
        f"\nCalibrated:\n- Lowest: {lowest_voltage:.2f}v\n- Highest: {highest_voltage:.2f}v\n"
    )

    log.section("Calibrating Pollux...", depth=2)
    pollux_calibration = _calibrate_oscillator(gem, scope, 1)

    lowest_voltage = oscillators.charge_code_to_volts(
        min(pollux_calibration.values()))
    highest_voltage = oscillators.charge_code_to_volts(
        max(pollux_calibration.values()))
    log.success(
        f"\nCalibrated:\n- Lowest: {lowest_voltage:.2f}v\n- Highest: {highest_voltage:.2f}v\n"
    )

    log.section("Saving calibration table...", depth=2)

    local_copy = pathlib.Path(
        "calibrations") / f"{gem.serial_number}.ramp.json"
    local_copy.parent.mkdir(parents=True, exist_ok=True)

    with local_copy.open("w") as fh:
        data = {
            "castor": castor_calibration,
            "pollux": pollux_calibration,
        }
        json.dump(data, fh)

    log.success(f"Saved local copy to {local_copy}")

    if save:
        output = tui.Updateable()
        bar = tui.Bar()

        log.info("Sending LUT values to device...")

        with output:
            for n, timer_period in enumerate(castor_calibration.keys()):
                progress = n / (len(castor_calibration.values()) - 1)
                bar.draw(
                    tui.Segment(
                        progress,
                        color=tui.gradient(start_color, end_color, progress),
                    ), )
                output.update()

                castor_code = castor_calibration[timer_period]
                pollux_code = pollux_calibration[timer_period]

                gem.write_lut_entry(n, timer_period, castor_code, pollux_code)

                log.debug(
                    f"Set LUT entry {n} to {timer_period=}, {castor_code=}, {pollux_code=}."
                )

        log.info("Committing LUT to NVM...")
        gem.write_lut()

        checksum = 0
        for dac_code in castor_calibration.values():
            checksum ^= dac_code

        log.success(f"Calibration table written, checksum: {checksum:04x}")

    else:
        log.warning("Dry run enabled, calibration table not saved to device.")

    gem.close()

    print("")
    log.success("Done!")
Exemplo n.º 9
0
def run_ramp_calibration():
    log.section("Calibrating ramps")
    ramp_calibration.run(save=True)
Exemplo n.º 10
0
def program_firmware():
    log.section("Programming firmware")

    fw_fetch.latest_bootloader(DEVICE_NAME)

    jlink.run(JLINK_DEVICE, JLINK_SCRIPT)