Jump to content
  • 0

Measuring the delay between two rising edges on Discovery 2


maxwell_

Question

Hi. I would like to measure the absolute time difference between the rising edges of two digital output pins. The time that the pins stay on are about 100 ms, and I expect the delay to be in the range of 1-10 ms. To be safe, I have to assume that either pin can get HIGH first. 

Additionally, I want to take many measurements (100-1000), it would be great if there is a way to log the data as well. 

 

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0
On 3/16/2022 at 10:33 AM, attila said:

Hi @maxwell_

You can use the following Script with Record and data compression, here you have the workspace: dt.dwf3work
Here I used the Patterns to generated signals with delay.

image.png.fb852e8ca1c6d105c2c81cec059cdd7d.png

Hi Attila,

How to measure the delay of transient slopes (both rising and falling edge) between two channels eg. CH1-CH2 ? I prefer to use a script either in JS or Python.

I currently subtract two channels each other, then use the PosWidth and NegWidth functions to measure delay in Scope. However, I always have to zoom the transient edges to obtain the most accurate results (from 10 to 100ns). So the test procedure is manual and boring in this way.

 

Kind regards,

 

Edited by 3D_loves_eng
clarify measurement sources
Link to comment
Share on other sites

  • 0

Hello @attila

On 3/16/2022 at 10:33 AM, attila said:

Hi @maxwell_

You can use the following Script with Record and data compression, here you have the workspace: dt.dwf3work
Here I used the Patterns to generated signals with delay.

image.png.fb852e8ca1c6d105c2c81cec059cdd7d.png


Is it possible to do something similar, but with the analog inputs of the scope?
What I want to do is obtain automatically the delay of the rising edge on CH2 compared to the instant of the rising edge on CH1.  
I thought that a possible approach could be using the rising edge trigger of the channels, but I couldn't figure it out how to use the trigger to calculate the delay between the two wave forms.

Can you please help me?
Best regards

Link to comment
Share on other sites

  • 0

Hi @Albertu95

You can use something like this to measure the delay with higher approximation/interpolation :

image.thumb.png.f1115051a8b3262123dd9105ddf2648d.png

var trig = Scope.Trigger.Level.real;
var c = Scope.Time.Samples.real;
var v2 = 0;
// T0 is aligned to trigger crossing
for(var i = floor(Scope.Time.IndexOf(0))-1; i < c; i++){
    var v = Scope.Channel2.Sample(i);
    if(v<trig){
        v2 = v;
        continue;
    }
    var s = i - (v-trig)/(v-v2);
    var t = Scope.Time.TimeOf(s);
    print(i, t*1e9, "ns");
    break;
}

 

Link to comment
Share on other sites

  • 0

Hi @attila
I did a simple test code for what you explained to me, using the wave generator of the instrument itself.

 

// This script adjusts the Wavegen offset based on Scope measurement.
clear()
if(!('Wavegen' in this) || !('Scope' in this)) throw "Please open a Scope and a Wavegen instrument";

Wavegen.Channel1.Mode.text = "Simple";
Wavegen.Channel1.Simple.Type.text = "pulse";
Wavegen.Channel1.Simple.Phase.value = 95;
Wavegen.Channel1.Simple.Offset.value = 0.0;
Wavegen.Channel1.Simple.Period.text = "2us";
Wavegen.Channel1.Simple.Symmetry.value= "25"


Wavegen.Channel2.Mode.text = "Simple";
Wavegen.Channel2.Simple.Type.text = "pulse";
Wavegen.Channel2.Simple.Phase.value = 80;
Wavegen.Channel2.Simple.Offset.value = 0.0;
Wavegen.Channel2.Simple.Period.text = "1us";
Wavegen.Channel2.Simple.Symmetry.value= "25"

Scope1.Trigger.Type.text= "edge";
Scope1.Trigger.Condition.text= "rising";
Scope1.Trigger.Level.value=0.5;



Wavegen.run();
Scope.run();

var trig = Scope.Trigger.Level.real;//returns the trigger set value
var c = Scope.Time.Samples.real;//returns the number of samples
var v2 = 0;
print(trig, "trig");
print(c, "samples");// T0 is aligned to trigger crossing
for(var i = floor(Scope.Time.IndexOf(0))-1; i < c; i++){//floor(Scope.Time.IndexOf(0))-1: takes the moment of the trigger -1 as starting point for the for cycle (?)
    t=0;
    var v = Scope.Channel2.Sample(i);// takes i sample from channel 2
    if(v<trig){//if value i of channell 2 is smaller than trigger go further
        v2 = v;
        continue;
    }
    var s = i - (v-trig)/(v-v2);//tries to take the most precise value possible i-((sample bigger than trigger)-trigger)/((sample bigger than trigger) - previous sample) 
    var t = Scope.Time.TimeOf(s);//time raltive to the trigger, and so the delay
    print(i, t*1e9, "ns");
    break;
}
Wavegen.stop();
Scope.stop();

It seems that it works, my only problem now is that if I try to change a parameter, let's say the phase, after the first run of the code it does not work. 
I have to start and stop manually wave generator and scope, and then it works again for one run. Then, if I want to use it again, I have to repeat the operation described before. 

I guess I don't reset properly the instrument in the script, but I cannot figure out what I make wrong.

Can you please help me?

Link to comment
Share on other sites

  • 0

Here is the complete code if someone needs it:

