close all
clear all


port = "COM5";
I_offset = 0.5;      
I_amp    = 0.5;      
T        = 10;      
dt       = 0.05;   
duration = 30;    
Vmin = 2.5;
sp = serialport(port, 4800);
BK_EnableRemote(sp,1)
BK_SetCCMode(sp)
BK_LoadOn(sp,1)
BK_SetMinVoltageForBattTest(sp, Vmin)
t0 = tic;

while toc(t0) < duration
    t = toc(t0);   
    I = I_offset + I_amp*cos(2*pi*t/T);
BK_SetCurrent(sp,I)
 [Vmon, ~, ~] = BK_ReadVandI(sp);   
  
    fprintf("t = %.3f seconds\n", t);
   
if Vmon <= Vmin
    fprintf("Voltage cutoff");
    break
end
pause(dt);
end
fprintf("test complete");

