From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement SCPI commands for setting current sweeps with current source (Keithley 6221)

Hello,

I am trying to set up an AC current sweep from a minimum to maximum current value using a Keithley 6221 current supply. I found SCPI command in the instrument manual that specifies how to set up custom sweeps, but I am very new to LabView so I am not sure how I would implement these command. I have attached the VI in which I would like to implement the commands. I've also attached a Sub VI (labeled as K6221 Init Sine Wave and color coded blue) to which I would like to send these commands to. In short what the Sub VI does right now is that it puts out an AC current (a sine wave) at a particular frequency and amplitude with specific output configurations. I would like to send SCPI commands to the VI so as to set up an AC current sweep. 

 

Any suggestion/help is appreciated!

Download All
0 Kudos
Message 1 of 12
(5,911 Views)

Customs sweeps in the manual are for DC, not AC current.  There are no SCPI commands that I see that perform and AC current sweep.  If there please point to the section in that manual that explains them.  An AC current sweep is less common.  Are you measuring something during each step using another instrument?  Do you specify N periods of the signal before moving to the next amplitude?

 

I had a look at the attached code.  You seem to be mixing 2 different ages of Keithley 6221 drivers in your code.  The "blue" subvi being older and using GPIB commands.  There's no need to mix, all the commands are in the most recent LabVIEW driver for the Keithley 6221 - https://www.tek.com/specialty-instruments/6220-software/622x-native-labview-2009-driver-version-100-...

 

I suggest you stick to that one to make your code easier to follow.

 

Under \Examples\ you will find "KE6221 -- Wave Gen Example.vi", which stands for Waveform Generation and is what Keithley calls their AC signals (sine wave, square wave, arbitrary waveform) for this instrument.  The example shows you how to properly configure any AC signal, something like the VI you attached, for one specific current amplitude, frequency, and number of cycles. You'll note that the triggering and end conditions for waveforms is much more complicated than for simple DC current.

 

If you want to sweep current amplitude, with all other conditions of the waveform held constant,  then you would use a For or While loop to step through each amplitude from start to end.  You would use the "KE6221 -- Set Wave Amplitude.vi" to change the amplitude in each loop iteration.  You still need to wait for the waveform to be completed on each loop before going to the next iteration.

 

Try that and post code if you get stuck.

Craig

0 Kudos
Message 2 of 12
(5,867 Views)

I actually do want to sweep the amplitudes of the AC current set at a particular frequency. If you notice, in my first attached VI named TestforCurrentSweepKeithley622x.vi I do have a for loop (with an indexing tunnel), that is supposed to give me the voltage for each element of the "Current Sweep" array. But when I want to test this out using a 50 Ohm resistor, it's throwing an error, which says that I need to configure the sweep. In the manual (section 4-9) there are SCPI commands for remotely configuring the sweep. But i was hoping if I could incorporate one of the Keithley drivers that are already there to perform a sweep. I was going through the block diagram of an example VI provided by Keithley that performs DC current sweeps "Execute Current Sweep Example.VI" (attached) and I came up with a couple of things I tried/want to try

Attempt at a solution:

(1) Two Sub VI's "Set Trig Params.vi" and "Arm Init Sweep.vi" I think can be used to configure the sweep. I know they should be outside the loop, but can't think of a way to incorporate these to the for loop, which contains the "Init Sine Wave" VI
(2) There's another Sub VI (Set Lin Log Sweep Params.vi, attached) I thought might be useful. I was wondering whether altering the VI by putting additional commands like "SOUR:WAVE: SIN FUNC" and "SOUR:WAVE:FREQ" to the "format string" junction of the "format into string" function would work if I want to tell the VI to sweep amplitudes of AC current. If so, then I am not sure about the correct syntax for making these specifications. 

All the VI's including the manual are attached for your convenience.

0 Kudos
Message 3 of 12
(5,858 Views)

I looked at the manual, and I looked at your code. There are no magic SCPI commands that simply execute a AC current sweep.   To do so you must do more setup with regards to trigger and status registers.  But it doesn't sound like you downloaded the driver I recommended or looked at my suggestions to implement your solution.

 

