0
\$\begingroup\$

I need to automate the measurement of delay between two signals using the oscilloscope. I am using MSO4104 from Tektronix. I programmed the oscilloscope for delay measurement, but I am not getting the output.

The measurement conditions are given below:

Signal 1

High-90%,Mid,20% Low 10% and EDGE-Falling

Signal-2 Low 10% ,Mid 20%, High 90 EDGE Raising

Please see my code below. After executing this code output is not coming.

Can you please tell me where I went wrong?

import pyvisa
from time import *
rm = pyvisa.ResourceManager()
rm.list_resources()
#print(rm.list_resources())
scope = rm.open_resource('USB0::0x0699::0x0401::C002760::0::INSTR')
IDN = scope.query('*IDN?')
print ('Successfully connected to: ', IDN)
scope.write("*RST")
scope.write('SELECT:CH1 ON')
scope.write('SELECT:CH2 ON')
scope.write("AUTOset EXECute")
sleep(5)
scope.write("MEASUrement:REFLevel:METHod PERCent")
scope.write("MEASUREMENT:IMMED:DELAY:DIRECTION FORWARDS")
#For Channel_1
scope.write("MEASUrement:IMMed:SOURCE CH1")
scope.write("MEASUrement:IMMed:DELay:EDGE1 FALL")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:HIGH 90")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:MID 20")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:LOW 10")
#For Channel_2
scope.write("MEASUrement:IMMed:SOURCE CH2")
scope.write("MEASUrement:IMMed:DELay:EDGE2 RISE")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:LOW 3")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:MID 20")
scope.write("MEASUREMENT:REFLEVEL:PERCENT:HIGH 80")
sleep(10)
scope.write("MEASure:DELay CH1,CH2")
sleep(10)
Delay_1_2 = scope.query('MEASure:DELay? CHANNEL1,CHANNEL2')
print('Delay is:',Delay_1_2)
scope.close()
rm.close()
\$\endgroup\$
2
  • \$\begingroup\$ Have you tried if your delay can be succesfully measured without PC connected? I mean, if there is measurement which cannot be performed on oscilloscope by itself, it cannot be performed with the script. It caught me a couple of times. \$\endgroup\$ – smajli Feb 19 at 13:16
  • \$\begingroup\$ I am able to measure successfully with the oscilloscope,without using any script \$\endgroup\$ – HARI T O Feb 19 at 16:34
1
\$\begingroup\$

Below is a script to measure delay in Ch1 - Ch2 raising edges with MDO4042 Tek scope.
I had to improvise to make delays between Ch1 and 2, so please tune the script to your needs.

#Script to measure delay with MDO4024C Mixed Domain Oscilloscope
import time
import pyvisa as visa
rm = visa.ResourceManager()
print('Available devices: ')
print(rm.list_resources())  #to check instruments connected
try:
    scope = rm.open_resource('USB0::0x0699::0x0456::C000197::INSTR', send_end = True)  #adding scope
    print('Device open: ', scope)
except:
    print('Opening device problem')

IDN = scope.query('*IDN?')
print ('Successfully connected to: ', IDN)

#---SCOPE SETUP---
scope.write("*RST")
scope.write('SELECT:CH1 ON')
print('Select Ch1: OK')

scope.write('SELECT:CH2 ON')
print('Select Ch2: OK')

scope.write('AUTOset EXECute')
print('Autoset: OK')

scope.write('HORizontal:SCAle 4E-3') #set horizontal scale to 4ms
print('Horizontal scale set to 4ms')

scope.write('TRIGger:A SETLevel') #set trigger level to 50% of range
print('Trigger to 50% of the range')

scope.write('MEASUrement:IMMed:DELay:DIRection FORWARDS')
print('Measurement type sent: OK')

scope.write('MEASure:DELay CH1,CH2')
print('Command sent: MEASure:DELay CH1,CH2')


scope.write('MEASurement:IMMed:TYPe DELay')
time.sleep(1)

#--checks to confirm---
#scope.write('MEASurement:IMMed:TYPe?')
#time.sleep(0.5)
#print(scope.read())
#-------
#time.sleep(2)
#scope.write('MEASurement:IMMed:DELay?')
#time.sleep(0.5)
#print(scope.read())
#-----------
#time.sleep(2)
#scope.write('MEASurement:IMMed:UNIts?')
#time.sleep(0.5)
#print(scope.read())
#-------

while True:
    scope.write('MEASurement:IMMed:VALue?')
    time.sleep(0.5)
    print(scope.read())

Commented part was used to confirm type of measurement, settings and units.
Below is a picture of returned values: Output

Two first received values shows some problems (scope manual say this specific value is normally associated with error), anyway later values are correct.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you I will Implement this and will update you \$\endgroup\$ – HARI T O Feb 24 at 13:54
  • \$\begingroup\$ scope.write('MEASUrement:IMMed:DELay:DIRection FORWARDS') print('Measurement type sent: OK') scope.write('MEASure:DELay CH1,CH2') scope.write("MEASUrement:IMMed:DELay:EDGE1 FALL") scope.write("MEASUREMENT:REFLEVEL:PERCENT:HIGH 90") scope.write("MEASUREMENT:REFLEVEL:PERCENT:MID 20") scope.write("MEASUREMENT:REFLEVEL:PERCENT:LOW 10") scope.write("MEASUrement:IMMed:DELay:EDGE2 RISE") scope.write("MEASUREMENT:REFLEVEL:PERCENT:LOW 3") scope.write("MEASUREMENT:REFLEVEL:PERCENT:MID 20") scope.write("MEASUREMENT:REFLEVEL:PERCENT:HIGH 80") print('Command sent: MEASure:DELay CH1,CH2') \$\endgroup\$ – HARI T O Mar 8 at 8:21
  • \$\begingroup\$ I have some conditions for Edges that I entered in your code.Could you please check the above code I inserted.I insrted after this line scope.write('MEASUrement:IMMed:DELay:DIRection FORWARDS') print('Measurement type sent: OK') \$\endgroup\$ – HARI T O Mar 8 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.