Knowledge Base

MATLAB을 이용한 계측기 프로그래밍

이 기술 자료 문서에서는 MATLAB을 사용하여 Magna-Power 프로그래머블 전원 제품을 프로그래밍하는 방법을 소개합니다. MATLAB은 수치 계산, 시각화 및 프로그래밍의 편의성으로 널리 알려진 고급 프로그래밍 환경입니다. MATLAB의 강력한 툴박스와 함수들은 프로그래머블 계측기의 제어, 측정 및 데이터 플로팅에 탁월한 선택입니다. 또한, Magna-Power는 SCPI(Standard Commands for Programmable Instrumentation)를 폭넓게 지원하여 직관적이고 간편한 명령을 통해 MATLAB과의 원활한 통합을 보장합니다.

Magna-Power 제품은 RS-232, TCP/IP 이더넷, USB, RS-485, IEEE-488 GPIB를 포함한 다양한 통신 인터페이스를 지원합니다. 인터페이스가 다르더라도 SCPI 명령은 특정 제품 시리즈에 대해 동일하게 유지되며, 이는 해당 제품 시리즈의 사용자 매뉴얼에 문서화되어 있습니다. MATLAB 프로그램을 작성할 때 인터페이스 간 유일한 차이점은 장치 연결 설정뿐입니다.

통신 인터페이스

USB, 시리얼 또는 RS-485 연결

USB, 시리얼 또는 RS-485 연결의 경우, MATLAB은 내장 serialport 함수를 사용하여 계측기에 시리얼 연결을 생성합니다:

conn = serialport('COM4', 115200);

xGen 제품의 시리얼 보레이트는 115200이며, xGen이 아닌 제품의 경우 19200입니다. 포트 위치는 운영 체제에 의해 정의됩니다. Windows에서는 장치 관리자에서 이 포트를 확인할 수 있습니다.

시리얼 연결을 통한 후속 명령 송수신은 다음과 같이 수행됩니다:

writeline(conn, '*IDN?');
response = readline(conn);
disp(response);

TCP/IP 이더넷 연결

TCP/IP 이더넷 연결의 경우, MATLAB은 tcpclient 함수를 사용합니다:

t = tcpclient('192.168.0.86', 50505);

TCP/IP 이더넷 연결을 통한 후속 명령 송수신은 다음과 같이 수행됩니다:

writeline(t, '*IDN?');
response = read(t);
disp(char(response));

IEEE-488 GPIB 연결

IEEE-488 GPIB 연결의 경우, MATLAB은 Instrument Control Toolbox와 함께 gpib 함수를 사용합니다:

g = gpib('NI', 0, 12);
fopen(g);

IEEE-488 GPIB 연결을 통한 후속 명령 송수신은 다음과 같이 수행됩니다:

fprintf(g, '*IDN?');
response = fscanf(g);
disp(response);

심화 예제

다음 예제들은 xGen MagnaDC 전원 공급 장치를 사용하는 보다 상세한 MATLAB 프로그램을 제공합니다. xGen이 아닌 MagnaDC 프로그래머블 DC 전원 공급 장치를 MATLAB에서 프로그래밍하는 방법은 거의 동일하며, 해당 제품 시리즈의 사용자 매뉴얼에 문서화된 SCPI 명령의 미세한 차이만 있습니다.

예제 1: 기본 TCP/IP 이더넷 제어

이 기본 예제는 TCP/IP 이더넷 연결을 생성하고, 초기화 명령을 전송한 후, DC 출력을 활성화하고, 전류 레벨을 5 A로 올린 다음, 20초간 대기한 후 종료합니다.

% Create a TCP/IP connection to the instrument
t = tcpclient('192.168.0.86', 50505);

% Send SCPI command requesting the product to identify itself
writeline(t, '*IDN?');
% Receive the product's response and display it in the command window
response = read(t);
disp(char(response));

% Configure the MagnaDC for local control
writeline(t, 'CONF:SOUR 0');
% Set the DC output current to 0 A before enabling DC output
writeline(t, 'CURR 0');
% Enable the MagnaDC power supply output
writeline(t, 'OUTP:START');
% Set the DC output current to 5 A
writeline(t, 'CURR 5');

% Wait for 20 seconds
pause(20);

% Disable the DC output
writeline(t, 'OUTP:STOP');

% Clear the TCP/IP connection
clear t;

예제 2: 전류 설정값을 사용한 시리얼 연결

이 예제는 제품에 대한 시리얼 연결을 생성하고, 연결된 제품을 식별한 후, 각 전류 레벨 사이에 20초 간격을 두고 일련의 전류 명령을 전송합니다. 이 유형의 프로그램은 전압, 전력 및 저항 값을 순환하도록 확장할 수 있습니다.

