LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to find fast and acurate duty cycle measuremeants?

I have a square wave signal being inputted. What I would like to do is find the duty cycle for each period throughout the signal, and not just the average duty cycle. Using the Read Pulse Duty Cycle and Frequency (Continious).vi it will measure the duty cycle exactly, but the VI is very slow. There will be a few thousand periods per signal, and that one takes a few seconds to calculate 100. I have also a software based approach for finding each duty cycle. This one is much faster, never measured the time but can calculate it all almost the second I say run. However, when running that VI the duty cycle values calculated are wrong. I'm wondering is there a way to pretty much combine both approaches, to get the speed of the software way, and the accuracy of the hardware?

0 Kudos
Message 1 of 8
(2,280 Views)

Do you have any examples of your waveform data?  When I run your code with a simulation, it comes up with the correct duty cycle.  Granted, we could do quite a bit to improve your software calculation by combining loops and probably some other optimizations.  Also, I would expect the hardware to be a lot more exact and faster.  Perhaps you can optimize you settings to make the counter run faster.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(2,266 Views)

This one was captured using a function generator to create the signal. 50kHZ with 50% duty cycle. The VI will calculate the correct values most of the time, but then I'll get a run like this where it calculates the max duty at 60%. I would ideally like to use the hardware as I expect it to be a lot more precise as well. I've just started trying a new approach by capturing each rising and falling edge, rather than using the example and slightly modifying it, and then calculating the duty based off of the position of each edge. It speeds up the capture a lot, so I'm thinking that may be the hardware approach to take.

0 Kudos
Message 3 of 8
(2,260 Views)

After playing around with the edge method I mentioned I am currently here. It works ok. Gets me within .5%, still not great though, and I have to remove a lot of points before it gets to a stable output.

0 Kudos
Message 4 of 8
(2,255 Views)

The funny thing about "Time" is that it does take time to make accurate measurements.  "Fast", and "Accurate" only happens at really high frequencies! (and then they are still limited by Nyquist) 

 

Determine how accurate you need the measurement to be first, then you will need to deal with the time the measurement takes.  There are some means of anti-aliasing (unfolding) possible (like using a 3:4 sample rate) but normally these are not necessary.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 8
(2,247 Views)

50kHZ is going to be around the frequency of the signal. Far from the fastest signal ever, but should be fast enough that 100 duty cycle measurements should be able to happen almost instantly I would think.

0 Kudos
Message 6 of 8
(2,242 Views)

@Chi55 wrote:

50kHZ is going to be around the frequency of the signal. Far from the fastest signal ever, but should be fast enough that 100 duty cycle measurements should be able to happen almost instantly I would think.


No, 100% Duty Cycle is a value with a 0Hz component.  To accurately measure 0Hz you need +inf time


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 8
(2,240 Views)

@Chi55 wrote:

50kHZ is going to be around the frequency of the signal. Far from the fastest signal ever, but should be fast enough that 100 duty cycle measurements should be able to happen almost instantly I would think.


100/50kHz = 2ms.  A long time for a computer.

 

What equipment are you using?  What settings were you using with the hardware duty cycle example?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(2,199 Views)