0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PythonおよびKeithley 2401 を用いた矩形波定電流の印加

Last updated at Posted at 2022-03-17

はじめに

PythonおよびKeithley 2401 を用いた矩形波定電圧の印加 の定電流版。
サンプルコードに手を加えることで、定電流印加に関する様々なプログラムを組める。

コード

サンプルコード
# coding: UTF-8
import openpyxl
import time
from pymeasure.instruments.keithley import Keithley2400
from datetime import datetime

### common settings ###
date = int(datetime.now().strftime("%Y%m%d"))-20000000 # 日付。2020年9月10日なら「200910」

keithley1 = Keithley2400("GPIB::24") 

def initial_settings():
    sheet.cell(row = 1, column = 1).value = 't1 (sec)'
    sheet.cell(row = 1, column = 2).value = 'V1(V)'
    sheet.cell(row = 1, column = 5).value = datetime.now()

    ### keithley settings ###
    keithley1.reset()    
    keithley1.disable_buffer()
    keithley1.use_front_terminals()
    keithley1.apply_current()
    keithley1.source_current = 0
    keithley1.enable_source()
    keithley1.measure_voltage()
    keithley1.compliance_voltage = 1 

def i_1(current):
    target_time = interval
    voltage_time = voltage_interval
    time_accuracy = 0.2

    rest_direction = time.time() - base_time - target_time
    for step in range(steps):
        keithley1.ramp_to_current(current,steps=3)
        while  rest_direction < 0 : # 電流の向き不変
            rest_voltage = time.time()-base_time - voltage_time
            while rest_voltage < 0 and rest_direction<0: # 電圧測定しない、かつ、電流の向き不変
                time.sleep(time_accuracy)
                rest_voltage = time.time()-base_time - voltage_time
                rest_direction = time.time() - base_time - target_time
            # 電圧測定する、かつ、電流の向き不変
            sheet.cell(row = int(voltage_time/voltage_interval)+1, column = 1).value = time.time()-base_time
            sheet.cell(row = int(voltage_time/voltage_interval)+1, column = 2).value = keithley1.voltage # 電圧記録の予定時間が来たらエクセルへ記録。
            voltage_time = voltage_time + voltage_interval # 電圧記録時間を再設定。
        #電流の向き変更
        target_time = target_time + interval
        rest_direction = time.time() - base_time - target_time

        #電流 0 にする(後の電流の向き反転のため、voltageに0を代入していない)
        keithley1.ramp_to_current(0,steps=3)
        while  rest_direction < 0 : # 電流の向き不変
            rest_voltage = time.time()-base_time - voltage_time
            while rest_voltage < 0 and rest_direction<0: # 電圧測定しない、かつ、電流の向き不変
                time.sleep(time_accuracy)
                rest_voltage = time.time()-base_time - voltage_time
                rest_direction = time.time() - base_time - target_time
            # 電圧測定する、かつ、電流の向き不変
            sheet.cell(row = int(voltage_time/voltage_interval)+1, column = 1).value = time.time()-base_time
            sheet.cell(row = int(voltage_time/voltage_interval)+1, column = 2).value = keithley1.voltage # 電圧記録の予定時間が来たらエクセルへ記録。
            voltage_time = voltage_time + voltage_interval # 電圧記録時間を再設定。
        #電流の向き変更
        current = current*(-1) # 電流の向き反転
        target_time = target_time + interval
        rest_direction = time.time() - base_time - target_time
    keithley1.shutdown()
    print('v_1_done.')

### conducting functions ###
if __name__ == "__main__":

    sample_name = "test"
    I1 = 0.1
    steps = 2
    interval = 2 #(sec)
    voltage_interval = 0.5 # 電圧測定間隔

    Username = '***' 
    path = "C:\\Users\\{0}\\Desktop\\".format(Username)
    filename = "{0}_{1}_{2}A_{3}sec_{4}.xlsx".format(date, sample_name, I1, interval, steps)

    print(datetime.now())
    book = openpyxl.Workbook() # エクセルファイルを作成
    sheet = book.worksheets[0] 
    initial_settings() #ソースメータの電源を入れる

    base_time = time.time()
    i_1(I1)
    book.save(path + filename)
    print('finished.')

内容は定電圧の際とほぼ同じ。
電流印加と電圧印加における initial_settings の違いを参照されたい。

結果

0.1A の電流を、2秒ごとに向きが入れ替わるように2サイクル印加した。
ワニ口同士を直接噛ませたため、低電圧。
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?