LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pulse measurements

G'd day,
 
I'm a french mechanical engineer student working as a trainee at Charles Darwin University, and I have some problems with getting the duty cycle of a square signal, which I'm acquiring as digital (the interface board is done for good). Basically I'm trying to get it to work with a function generator, the final goal being to do the same with a chip that will convert an analogue current signal into a voltage PWM.
The input signal in Labview is boolean, and though I've tried many different conversion blocks, it wouldn't work. I've put a simple waveform as an input to the "pulse measurement" block to check and obviously, that is ok. I don't understand where the fault is, but I acknolwedge I'm a newbie with labview.
 
 
I've also tried different ways of measuring the time between two rising / falling signals, unsuccessfully (I think I could know the duty cycle that way, too). I would like to know how to do it as well anyway : I've got an 12bits encoder mounted on a shaft, from which I'd like to retrieve the speed information, that is to say the period between two changes of values.
 
Thanks for your assistance,
 
Gabriel
0 Kudos
Message 1 of 13
(7,311 Views)

Gabriel,

Thank you for contacting National Instruments.

If you want to measure duty cycle, one of the easiest ways to do that is with a Semi-period Measurement. Semi-period measurements measure the time between consecutive edges with the use of counters. From that you can easily determine duty cycle. There is an example that ships with LabVIEW named Meas Duty Cycle-Buffered-Finite.vi that demonstrates this. I highly recommend taking a look at this example.

--
Michael P
National Instruments
0 Kudos
Message 2 of 13
(7,293 Views)

Thanks for such a quick answer,

Unfortunately, I hardly understand the example you advised me to look at, despite the several days I spent searching. The thing is that I've just started to use Labview, and I only know the basic functions. I went through several trainings, but all quite simple. I hardly understand the point and the functioning of the blocks used in that VI. I simply tried to see if I could get it to work with my input, changing the trigger channel to "Dev1/PFI3" to which a function generator is wired... Unsuccessfully.

In part #1 of the example the operation of the "semi-period" block is described.  From reading the documentation on "semi-period" blocks, I am unclear whether this block measures the "semi-period" or if it only creates a counter to measure the semi-period.  Initially I assumed that it measured the semi-period, however when I try to connect my pulsed channel to the input I get an error message saying that there is no data coming from the board. In addition to that, the ”DAQmx trigger” seems to be meant to trigger on the digital channel more than the semi-period block, as it has a “trigger source” I can set to my pulsed channel.

I am also unclear about the function of the "task in" and "task out" ports.  I have looked through all the documentation and help files and am still not clear on their function : what is a task ?

Basically I think I am really unclear about those DAQmx blocks I never used before (all of them unfortunately), I can just understand the way the calculation works…

Thanks for your support,

 

Gabriel

 

0 Kudos
Message 3 of 13
(7,274 Views)

I am including an excerpt from the documentation for the example here, and adding notes to clarify:

Semi-period measurement differs from pulse width measurement in that it measures both the high and the low pulses of a given signal.  So for every period, two data points will be returned.

II.   Instructions for Running:
1. Select the Physical Channel which corresponds to the counter you want to measure duty cycle on the DAQ device.
2.  Enter the Maximum and Minimum Value to specify the range or your unknown semi-periods.  Additionally, you can change the input terminal where the duty cycle is measured using the channel property node.  The input terminal and the trigger terminal must be the same for this example to behave as expected. [I have attached an edited version of the example that does this, so whatever pin you choose for the trigger terminal is also routed to the counter. Just connect the signal you want to measure to the PFI pin you select for the trigger.]
Note:  It is important to set the Maximum and Minimum Values of your unknown semi-period as accurately as possible so the best internal timebase can be chosen to minimize measurement error.  The default values specify a range that can be measured by the counter using the 20MhzTimebase.  Use the Gen Dig Pulse Train-Continuous example to verify that you are measuring correctly on the DAQ device.

To answer your questions about the DAQmx VIs, I recommend taking a look at the tutorial linked below:

Learn 10 Functions in NI-DAQmx and Solve 80% of Data Acquisition Applications

https://www.ni.com/en/support/documentation/supplemental/06/learn-10-functions-in-ni-daqmx-and-handl...

 
--
Michael P
National Instruments
0 Kudos
Message 4 of 13
(7,247 Views)
Thanks a lot for that adapted version, which I had to modify a little as it gave me the complement of the duty cycle (e.g. 0.3 instead of 0.7) : I think I'm going to use it just as it is.
 
Still, I have several questions :
1) Why does the table fill in itself once the VI has run, and after an error message (Error -200284 occurred at DAQmx Read (Counter 1D DBL 1Chan NSamp).vi, Possible reason(s):
Some or all of the samples requested have not yet been acquired) ? Basically I'd like to be able to have a real time plot of the duty cycle, as well as to record it in a text file on pressing a button.
2) Is there a reading direction ? Do the blocks work one after the other or is it just a thread on which we add functions ?
3) Why do we use a "property node" to set the input channel as the terminal input of the semi-period block and cannot wire it directly to the input of the latter ?
 
I tried to insert that VI to mine, but then the rest doesn't work any longer, whereas the duty cycle table fills in with values. What's happening is that my other displays run for a fraction af second and then freeze, not preventing the duty cycle calculation part to run.
 
I also tried to create subVI's which I thought allowed to clean up the block diagram the way it's possible to do it with "Subsystems" in Matlab/Simulink (it just puts everything in a box with corresponding inputs/outputs). But then nothing works any more. I guess it's due to the global while loop I need to add in the subVI to still be able to use feedback nodes though not in the global loop.
 