% Create a serial connection object with default baud rate for MagnaLOADs
conn = serialport('COM4', 115200);

% Send SCPI command requesting the product to identify itself
writeline(conn, '*IDN?');
% Receive the product's response and display it in the command window
response = readline(conn);
disp(response);

% Create an array of current set points
currSetPoints = [50, 100, 150, 250];

% Configure the MagnaDC power supply for local control
writeline(conn, 'CONF:SOUR 0');
% Enable the MagnaDC power supply output
writeline(conn, 'OUTP:START');

% Loop through each current set point
for currSetpoint = currSetPoints
    fprintf('Setting Current to %d A\n', currSetpoint);
    writeline(conn, sprintf('CURR %d', currSetpoint));
    pause(20);
end

% Disable the MagnaDC power supply output
writeline(conn, 'OUTP:STOP');

% Clear the serial connection
clear conn;

예제 3: 배터리 방전 및 데이터 플로팅

이 예제에서는 xGen MagnaDC 전원 공급 장치를 프로그래밍하여 쉼표로 구분된 값(.csv) 파일에서 읽어온 설정값과 시간을 사용하여 배터리를 방전하고, 제품의 고정밀 측정 명령을 사용하여 DC 입력을 측정한 후, 측정 데이터 대 시간 플롯을 제공합니다. 이 프로그램은 측정 데이터, 플롯 및 기타 계측기의 정보를 통합하여 PDF 테스트 보고서를 생성하도록 추가 확장할 수 있습니다.

% Import data from CSV file
% The CSV file should have two columns:
% Column 1: Current set point in amperes
% Column 2: Time in seconds
data = readmatrix('example_profile.csv');

% Create a serial connection object with default baud rate for xGen products
conn = serialport('COM8', 115200);

% Configure the MagnaDC for local control
writeline(conn, 'CONF:SOUR 0');
% Enable the MagnaDC power supply output
writeline(conn, 'OUTP:START');

% Initialize arrays to store measurements
currents = [];
voltages = [];
times = [];
testStartTime = tic;

% Loop through each set point and duration
for i = 1:size(data, 1)
    currSetpoint = data(i, 1);
    duration = data(i, 2);
    
    % Set the current set point
    writeline(conn, sprintf('CURR %f', currSetpoint));
    
    % Record data for the specified duration
    stopTime = toc(testStartTime) + duration;
    while toc(testStartTime) < stopTime
        % Measure all DC output variables
        writeline(conn, 'MEAS:ALL?');
        response = readline(conn);
        measurements = strsplit(response, ',');
        
        % Store measurements
        currents(end+1) = str2double(measurements{1});
        voltages(end+1) = str2double(measurements{2});
        times(end+1) = toc(testStartTime);
        
        pause(0.5);
    end
end

% Disable the MagnaDC power supply output
writeline(conn, 'OUTP:STOP');

% Clear the serial connection
clear conn;

% Plot Current vs. Time
subplot(2,1,1);
plot(times, currents, 'r--');
ylabel('Output Current (A)');
title('I-V Profile');

% Plot Voltage vs. Time
subplot(2,1,2);
plot(times, voltages, 'b--');
xlabel('Time (s)');
ylabel('Output Voltage (V)');

% Display the plots
figure(gcf);

참고: CSV 파일 example_profile.csv가 올바른 형식으로 작성되어 있고 MATLAB 작업 디렉토리에 위치해 있는지 확인하십시오. 첫 번째 행은 헤더여야 하며, 데이터는 두 번째 행부터 시작해야 합니다.

결론

MATLAB은 Magna-Power 프로그래머블 전원 제품을 제어하기 위한 강력한 환경을 제공합니다. 시리얼, TCP/IP 및 GPIB 통신을 위한 내장 함수와 광범위한 플로팅 기능을 통해 MATLAB은 테스트 자동화, 데이터 수집 및 결과 시각화 프로세스를 간소화합니다. SCPI 명령과 MATLAB의 기능을 활용하여 사용자는 특정 애플리케이션에 맞춤화된 정교한 제어 프로그램을 개발할 수 있습니다.

상세한 SCPI 명령 세트 및 추가 사용자 정의에 대해서는 사용 중인 특정 Magna-Power 제품 시리즈의 사용자 매뉴얼을 참조하십시오.

Originally published 10월 29, 2024

Stay connected and informed.

Subscribe to receive emails—no more than once per month—with new technical articles, product releases and factory updates from Magna-Power.

Have any questions or feedback?
We'd love to hear from you.
Contact us