// This script adjusts the Wavegen offset based on Scope measurement.
clear()
if(!('Wavegen' in this) || !('Scope' in this)) throw "Please open a Scope and a Wavegen instrument";

Wavegen.Channel1.Mode.text = "Simple";
Wavegen.Channel1.Simple.Type.text = "pulse";
Wavegen.Channel1.Simple.Phase.value = 92;
Wavegen.Channel1.Simple.Offset.value = 0.0;
Wavegen.Channel1.Simple.Period.text = "1us";
Wavegen.Channel1.Simple.Symmetry.value= "25"


Wavegen.Channel2.Mode.text = "Simple";
Wavegen.Channel2.Simple.Type.text = "pulse";
Wavegen.Channel2.Simple.Phase.value = 80;
Wavegen.Channel2.Simple.Offset.value = 0.0;
Wavegen.Channel2.Simple.Period.text = "1us";
Wavegen.Channel2.Simple.Symmetry.value= "25"

Scope1.Trigger.Type.text= "edge";
Scope1.Trigger.Condition.text= "rising";
Scope1.Trigger.Level.value=0.5;



Wavegen.run();
Scope.run();
Scope.wait();// wait for the capture to be done

var trig = Scope.Trigger.Level.real;//returns the trigger set value
var c = Scope.Time.Samples.real;//returns the number of samples
var v2 = 0;
print(trig, "trig");
print(c, "samples");// T0 is aligned to trigger crossing
for(var i = floor(Scope.Time.IndexOf(0))-1; i < c; i++){//floor(Scope.Time.IndexOf(0))-1: takes the moment of the trigger -1 as starting point for the for cycle (?)
    t=0;
    var v = Scope.Channel2.Sample(i);// takes i sample from channel 2
    if(v<trig){//if value i of channell 2 is smaller than trigger go further
        v2 = v;
        continue;
    }
    var s = i - (v-trig)/(v-v2);//tries to take the most precise value possible i-((sample bigger than trigger)-trigger)/((sample bigger than trigger) - previous sample) 
    var t = Scope.Time.TimeOf(s);//time raltive to the trigger, and so the delay
    print(i, t*1e9, "ns");
    break;
}
Wavegen.stop();
Scope.stop();

-----------------------------------------------------------------------------------

I was trying to adapt this same code for the falling edge, but the result seems not as precise as the rising edge one.

This is the code I used:

// This script adjusts the Wavegen offset based on Scope measurement.
clear()
if(!('Wavegen' in this) || !('Scope' in this)) throw "Please open a Scope and a Wavegen instrument";

Wavegen.Channel1.Mode.text = "Simple";
Wavegen.Channel1.Simple.Type.text = "pulse";
Wavegen.Channel1.Simple.Phase.value = 10;
Wavegen.Channel1.Simple.Offset.value = 0.0;
Wavegen.Channel1.Simple.Period.text = "1us";
Wavegen.Channel1.Simple.Symmetry.value= "25"


Wavegen.Channel2.Mode.text = "Simple";
Wavegen.Channel2.Simple.Type.text = "pulse";
Wavegen.Channel2.Simple.Phase.value = 0;
Wavegen.Channel2.Simple.Offset.value = 0.0;
Wavegen.Channel2.Simple.Period.text = "1us";
Wavegen.Channel2.Simple.Symmetry.value= "25"

Scope1.Trigger.Type.text= "edge";
Scope1.Trigger.Condition.text= "falling";
Scope1.Trigger.Level.value=0.5;



Wavegen.run();
Scope.run();
Scope.wait();// wait for the capture to be done

var trig = Scope.Trigger.Level.real;//returns the trigger set value
var c = Scope.Time.Samples.real;//returns the number of samples
var v2 = 0;
print(trig, "trig");
print(c, "samples");// T0 is aligned to trigger crossing

for(var i = floor(Scope.Time.IndexOf(0))-1; i < c; i++){//floor(Scope.Time.IndexOf(0))-1: takes the moment of the trigger -1 as starting point for the for cycle (?)
    t=0;
    var v = Scope.Channel2.Sample(i);// takes i sample from channel 2
    if(v>trig){//if value i of channell 2 is BIGGER than trigger go further; TAKE CARE FOR FALLING V>TRIGGER; FOR RISING V<TRIG
        v2 = v;
        continue;
    }
    //var s = i - (v-trig)/(v-v2);//tries to take the most precise value possible i-((sample bigger than trigger)-trigger)/((sample bigger than trigger) - previous sample)
    var s = i - (trig-v)/(v2-v);//tries to take the most precise value possible i-(trigger-(sample SMALLER than trigger))/(previous sample - (sample SMALLER than trigger))
  
    var t = Scope.Time.TimeOf(s);//time raltive to the trigger, and so the delay
    print(i, t*1e9, "ns");
    break;
}
Wavegen.stop();
Scope.stop();


The scope seems not to trigger as precisely as for the rising edge case:
1285676267_fallingtrigger.thumb.png.3555d38bd39c3c8ba32537806aed5244.png

image.png.509077734857f7ddaef7bf4045b3966f.png

rising.thumb.png.ad8fbbf009709fbb3e7b24a9d12cc4cf.png

image.png.377ce4189d08cbba48d945eee78339d6.png

 

as you can see the rising edge trigger seems more precise than the falling edge one.

@attila do you have any sudgestions?

Can I improve this with the code, or it is some kind of hardware limitation?

EDIT: typo

Edited by Albertu95
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...