• 0
gergelytakacs

PWM and pulse width with Waveforms 2015

Question

Hello all. New to WaveForms, so excuse me if this is too easy.

I'd like to capture an analog channel, and two digital ones - where information is encoded into the width of the pulses. Sure enough, I can do this. 

But of the digital, one is PWM, which I'd like to manipulate into the corresponding stream of percentages (or 8-bit values, does not matter); the other one encodes the duration of something - therefore I'd like to measure their positive duration, as in a timer/counter... Can this be done in WaveForms with the AD2?

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Szia @gergelytakacs

You could use measurements, Scope/View/Measurements/Add/Custom Global, insert the code below and enter name/unit.
You should also replace the "DIO0" in the code with the name of your digital line.

image.png.d13582333c060f1c68cff97fc226b36b.png

var rg = Scope.DigitalChannels.DIO0.data
var n = rg.length;

var c0 = 0
var c1 = 0
var i = 0
var f = rg[i]

// skip samples with initial level
while(rg[i]==f && i<n) i++

// count low and high levels in the first pulse of the acquisition
for(var fc = 0; fc<2 && i<n; fc++){
    f = rg[i]
    while(rg[i]==f && i<n) {
        i++
        if(f==0) c0++
        else c1++
    }
}
// duty
100*c1/(c0+c1)
var rg = Scope.DigitalChannels.DIO0.data
var n = rg.length;

var c0 = 0
var c1 = 0

var i = 0
var f = rg[i]

// skip samples with initial level
while(rg[i]==f && i<n) i++

// count low and high levels in the first pulse of the acquisition
for(var fc = 0; fc<2 && i<n; fc++){
    f = rg[i]
    while(rg[i]==f && i<n) {
        i++
        if(f==0) c0++
        else c1++
    }
}
// positive length
c1/Scope.DigitalTime.Rate.real

 

Share this post


Link to post
Share on other sites
  • 0

Szia Attila,

Thank you so much for your quick response. I actually ended up solving the problem in MATLAB as I needed a continuous information on PWM, not just an instantaneous measurement.

Maybe a feature idea / request: it would be very useful if users could visualize "continuous" data in the scope environment, that is otherwise encoded in the digital channels. Say, for example, you want to show the duty cycle of the PWM signal in percents, as a continuous value. Just an idea.

Ugyanitt. Hajdú bojler eladó. :)

Share this post


Link to post
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