def loop(self):
        time_step = 1 #seconds
        low_count = 0
        self.display_charge_pane()
        self.startDatalogging()
        uMon = getU(channel)
        iMon = getI(channel)

        total_amp_seconds = 0
        self.total_amp_hour = 0
        self.total_seconds = 0

        try:
            self.set_charge_param()

            action = ''
            while True:
                if action == 'stop':
                   break
                elif action == 'view_datalog':
                    scpi('DISP:WINDOW:DLOG')
                elif action == 'close' or action == 0:
                    # TODO this won't actually exit...
                    break;

                uMon = getU(channel)
                iMon = getI(channel)

                amp_seconds = iMon * time_step
                total_amp_seconds += amp_seconds
                self.total_amp_hour = total_amp_seconds/3600

                dlogTraceData(uMon, iMon, self.total_amp_hour)

                scpi('DISP:DIAL:DATA "Vmeas", FLOAT, VOLT, ' + str(uMon))
                scpi('DISP:DIAL:DATA "Imeas", FLOAT, AMPER, ' + str(iMon))
                scpi('DISP:DIAL:DATA "elapsed_amp_hour", FLOAT, AMPER, ' + str(self.total_amp_hour))
                scpi('DISP:DIAL:DATA "total_seconds", FLOAT, SECOnd, ' + str(self.total_seconds))

                if iMon < termination_current:
                    low_count += 1
                    if low_count >=3:
                        break
                else:
                    low_count = 0

                action = scpi('DISP:DIALog:ACTIon? ' + str(time_step))
                self.total_seconds += time_step

        finally:
            scpi('OUTP 0')
            scpi('ABOR:DLOG')

        self.done_loop()
Ejemplo n.º 2
0
def discharge_cap():
    global channel
    setU(channel, 0.0)
    setI(channel, 0.1)  # Must be >= 10mA otherwise Downprogrammer is off.
    scpi("DISP:WINDOW:TEXT \"Discharging...\"")
    scpi("OUTP 1")
    sleep_ms(1000)
    while getU(channel) > 0.5:
        sleep_ms(100)
    scpi("DISP:WINDOW:TEXT:CLEAR")
    setI(channel, 0.1)
    scpi("OUTP 0")
Ejemplo n.º 3
0
def discharge_cap():
    global channel
    setU(channel, 0.0)
    setI(channel, 0.1)  # Must be >= 10mA otherwise Downprogrammer is off.
    ovp = scpi("SOUR1:VOLT:PROT:STAT?")
    if ovp:
        scpi("SOUR1:VOLT:PROT:STAT OFF")
    scpi("DISP:WINDOW:TEXT \"Discharging...\"")
    scpi("OUTP 1")
    sleep_ms(1000)
    while getU(channel) > 0.5:
        sleep_ms(100)
    scpi("DISP:WINDOW:TEXT:CLEAR")
    setI(channel, 0.1)
    scpi("OUTP 0")
    if ovp:
        scpi("SOUR1:VOLT:PROT:STAT ON")
Ejemplo n.º 4
0
def start_reform():
    global max_cap_volt, charge_current, reform_time, have_data, channel

    try:
        scpi("SENS:CURR:RANG BEST")
        scpi("VOLT 0")
        scpi("CURR 0")
        scpi("CURR " + str(charge_current))

        # Define datalogging
        scpi("SENS:DLOG:CLE")
        scpi('SENS:DLOG:TRAC:REM " Icharge = ' + str(charge_current) + '"')
        scpi("SENS:DLOG:TRAC:X:UNIT SECOND")
        scpi("SENS:DLOG:TRAC:X:STEP " + str(TIME_STEP))
        scpi("SENS:DLOG:TRAC:X:RANG:MAX " + str(reform_time))
        scpi('SENS:DLOG:TRAC:X:LABel "Time"')
        scpi("SENS:DLOG:TRAC:Y1:UNIT VOLT")
        scpi("SENS:DLOG:TRAC:Y1:RANG:MAX " + str(cap_max_volt * 1.1))
        scpi("SENS:DLOG:TRAC:Y1:RANG:MIN 0")
        scpi('SENS:DLOG:TRAC:Y1:LABel "Vmon"')
        scpi("SENS:DLOG:TRAC:Y2:UNIT AMPER")
        scpi("SENS:DLOG:TRAC:Y2:RANG:MAX " + str(charge_current * 2))
        scpi("SENS:DLOG:TRAC:Y2:RANG:MIN 0")
        scpi('SENS:DLOG:TRAC:Y2:LABel "Imon"')
        scpi('INIT:DLOG:TRACE "/Recordings/ReformCap.dlog"')

        scpi("OUTP 1")
        have_data = True

        starttime = ticks_ms()
        t = starttime
        tdiff = 0.0  # Allocate outside loop for speed.
        action = ""

        # This is the measurement loop.
        ###############################
        while True:
            scpi('SYST:DIG:OUTP:DATA 4,1')  # For timing analysis
            # Time critical stuff first
            ###########################
            # Measure as soon and fast as possible to hit it as close as possible to the set time (after delay)
            uMon = getU(channel)
            iMon = getI(channel)

            # Remember timestamp of the beginning of this iteration
            nowtime = ticks_ms()

            # Set (new) value
            uSet = STEP1 * cap_max_volt

            if nowtime > (starttime + 0.6666 * reform_time * 1000):
                uSet = STEP3 * cap_max_volt
            elif nowtime > (starttime + 0.3333 * reform_time * 1000):
                uSet = STEP2 * cap_max_volt
            setU(channel, uSet)

            # Not time critical
            ###################
            try:
                dlogTraceData(uMon, iMon)
            except:
                break

            # Done with loop?
            if nowtime > (starttime + reform_time * 1000):
                scpi('SYST:DIG:OUTP:DATA 4,0')
                break

            # Finally do the slow GUI stuff.
            ################################
            # Process the action read during the delay
            if action == "view_dlog":
                scpi("DISP:WINDOW:DLOG")

            if action == "stop_reform":
                break

            # Update progress bar.
            scpi("DISP:DIAL:DATA \"reform_progress\", INT, " +
                 str(int((nowtime - starttime) / (reform_time * 10))))
            # Update V and I data
            scpi("DISP:DIAL:DATA \"Vmon\", FLOAT, VOLT, " + str(uMon))
            scpi("DISP:DIAL:DATA \"Imon\", FLOAT, AMPER, " + str(iMon))

            # Loop delay
            ############
            # Set the next time we want the loop to execute
            t = ticks_add(t, int(TIME_STEP * 1000))
            scpi('SYST:DIG:OUTP:DATA 4,0')
            # Everything after this line is time sensitive, it is nog compensated in the timing calculation
            # It will cause a drift in sampling time.
            # Calculate how long until next interval, wait for this time in dialog wait.
            #sleep_ms(ticks_diff(t,ticks_ms()))
            action = scpi("DISP:DIALOG:ACTION? " +
                          str(max(1, ticks_diff(t, ticks_ms()))) + 'ms')
            # We don't process the action here but in the next iteration to keep timing
            # of measurements as jitter free as possible

    finally:
        scpi("OUTP 0")
        # Stop recording.
        scpi('ABOR:DLOG')
        discharge_cap()