03-19-2008 11:46 AM
03-20-2008 06:11 AM
03-20-2008 09:38 AM
To get both from a single counter measurement, configure it to measure semi-periods. Every pair of consecutive values will be a high time, low time pair. Freq is just 1/(high + low) and duty cycle is high*freq, or high/(high + low).
-Kevin P.
03-20-2008 10:30 AM
Thanks a lot for your answer, it does the trick. The only problem I am left with is that to get a reliable measure in the Semi Period mode, the channel must be triggered otherwise I can get the low edge first than the high edge or vice-versa. So trigger is mandatory. In my case i would like to trigger on the signal itself choosing for instance Start Digital Edge (Rising) then I am sure I get always the high edge before but if I insert the DAQmx Start Trigger icon with this setting I get the error -200452, not supported fir the device. My counter is dev3/ctr0 and the source I/O that I choose for the trigger (same as the ctr0) is hence /dev3/PFI38
Any thoughts? Is it possible to trigger on the same counter than the one I am continuously acquiring?
Thanks a lot,
Christophe
03-20-2008 11:57 AM
Two answers. Either one alone should help -- no real need to do both. Note: I am assuming buffered measurements. Behavior may be slightly different for single measurements.
1. The standard digital start trigger can't be used for counter input measurements -- it's only for counter output pulses and pulse trains. For input tasks, you need to configure an "Arm Start" trigger which is only available in LabVIEW via a DAQmx Trigger property node.
(This is a recurring point of confusion for counters under DAQmx. I'm really not sure why NI chose to implement the API the way they did. I've yet to see the advantage of it. Just about any timed task except counter input can be triggered with a Digital Start trigger. No task except counter input can use a digital Arm Start trigger. Why they didn't just let users call it a Digital Start trigger and then do the conversion under the hood remains a mystery to me...)
2. There should be another DAQmx property node (probably a DAQmx Channel property node) that will let you define the polarity of the semi-period signal you wish to measure. This was at least possible for 6602's under the legacy driver. If you specify "high" or "rising" (don't recall the syntax), the very first value buffered will be the time from starting the task until the first rising edge. (If a falling edge comes in before the first rising edge, it'll be ignored.) The first value is meaningless for PWM. So the array will hold:
(meaningless time, high time, low time, high time, low time, high time, low time, ...)
I'm expect that if you don't buffer the measurements, you won't get an initial meaningless value. However, I don't think I've ever tested this.
-Kevin P.
03-21-2008 03:43 AM
03-21-2008 08:42 AM
The trigger actually works well, but only in the first iteration of my while loop (see WorkOnlyFirstTime.jpg) which is logical as the as soon as the next iteration start there will not be any new synchronisation
03-21-2008 08:56 AM
Kevin,
Let me try to explain better: the first iteration of the While loop will retrieve a certain odd or even number of edges. I will discard the first sample and will get the correct widths for both high and low edge. But this is only because when I enter the while loop the first time my acquisition is synchronised (trigger armed) on the first counter edge. Then I will wait 100ms (in the while loop) and read another bunch of samples. I assume that I will not miss any samples that came during the 100ms pause, is this correct? If yes then the problem will remain that I will not know if the reading of my second iteration in the while loop starts with a high or low edge, I have no means to assess that and hence I am stuck. Ideally at each iteration of the while loop I should re-arm the trigger and start task (?) but I do not think this works...
I hope this is clearer,
Thanks for your patience,
Christophe
03-21-2008 05:38 PM
04-08-2008 02:48 AM