Real time data collect and plot with keithley 2636

7 vues (au cours des 30 derniers jours)
mk
mk le 14 Jan 2024
Commenté : mk le 21 Jan 2024
I am trying to obtain a real time plot of Voltage pulses acquired from a Keithley 2636 Voltage Source. Now, I can only wait until keithley finishes running the script and then acquire data with matlab. I don't know how to collect data while keithley is running (during loop). Below is my script of running program and collecting data.
running program:
vstep=(vMAX-vMIN)/steps;
fprintf(vg, 'vMIN = %f',vMIN);
fprintf(vg, 'vMAX = %f',vMAX);
fprintf(vg, 'vstep = %f',vstep);
fprintf(vg, 'numPoints = %f',steps +1);
fprintf(vg, 'VG = %f',vGate);
xx=max(abs([vMAX vMIN]));
fprintf(vg,'smua.source.rangev= %f', xx);
fprintf(vg,'smub.source.rangev= %f', vGate)
fprintf(vg, 'smua.source.levelv =0');
fprintf(vg, 'smub.source.levelv =0');
fprintf(vg,'loadscript vd_id')
fprintf(vg,'smub.source.output = smub.OUTPUT_ON');
fprintf(vg,'smua.source.output = smua.OUTPUT_ON');
fprintf(vg,'for j=1,2 do');
fprintf(vg,'smub.source.levelv = VG/2*j');
fprintf(vg,'delay(2E-5)')
fprintf(vg, 'end');
fprintf(vg,'smua.measure.autozero = smua.AUTOZERO_AUTO');
fprintf(vg,'smub.measure.autozero = smub.AUTOZERO_AUTO');
fprintf(vg, 'for j=1,2*numPoints-1 do');
fprintf(vg, 'if j<(numPoints)/2 then');
fprintf(vg, 'smua.source.levelv = (vMIN+vMAX)/2 - (j-1)*vstep');
fprintf(vg, 'elseif j>3*(numPoints-1)/2 then');
fprintf(vg, 'smua.source.levelv = (vMIN+vMAX)/2 + (2*numPoints-1-j)*vstep');
fprintf(vg, 'else');
fprintf(vg, 'smua.source.levelv = vMIN + (j-(numPoints-1)/2-1)*vstep');
fprintf(vg, 'end');
fprintf(vg, 'smua.measure.iv(ibuffer,vbuffer)');
fprintf(vg, 'smub.measure.iv(igbuffer,vgbuffer)');
fprintf(vg, 'end');
fprintf(vg,'for j=1,2 do');
fprintf(vg,'smub.source.levelv = VG-VG/2*j');
fprintf(vg,'delay(2E-5)')
fprintf(vg, 'end');
fprintf(vg,'smub.source.output = smub.OUTPUT_OFF');
fprintf(vg,'smua.source.output = smua.OUTPUT_OFF');
fprintf(vg, 'endscript');
collecting data:
fprintf(vg,'*OPC?');
bLoop = 1;
while (bLoop == 1)
status = fscanf(vg, '%d');
if (status == 1)
bLoop = 0;
end
end;
% read I
temp='';
fprintf(vg, 'printbuffer(%d, %d, ibuffer.readings)',[1 2*steps+1])
while (length(temp) == 0)
temp = fscanf(vg, '%s');
end;
temp = regexprep(temp, ',', ' ');
i_list(:,1) = sscanf(temp, '%f');

Réponse acceptée

Hassaan
Hassaan le 14 Jan 2024
Modifié(e) : Hassaan le 14 Jan 2024
Real-time data acquisition and plotting while a Keithley instrument is running a script can be challenging, particularly because the instrument is busy executing its script and may not be able to communicate continuously with MATLAB. However, there are a few strategies you can use to approach this problem:
1. Polling Method
The approach you're currently using seems to be a polling method where you wait for the Keithley script to finish before reading the data. This method won't allow real-time plotting.
2. Data Streaming
If the Keithley model supports it, a better approach might be to stream data from the Keithley to MATLAB in real-time. This would involve modifying the Keithley script to send data back at each step of the loop, rather than storing it all and sending it at the end. However, this approach depends heavily on the capabilities of the Keithley model you are using.
3. Smaller Batches
Another approach is to break your Keithley script into smaller parts and acquire data in batches. After running each part of the script, pause the script, transfer the data to MATLAB, plot it, and then proceed to the next part. This won't be real-time in the strictest sense but will allow you to monitor the data more frequently.
4. External Triggering
If Keithley supports external triggering for data acquisition, you could set it up to acquire and send data upon each trigger. MATLAB would send a trigger, wait for the data, plot it, and then send the next trigger.
% ... (initialization)
fprintf(vg, 'loadscript vd_id');
% ... (other setup commands)
fprintf(vg, 'for j=1,2*numPoints-1 do');
fprintf(vg, ' ...'); % Your loop operations
fprintf(vg, ' smua.measure.iv(ibuffer,vbuffer)');
fprintf(vg, ' smub.measure.iv(igbuffer,vgbuffer)');
fprintf(vg, ' print(ibuffer.readings)'); % Print readings to be read by MATLAB
fprintf(vg, ' print(vbuffer.readings)');
fprintf(vg, 'end');
fprintf(vg, 'endscript');
% ... (rest of the script)
In MATLAB, after sending the script to Keithley, you would read the data continuously within the loop:
```matlab
fprintf(vg,'*OPC?');
bLoop = 1;
while bLoop
temp = fscanf(vg, '%s');
if ~isempty(temp)
% Process and plot the data
% temp will contain the readings from ibuffer and vbuffer
% Convert the string to numerical data and plot
end
end
Important Considerations:
  • Latency and Buffering: There might be a delay between sending data from Keithley and receiving it in MATLAB. Ensure your MATLAB code handles this properly.
  • Data Format: Ensure the data sent by Keithley is in a format that MATLAB can easily interpret.
  • Error Handling: Include error handling in your MATLAB code to deal with communication errors or unexpected data formats.
  • Instrument Manual: Refer to your Keithley instrument's manual for specific commands and capabilities related to real-time data transfer.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  3 commentaires
Hassaan
Hassaan le 15 Jan 2024
You need to change and adjust as per your need
mk
mk le 21 Jan 2024
Thank you so much. I have finished this program with your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by