01-04-2019 12:50 PM
I have the follow VI that I am using to calculate duty cycle. When I use a function generator for the input signal it calculated the duty to within .1%. However, when I use a signal from an encoder attached to a motor, so not a perfect wave, the duty cycle jumps anywhere from 2% off up to almost 20% off. When the signal is attached to an oscilloscope the duty cycle is +-1% of change at most. The only thing I can think of is that the timing between the two counters in not simultaneous, and so the pulse width measurement isn't correlated to the period measurement. That also would explain why with a function generator that is would work, since the signal does not change in anyway.
Is my assumption correct that they are not synchronized, or is there something else that would cause that?
Solved! Go to Solution.
01-04-2019 02:29 PM
I'm still on LV 2016 and can't look at your 2017 code (unless you use File-->Save for Previous Version, hint, hint).
1. Syncing two counter measurement tasks is possible but not obvious or trivial. Odds are your tasks aren't sync'ed.
2. Dunno what board you're using, but you can avoid sync issues by doing your measurement with a single semi-period measurement task (or possibly a pulse measurement task if you have an X-series board that supports that measurement mode).
By setting the input signal polarity for the semiperiod task you control whether the first valid interval in the buffer (see caveat below) will be a high time or a low time. From there it's easy enough to figure out any timing relationship you want -- high and low pulse width, duty cycle, frequency, you name it.
*Caveat: the meaning of the first value in the buffer might vary from one board type to another. On older boards, you'll get a time from task start until the first edge of the specified polarity. This is not generally a valid interval time. On newer X-series boards, the first value in the buffer should be a valid full interval but offhand I can't say whether a rising edge polarity spec leads to an initial buffer value of high time or of low time.
The old behavior created some confusion, but the new behavior isn't perfect either.
-Kevin P
01-04-2019 02:53 PM
Here is a version for 2016, and also a snippet for the duty cycle. I'm using a 6341 daq.
01-04-2019 02:59 PM
@randomguy77 wrote:
Here is a version for 2016, and also a snippet for the duty cycle. I'm using a 6341 daq.
I am the same page as Kevin.
If you change your acquisition to return a "Waveform" instead of "1D DBL", you MAY be able to see a difference in the "t0" for the Waveform data.
Ben
01-04-2019 04:09 PM
Can you combine the two counters into a single task, then use a single start function?
I know you can for analog channels where you can add individual channels in a series of "creates" or within a loop. I don't mess with DAQ counters, so I don't know if the philosophy applies. But the DAQmx Read does have a Multiple Channel option in it.
01-06-2019 08:20 AM
I made mods in place to convert to a single counter doing semi-period measurement. I don't have hw here to test so it's possible I have the high times and low times swapped due to misinterpretation of the "starting edge" parameter. Fix as needed. Otherwise, this should help you get all the pulse params you care to measure.
-Kevin P