Jump to content
  • 0

PWM and pulse width with Waveforms 2015


gergelytakacs

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?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

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

 

Link to comment
Share on other sites

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ó. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...