All your code does is reset the amplitude of the AC sine wave in a loop.  It never sets the instrument to actually trigger the output of the waveform, or wait for N periods of the waveform to be output and then report its finished. 

 

Perhaps you should look at the examples I mentioned that do all those things. Then consider what portions of the example code needs to be in the loop, and which outside, in order to step amplitude. 

 

Best of luck.

0 Kudos
Message 4 of 12
(5,842 Views)

I looked at the "Wave Gen Example.vi" and tried to implement parts of it. Looking at the block diagram, I don't exactly see where they are triggering the output, maybe it's the initialize function? I also don't understand how the "timer" function is setting the duration for each iteration. What are your thoughts?

0 Kudos
Message 5 of 12
(5,829 Views)

Did the example run as-is?  If I have time later today I'll try to draw you what I explained.


Craig

0 Kudos
Message 6 of 12
(5,819 Views)

Here's some code you might try.k6221_AC_current_sweep.png

 

0 Kudos
Message 7 of 12
(5,811 Views)

Thanks, I will take a look at it and test to see if that works. I had the nested for loops, but wasn't sure how to change/incorporate the error handling sequence at the very end of the Wave Gen Example.vi, but I will definitely try this one out and will let you know if something isn't running properly.

0 Kudos
Message 8 of 12
(5,762 Views)

There are a couple of problems:
(1) I ran the Wave Gen Example.vi by itself. Keithley sends a message saying "WAVE FORM ARMED Press trig to start". Maybe that just means I need to connect it to a lock-in to read out the voltage?

(2) I tried the code you suggested. I am getting a error when I run it; Keithley 6221 displays "ERROR:ID CODE = -222 Parameter data out of range". When I highlight the execution, it shows that the error happens inside the for-loop after the sine wave amplitude has been set. I've attached a screen shot of the front panel.

Also looking at the code, I noticed if the functions outside the for-loop, "set sine wave params" is set to false; shouldn't they be inside the for-loop so they get updated at each iteration? Otherwise how are we setting the AC frequency?

P.S. Just to be clear, the Keithley is attached to a 50 Ohm resistor.

0 Kudos
Message 9 of 12
(5,750 Views)

@humayusuf93 wrote:

There are a couple of problems:
(1) I ran the Wave Gen Example.vi by itself. Keithley sends a message saying "WAVE FORM ARMED Press trig to start". Maybe that just means I need to connect it to a lock-in to read out the voltage?

No, you need to send a trigger command to the K6221. But atleast we know you are properly communicating with the instrument.

(2) I tried the code you suggested. I am getting a error when I run it; Keithley 6221 displays "ERROR:ID CODE = -222 Parameter data out of range". When I highlight the execution, it shows that the error happens inside the for-loop after the sine wave amplitude has been set. I've attached a screen shot of the front panel.

Also looking at the code, I noticed if the functions outside the for-loop, "set sine wave params" is set to false; shouldn't they be inside the for-loop so they get updated at each iteration? Otherwise how are we setting the AC frequency?


 

>>  "set sine wave params" is set to false; 

No, the parameter "Read Back Values" of the VI with a label "set sine wave params" is set to False.  This means the K6221 doesn't read back what the paramters are set to after you set them.  Might be a good idea to set True but has no effect on errors or functioning of the code.  

 

A Keithley -221 error means that one of the parameters you are trying to set is either too BIG or too small.  Perhaps its the 0mA initial amplitude for the sine wave?  Try setting 10uA or the minimum ACI the instrument allows, the manual will have that info. 

 

>> Otherwise how are we setting the AC frequency?

You only need to set the AC frequency once, before the for loop, and just vary the ACI in the loop.

 

I don't have a K6221 to test this on, you're going to have to do some troubleshooting and debugging.  I suggest you watch the entire program executre with debugging on.  Watch the settings change on the K6221 as the commands are sent and see exactly what value the K6221 errors on.  Then try to set that manually, when doing so it will usually tell you what the upper/lower limits of the value are.  Then correct the value in the code.

 

Let me know how that goes.

 

0 Kudos
Message 10 of 12
(5,726 Views)