I read through the whole "Learn 10 Functions in NI-DAQmx" but my Matlab/Simulink background doesn't help me to understand. In any case I want to thank you for your understanding and your patience !
 
Gabriel
0 Kudos
Message 5 of 13
(7,237 Views)
 

1) This is from the documentation for that error: To wait for the samples to become available use a longer read timeout.

If the frequency of the signal you are measuring is low enough that it takes longer than the timeout specified to read the number of samples you request, this error will occur.

2) I'm not sure I fully understand this question, but I think you are asking about how dataflow works in LabVIEW. The (very) basic idea is that a VI (square icon) will not execute until all of its inputs are available. I recommend checking out the LabVIEW online introduction course online (https://learn.ni.com/learn/article/labview-tutorial).

3) The counter on your device has default pins that correspond to its source, gate, and output. I used the property node to set it to the same pin that is being used to trigger the measurement (instead of the default pin).

I think a better understanding of how to program in LabVIEW will help you to understand all of this tremendously.

--
Michael P
National Instruments
0 Kudos
Message 6 of 13
(7,219 Views)

If I am not mistaking, there is nothing about the DAQmx VIs in the six-hour course you advise me to read (which I did before starting to use Labview, basically). Anyway, I managed to reproduce the logic of the example to create a period-measuring VI, still without understanding it. I would simply expect a VI with a digital input created by my square signal generator that would output the time for every rising or falling edge. I have been trying very hard to understand the "task-structure" used here, investigating on NI's website, unsuccessfully. My using a foreign language may make it twice as difficult, and my australian colleagues are unclear as well.

1) What is a task ?

2) I integrated the example you gave me to my own VI (programmed with express VIs in a while loop), which then could not work any longer. The duty-cycle is still measured and displayed in the table, but the rest of my VI freezes. I guess it is a structure problem, however I cannot sort it out.

3) I would like to hide a part of my VI by creating a subVI, the problem being that it utilises a feedback node. To allow such wiring, I need to create a while loop in my subVI too, and then it does not work any more when I replace the lot by the corresponding VI in the global VI. Is there a solution ?

4) Why can we only choose the trigger source amongst the PFI channels, and not the basic digital channel (e.g. P0.1 etc) ?

I thought about sending you my VI, but I doubt you would appreciate as it is not your business to correct my work (which would shock you I guess anyway, as I used some tricks to bypass some difficult points, such as logging data and comments in text files named with the recording start time, that is to say when you press a push button).

Gabriel, French trainee engineer in Darwin, stuck in his project.

0 Kudos
Message 7 of 13
(7,211 Views)
Hello Tchobiloute-
 
Let me see if I can help with your questions:
 
1) An NI-DAQmx Task is a grouping of information about a DAQ operation.  This includes timing and triggering, physical and virtual channels used, and any other task-specific settings.  Each NI-DAQmx VI or Function refers back to information stored in the task parameters in order to determine how to operate on the task.  This abstraction of functionality makes NI-DAQmx quite powerful and easy to adapt to new platforms and applications.
 
2) It is hard to suggest what might be causing your VI to freeze without knowing more about how it is structured, but nevertheless I would encourage you to stick with using the DAQmx VIs rather than the DAQ Assistant.  Using the DAQmx VIs directly gives you considerably more control over the flow of your application and it seems like it was working properly before.  So, pardon the American expression, but I would suggest that "if it ain't broke, don't fix it." Smiley Wink
 
3) How many times do you need the loop to iterate in the subVI?  If you only need to use one running's data then you could just put a FOR loop and set it to iterate twice so you get the feedback information from the first iteration.  The alternative would be to use uninitialized shift registers to store data from a previous iteration.  An example of using "LabVIEW 2 Style" globals (also known as uninitialized shift registers) is attached.
 
4) Only PFI lines are available for triggering because the hardware only supports triggering on those lines.  Digital lines (such as P0.0) are very different from PFI lines in that they are setup only for programmed-I/O operation with software timing.  PFI lines are more closely associated with counter operations and are designed for hardware-timed operations and triggering only.
 
Hopefully this helps- we are glad to help with any questions you might have.
Tom W
National Instruments
Message 8 of 13
(7,188 Views)
Thanks for your answer !
 
I have more and more things working, which reassures me. Putting every different part in a separate loop was the solution to a few of my problems (I had a practice at school on Labview that was so quick I first thought everything had to be integrated to a global while loop).
 
Now I would like to log the data whenever I decide to do it, that is to say when I press a button. I've looked for a kind of switch in the DAQmx VIs, unsuccessfully. I tried to use a case logic linked to such a button, without any better result.
 
I attached my VI, which I commented to make you understand my aims and what I understood out of the DAQmx VIs. I would be very thankful if you could take a quick look to it !
 
Gabriel
 
 
0 Kudos
Message 9 of 13
(7,171 Views)

Hello All,

It looks like your issues with DAQ might be coming to an end, so I'll help out with any LabVIEW questions you might be encountering.

It looks like you are attempting to log data with the LabVIEW measurement file VIs.  Your approach to this by using a Boolean control wired to a case structure should be appropriate to achieve the behavior you are requesting.  When you run your VI are you able to log any data to the LabVIEW measurement file, or are you encountering errors?  Make sure that when you are configuring the Write LabVIEW Measurement File VI that you have the "append to file" option enabled if the file exists (this way each time the loop iterates it will add data to the file rather than creating a new one).

I also suggest that you read over the LabVIEW programming style guidelines (I have attached the document to this post).  Good coding practices make code much easier to debug, easier to modify, and ultimately lead to a faster development cycle.

Hope this helps!




Travis M
LabVIEW R&D
National Instruments
0 Kudos
Message 10 of 13
(7,142 Views)