Search code examples
visapyvisa

How to read measurements in a Keysight SMU when using an external trigger


I am using a Keysight B2901A SMU with an external trigger. Everything works on the tool but when I use PyVISA with SCPI commands I cannot find the way to read the measurements done when a trigger event arrives and a measurement (acquisition) is done.

Here the python command I am using:

import pyvisa as visa

rm = visa.ResourceManager()
instrument = rm.open_resource('USB0::0x0957::0x8B18::MY51142340::INSTR')

# Configure the source as voltage with compliance current
instrument.write(":SOUR:FUNC:MODE VOLT")  # Set source mode to Voltage
instrument.write(":SOUR:VOLT 2.5")        # Set source voltage to 2.5V
instrument.write(":SENS:CURR:PROT 5E-3")  # Set compliance current to 5mA

# Configure the trigger system
instrument.write(":ARM:ACQ:COUN INF")
instrument.write(":TRIG:ACQ:SOUR EXT9")
instrument.write(":TRIG:ACQ:DEL 0")

# Configure 4-wire measurement
instrument.write(":SENS:REM ON")         # Enable 4-wire sensing

# Set measurement parameters
instrument.write(":SENS:VOLT:RANG:AUTO OFF")  # Disable auto range for voltage
instrument.write(":SENS:VOLT:RANG 20")        # Set fixed voltage range to 20V
instrument.write(":SENS:CURR:RANG:AUTO OFF")  # Disable auto range for current
instrument.write(":SENS:CURR:RANG 1E-3")      # Set fixed current range to 1mA
instrument.write(":SENS:VOLT:APER 0.006")     # Set aperture time to 6ms

# Turn on the output
instrument.write(":OUTP ON")
instrument.write(":INIT:ACQ")

# Everything work up to here but:
# How to read the current measurements ?

I would need to know, using SCPI commands, how to read the measurement of current done for each trigger event.

I tried the ":MEAS" and ":FETC" and I expected to obtain the measurement but that didn't work. The :MEAS command returns bogus values and :FETC gives a TIMEOUT error.


Solution

  • When using external triggering, the :FETCh command is used to retrieve data already acquired, while :MEASure performs a real-time measurement, potentially ignoring the trigger setup.

    Here’s how to resolve the issue and correctly read measurements for each trigger event:

    Ensure Buffer Usage

    Use the internal buffer to store triggered measurements. The :FETCh command retrieves data from this buffer.

    Read the Measurement Properly

    After configuring the SMU, you need to use :TRAC:DATA to read data stored in the buffer.

    Here the SCPI command to use:

    :FORM:ELEM:SENS VOLT,CURR # request voltage and current measurement
    :TRAC:POIN 50             # Buffer size
    :TRAC:CLE                 # Clear buffer
    :TRAC:FEED SENS           # Feed triggered data to buffer
    :TRAC:FEED:CONT NEXT      # Start filling buffer on next trigger
    
    :OUTP ON                  # Start the operations
    :INIT:ACQ                 # Init measurement acquisition
    
    :TRAC:DATA? 1,10          # Fetch first 10 measurements from the buffer
    

    The setting above works to retrieve the last 10 measurements, saved in the measurement buffer. Other approach may be possible also using the FETCH command.